]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
FileJournal: fix potential overflow in create()
authorSamuel Just <sam.just@inktank.com>
Tue, 25 Sep 2012 21:18:19 +0000 (14:18 -0700)
committerSamuel Just <sam.just@inktank.com>
Tue, 25 Sep 2012 21:59:29 +0000 (14:59 -0700)
CID 717016: Unintentional integer overflow (OVERFLOW_BEFORE_WIDEN)At (1):
Potentially overflowing expression "g_conf->osd_max_write_size << 20" with type
"int" (32 bits, signed) is evaluated using 32-bit arithmetic before being used
in a context which expects an expression of type "int64_t" (64 bits, signed).
To avoid overflow, cast the left operand to "int64_t" before performing the
left shift.

Signed-off-by: Samuel Just <sam.just@inktank.com>
src/os/FileJournal.cc

index 8a15e9517ba5a147e8ca656deac95f66d986eee7..eec5c9d320c2cf3c24195968dad7e159b2614c60 100644 (file)
@@ -427,7 +427,7 @@ int FileJournal::create()
     goto free_buf;
   }
 
-  needed_space = g_conf->osd_max_write_size << 20;
+  needed_space = ((int64_t)g_conf->osd_max_write_size) << 20;
   needed_space += (2 * sizeof(entry_header_t)) + get_top();
   if (header.max_size - header.start < needed_space) {
     derr << "FileJournal::create: OSD journal is not large enough to hold "