From: xie xingguo Date: Fri, 6 May 2016 08:40:18 +0000 (+0800) Subject: osd: don't get inc osdmap name truncated X-Git-Tag: v11.0.0~541^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8de5d887129524f7a246ff5068a6bd8cc369aabe;p=ceph.git osd: don't get inc osdmap name truncated By definition, epoch_t is of type __u32 and shall allow 13 epochs/second for 10 years. The biggest epoch we can ever see is 4294967296, which is 10 chars long. However, by declaring "char foo[20];" here, we leave 8 chars (20 - 11("inc_osdmap.") - 1('\0') = 8) for the epoch field only, so the epoch will get truncated when it becomes big enough, which is unsafe. Signed-off-by: xie xingguo --- diff --git a/src/osd/OSD.h b/src/osd/OSD.h index cdf2afd45dc2..c2ff47e7e7b4 100644 --- a/src/osd/OSD.h +++ b/src/osd/OSD.h @@ -1146,7 +1146,7 @@ public: return ghobject_t(hobject_t(sobject_t(object_t(foo), 0))); } static ghobject_t get_inc_osdmap_pobject_name(epoch_t epoch) { - char foo[20]; + char foo[22]; snprintf(foo, sizeof(foo), "inc_osdmap.%d", epoch); return ghobject_t(hobject_t(sobject_t(object_t(foo), 0))); }