]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commit
osdc/Objecter: always add `\0' after strncpy()
authorKefu Chai <kchai@redhat.com>
Mon, 1 Apr 2019 03:09:28 +0000 (11:09 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 3 Apr 2019 10:56:49 +0000 (18:56 +0800)
commitf35fa1c58cf24275458cb83097c57bdfd1184cf8
tree688bf38ca352ef1de44fe779fcd6cf66aa7329b0
parent42f777e67d25816cb6ce607a778e87b187d32053
osdc/Objecter: always add `\0' after strncpy()

strncpy() does not ensure that the dest str is nul terminated, so we
need to add the nul terminator here. another option is strlcpy(), but it
need to link against libbsd if glibc is used.

this change also silences warning like

In function ‘char* strncpy(char*, const char*, size_t)’,
    inlined from ‘virtual void
ObjectOperation::C_ObjectOperation_decodewatchers::finish(int)’ at
../src/osdc/Objecter.h:534:15:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:34: warning:
‘char* __builtin_strncpy(char*, const char*, long unsigned int)’
specified bound 256 equals destination size [-Wstringop-truncation]
  106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos
(__dest));
      |
~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/osdc/Objecter.h