]> git.apps.os.sepia.ceph.com Git - ceph.git/commit
common/blkdev.c: check retval of snprintf()
authorKefu Chai <kchai@redhat.com>
Wed, 29 May 2019 09:45:35 +0000 (17:45 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 29 May 2019 09:49:44 +0000 (17:49 +0800)
commitae466a0089fb4802751e5c9c5d79aa29426ace91
treeaaf0d5628e9eb5fdedd4087fc4d31cb6361229d5
parent41d2a9578ae4f5f990571d108b9a1787afed1be3
common/blkdev.c: check retval of snprintf()

as snprintf()'ed string could be truncated, to properly use this
function, we need to check its return value.

to silence warning like

../src/common/blkdev.cc: In member function ‘int64_t
BlkDev::get_string_property(blkdev_prop_t, char*, size_t) const’:
../src/common/blkdev.cc:165:15: warning: ‘%s’ directive output may be
truncated writing up to 4095 bytes into a region of size between 4085
and 4089 [-Wformat-truncation=]
  165 |     "%s/block/%s/%s", sysfsdir(), dev, propstr);
      |               ^~
In file included from /usr/include/stdio.h:873,
                 from /usr/include/c++/9/cstdio:42,
                 from /usr/include/c++/9/ext/string_conversions.h:43,
                 from /usr/include/c++/9/bits/basic_string.h:6493,
                 from /usr/include/c++/9/string:55,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iterator:64,
                 from
/opt/ceph/include/boost/iterator/iterator_traits.hpp:10,
                 from
/opt/ceph/include/boost/range/iterator_range_core.hpp:26,
                 from
/opt/ceph/include/boost/algorithm/string/replace.hpp:16,
                 from ../src/common/blkdev.cc:31:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:67:35: note:
‘__builtin___snprintf_chk’ output 9 or more bytes (assuming 4108) into a
destination of size 4096
   67 |   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL
- 1,
      |
~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   68 |        __bos (__s), __fmt, __va_arg_pack ());
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/common/blkdev.cc