From: Danny Al-Gaaf Date: Thu, 9 Oct 2014 16:09:41 +0000 (+0200) Subject: ceph_erasure_code_benchmark: fix parameter handling X-Git-Tag: v0.88~83^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2c7c03c56c6a27bd9b1eab705261bc43da8179fb;p=ceph.git ceph_erasure_code_benchmark: fix parameter handling Make sure k and m paramter are valid to prevent crash. Fix typo. Fix for the following CID and other possible invalid combinations of k/m parameter: CID 1219466 (#1 of 1): Division or modulo by zero (DIVIDE_BY_ZERO) divide_by_zero: In expression rand() % (k + m), modulo by expression k + m which may be zero has undefined behavior. Signed-off-by: Danny Al-Gaaf --- diff --git a/src/test/erasure-code/ceph_erasure_code_benchmark.cc b/src/test/erasure-code/ceph_erasure_code_benchmark.cc index c6a4228bdc1e..672e652ac5bb 100644 --- a/src/test/erasure-code/ceph_erasure_code_benchmark.cc +++ b/src/test/erasure-code/ceph_erasure_code_benchmark.cc @@ -107,6 +107,17 @@ int ErasureCodeBench::setup(int argc, char** argv) { workload = vm["workload"].as(); erasures = vm["erasures"].as(); + k = atoi(parameters["k"].c_str()); + m = atoi(parameters["m"].c_str()); + + if (k <= 0) { + cout << "parameter k is " << k << ". But k needs to be > 0." << endl; + return -EINVAL; + } else if ( m < 0 ) { + cout << "parameter m is " << m << ". But m needs to be >= 0." << endl; + return -EINVAL; + } + return 0; } @@ -130,13 +141,11 @@ int ErasureCodeBench::encode() cerr << messages.str() << endl; return code; } - int k = atoi(parameters["k"].c_str()); - int m = atoi(parameters["m"].c_str()); if (erasure_code->get_data_chunk_count() != (unsigned int)k || (erasure_code->get_chunk_count() - erasure_code->get_data_chunk_count() != (unsigned int)m)) { - cout << "paramter k is " << k << "/m is " << m << ". But data chunk count is " + cout << "parameter k is " << k << "/m is " << m << ". But data chunk count is " << erasure_code->get_data_chunk_count() <<"/parity chunk count is " << erasure_code->get_chunk_count() - erasure_code->get_data_chunk_count() << endl; return -EINVAL; @@ -170,13 +179,10 @@ int ErasureCodeBench::decode() cerr << messages.str() << endl; return code; } - int k = atoi(parameters["k"].c_str()); - int m = atoi(parameters["m"].c_str()); - if (erasure_code->get_data_chunk_count() != (unsigned int)k || (erasure_code->get_chunk_count() - erasure_code->get_data_chunk_count() != (unsigned int)m)) { - cout << "paramter k is " << k << "/m is " << m << ". But data chunk count is " + cout << "parameter k is " << k << "/m is " << m << ". But data chunk count is " << erasure_code->get_data_chunk_count() <<"/parity chunk count is " << erasure_code->get_chunk_count() - erasure_code->get_data_chunk_count() << endl; return -EINVAL; diff --git a/src/test/erasure-code/ceph_erasure_code_benchmark.h b/src/test/erasure-code/ceph_erasure_code_benchmark.h index b25b9ce373b3..b20f3098ac50 100644 --- a/src/test/erasure-code/ceph_erasure_code_benchmark.h +++ b/src/test/erasure-code/ceph_erasure_code_benchmark.h @@ -24,10 +24,15 @@ using namespace std; class ErasureCodeBench { int in_size; int max_iterations; - string plugin; int erasures; + int k; + int m; + + string plugin; string workload; + map parameters; + public: int setup(int argc, char** argv); int run();