* [PATCH 1/2] Fix segfault caused by invalid argument string.
@ 2011-06-08 17:59 Sam Lang
2011-06-08 17:59 ` [PATCH 2/2] Fix typo in usage output for --num-osds Sam Lang
0 siblings, 1 reply; 2+ messages in thread
From: Sam Lang @ 2011-06-08 17:59 UTC (permalink / raw)
To: ceph-devel; +Cc: Sam Lang
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 <samlang@gmail.com>
---
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<string, int> type_id;
map<string, int> 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
--
1.7.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH 2/2] Fix typo in usage output for --num-osds
2011-06-08 17:59 [PATCH 1/2] Fix segfault caused by invalid argument string Sam Lang
@ 2011-06-08 17:59 ` Sam Lang
0 siblings, 0 replies; 2+ messages in thread
From: Sam Lang @ 2011-06-08 17:59 UTC (permalink / raw)
To: ceph-devel; +Cc: Sam Lang
This patch fixes the typo in the usage description to match the actual argument string.
Signed-off-by: Sam Lang <samlang@gmail.com>
---
src/crushtool.cc | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/crushtool.cc b/src/crushtool.cc
index 64b2b4f..4ea7e79 100644
--- a/src/crushtool.cc
+++ b/src/crushtool.cc
@@ -750,7 +750,7 @@ void usage()
cout << " --compile|-c map.txt compile a map from source\n";
cout << " [-o outfile [--clobber]]\n";
cout << " specify output for for (de)compilation\n";
- cout << " --build --num_osd N layer1 ...\n";
+ cout << " --build --num_osds N layer1 ...\n";
cout << " build a new map, where each 'layer' is\n";
cout << " 'name (uniform|straw|list|tree) size'\n";
cout << " --test mapfn test a range of inputs on the map\n";
--
1.7.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-06-08 17:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-08 17:59 [PATCH 1/2] Fix segfault caused by invalid argument string Sam Lang
2011-06-08 17:59 ` [PATCH 2/2] Fix typo in usage output for --num-osds Sam Lang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.