]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/HashIndex.cc: fix unintentional integer overflow
authorDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Thu, 4 Sep 2014 12:36:18 +0000 (14:36 +0200)
committerDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Thu, 4 Sep 2014 12:36:18 +0000 (14:36 +0200)
CID 1232604 (#1 of 1): Unintentional integer overflow (OVERFLOW_BEFORE_WIDEN)
 overflow_before_widen: Potentially overflowing expression
 (unsigned int)abs(this->merge_threshold) * 16U * this->split_multiplier
 with type unsigned int (32 bits, unsigned) is evaluated using 32-bit
 arithmetic before being used in a context which expects an expression of
 type uint64_t const (64 bits, unsigned). To avoid overflow, cast either
 operand to uint64_t const before performing the multiplication.

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

index 706d75ada17643459f685ff630c5dbc89c01831e..ca0b591a9162edd9548351e212328c3f33285177 100644 (file)
@@ -375,7 +375,7 @@ int HashIndex::pre_split_folder(uint32_t pg_num, uint64_t expected_num_objs)
 
   // Calculate the number of leaf folders (which actually store files)
   // need to be created
-  const uint64_t objs_per_folder = (unsigned)(abs(merge_threshold)) * 16 * split_multiplier;
+  const uint64_t objs_per_folder = (uint64_t)(abs(merge_threshold)) * (uint64_t)split_multiplier * 16;
   uint64_t leavies = expected_num_objs / objs_per_folder ;
   // No need to split
   if (leavies == 0 || expected_num_objs == objs_per_folder)