]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
object: generate file_object string in a safer way
authorxie xingguo <xie.xingguo@zte.com.cn>
Tue, 8 Mar 2016 07:10:02 +0000 (15:10 +0800)
committerxie xingguo <xie.xingguo@zte.com.cn>
Tue, 15 Mar 2016 11:05:40 +0000 (19:05 +0800)
Make sure the file_object string will be bigger enough
(e.g., should be 16(for ino) + 1(for dot) + 16(for bno) +
1(for nul terminator) == 34 at maximum).
And update sprintf to snprintf correspondingly, which is
safer.

Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
src/include/object.h

index bdc15b52cbc2cb097e2395ae3d5faf93c5a9dc25..74a011b961a27ad625ee2e7fbfa4dd73a0b27489 100644 (file)
@@ -89,7 +89,7 @@ namespace std {
 
 struct file_object_t {
   uint64_t ino, bno;
-  mutable char buf[33];
+  mutable char buf[34];
 
   file_object_t(uint64_t i=0, uint64_t b=0) : ino(i), bno(b) {
     buf[0] = 0;
@@ -97,7 +97,7 @@ struct file_object_t {
   
   const char *c_str() const {
     if (!buf[0])
-      sprintf(buf, "%llx.%08llx", (long long unsigned)ino, (long long unsigned)bno);
+      snprintf(buf, sizeof(buf), "%llx.%08llx", (long long unsigned)ino, (long long unsigned)bno);
     return buf;
   }