From patchwork Wed Jun 8 17:59:11 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Lang X-Patchwork-Id: 861682 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p58I6rxc010696 for ; Wed, 8 Jun 2011 18:07:29 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751584Ab1FHR7S (ORCPT ); Wed, 8 Jun 2011 13:59:18 -0400 Received: from mail-qy0-f174.google.com ([209.85.216.174]:64792 "EHLO mail-qy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751051Ab1FHR7R (ORCPT ); Wed, 8 Jun 2011 13:59:17 -0400 Received: by qyk7 with SMTP id 7so2064209qyk.19 for ; Wed, 08 Jun 2011 10:59:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer; bh=b08XiHMtiIxp0LcZNRP3fpf3Zh5sO1+xsis04zsSu3U=; b=XmULFxm+FO15WfGQoJNNPbFm/ZNJ1zAWkcNwa+O60g3BlJzq1/jYIVd0xV7H8MdwvI eR+QCeZ9feDUEBqqZfEf3PLZOJLxVGphHceZ8BMtv5lL3vnha1b8nEPVynkwELXnYlqy cxflXGjpd6Wp/wrxDo4NmHjhDhO4mjklzdeCU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=jyIqC+2FW+ELZLnxARNCxPRBKDmPlECd8PyGTiEUt5oDsi9FzMdrq15a2L3EmZmHhL QKc2Ydfs5WQWTdwNAmHyLBoOOHcvt0Wq16OU/yOijfMLjti/1P9BHBvz+UZbQQ7Oqnl4 pGxxvl3I/VM/QpWPjnZhGa/mPlMxjt8duCVPc= Received: by 10.229.11.38 with SMTP id r38mr5876507qcr.18.1307555956807; Wed, 08 Jun 2011 10:59:16 -0700 (PDT) Received: from localhost.localdomain (chml01.drwholdings.com [76.8.89.6]) by mx.google.com with ESMTPS id u15sm579614qcq.12.2011.06.08.10.59.15 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 08 Jun 2011 10:59:16 -0700 (PDT) From: Sam Lang To: ceph-devel@vger.kernel.org Cc: Sam Lang Subject: [PATCH 1/2] Fix segfault caused by invalid argument string. Date: Wed, 8 Jun 2011 12:59:11 -0500 Message-Id: <1307555952-10340-1-git-send-email-samlang@gmail.com> X-Mailer: git-send-email 1.7.1 Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Wed, 08 Jun 2011 18:07:29 +0000 (UTC) This patchset includes minor fixes to the crushtool utility. If an invalid bucket type is speicifed on the command line, the code was iterating through bucket_types for the length of the static array, but the last entry in that array has null (0) values, which was causing a segfault. This patch just checks that bucket_types[i].name is non-null instead. Also, if the wrong bucket type or algorithm is specified, prints the usage string on exit. Signed-off-by: Sam Lang --- src/crushtool.cc | 14 ++++++++------ 1 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/crushtool.cc b/src/crushtool.cc index 73c303b..64b2b4f 100644 --- a/src/crushtool.cc +++ b/src/crushtool.cc @@ -54,6 +54,8 @@ map type_id; map rule_id; +void usage(); + string string_node(node_t &node) { string s = string(node.value.begin(), node.value.end()); @@ -141,8 +143,8 @@ void parse_bucket(iter_t const& i, CrushWrapper &crush) else if (a == "straw") alg = CRUSH_BUCKET_STRAW; else { - cerr << "unknown bucket alg '" << a << "'" << std::endl; - exit(1); + cerr << "unknown bucket alg '" << a << "'" << std::endl << std::endl; + usage(); } } else if (tag == "hash") { @@ -936,14 +938,14 @@ int main(int argc, const char **argv) crush.set_type_name(type, l.name); int buckettype = -1; - for (int i = 0; i < (int)(sizeof(bucket_types)/sizeof(bucket_types[0])); i++) - if (strcmp(l.buckettype, bucket_types[i].name) == 0) { + for (int i = 0; bucket_types[i].name; i++) + if (l.buckettype && strcmp(l.buckettype, bucket_types[i].name) == 0) { buckettype = bucket_types[i].type; break; } if (buckettype < 0) { - cerr << "unknown bucket type '" << l.buckettype << "'" << std::endl; - exit(1); + cerr << "unknown bucket type '" << l.buckettype << "'" << std::endl << std::endl; + usage(); } // build items