From: xie xingguo Date: Tue, 8 Mar 2016 07:10:02 +0000 (+0800) Subject: object: generate file_object string in a safer way X-Git-Tag: v10.1.0~42^2~9 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=07559158eeaf7e667d3eb8037039fbf1b8e1104f;p=ceph.git object: generate file_object string in a safer way 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 --- diff --git a/src/include/object.h b/src/include/object.h index bdc15b52cbc2..74a011b961a2 100644 --- a/src/include/object.h +++ b/src/include/object.h @@ -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; }