]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph_erasure_code_benchmark: fix parameter handling 2675/head
authorDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Thu, 9 Oct 2014 16:09:41 +0000 (18:09 +0200)
committerDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Fri, 10 Oct 2014 09:08:00 +0000 (11:08 +0200)
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 <danny.al-gaaf@bisect.de>
src/test/erasure-code/ceph_erasure_code_benchmark.cc
src/test/erasure-code/ceph_erasure_code_benchmark.h

index c6a4228bdc1e4a40f1fbf4fea120abc05bdf1809..672e652ac5bb76de25237d71d11883a19c3eead6 100644 (file)
@@ -107,6 +107,17 @@ int ErasureCodeBench::setup(int argc, char** argv) {
   workload = vm["workload"].as<string>();
   erasures = vm["erasures"].as<int>();
 
+  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;
index b25b9ce373b38011e21945ffff17a0ab2d8d7c44..b20f3098ac504b95dabcd4b1339fe6dabae21a32 100644 (file)
@@ -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<string,string> parameters;
+
 public:
   int setup(int argc, char** argv);
   int run();