]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crush/CrushCompiler.cc: fix error handling
authorDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Thu, 11 May 2017 13:29:56 +0000 (15:29 +0200)
committerKefu Chai <kchai@redhat.com>
Sat, 2 Sep 2017 04:27:15 +0000 (12:27 +0800)
calloc() does not take negative values, check return value from
get_max_buckets() and handle it correctly.

Fix for:

CID 1405301 (#1 of 1): Argument cannot be negative (NEGATIVE_RETURNS)
 negative_returns: arg_map.size is passed to a parameter that cannot
 be negative.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
src/crush/CrushCompiler.cc

index 946a6b037b9fef48c5f4510b9cd3881357639440..8825f7543c0f70383702bd0defc44a442d0ad4e3 100644 (file)
@@ -1023,8 +1023,13 @@ int CrushCompiler::parse_choose_args(iter_t const& i)
     err << choose_arg_index << " duplicated" << std::endl;
     return -1;
   }
+  const auto max_buckets = crush.get_max_buckets();
+  if (max_buckets < 0) {
+    err << "get_max_buckets() returned error" << std::endl;
+    return -1;
+  }
   crush_choose_arg_map arg_map;
-  arg_map.size = crush.get_max_buckets();
+  arg_map.size = max_buckets;
   arg_map.args = (crush_choose_arg *)calloc(arg_map.size, sizeof(crush_choose_arg));
   for (iter_t p = i->children.begin() + 2; p != i->children.end(); p++) {
     int r = 0;