From: Kefu Chai Date: Wed, 29 May 2019 09:48:21 +0000 (+0800) Subject: os/filestore: always always add `\0' after strncpy() X-Git-Tag: v15.1.0~2605^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f434b61dbe4c282e76f56704c9aad3af5b0b1f07;p=ceph.git os/filestore: always always add `\0' after strncpy() see also f35fa1c58cf24275458cb83097c57bdfd1184cf8 Signed-off-by: Kefu Chai --- diff --git a/src/os/filestore/BtrfsFileStoreBackend.cc b/src/os/filestore/BtrfsFileStoreBackend.cc index 2ff2000d7091..d2d016e790fe 100644 --- a/src/os/filestore/BtrfsFileStoreBackend.cc +++ b/src/os/filestore/BtrfsFileStoreBackend.cc @@ -466,7 +466,8 @@ int BtrfsFileStoreBackend::destroy_checkpoint(const string& name) btrfs_ioctl_vol_args vol_args; memset(&vol_args, 0, sizeof(vol_args)); vol_args.fd = 0; - strncpy(vol_args.name, name.c_str(), sizeof(vol_args.name)); + strncpy(vol_args.name, name.c_str(), sizeof(vol_args.name) - 1); + vol_args.name[sizeof(vol_args.name) - 1] = '\0'; int ret = ::ioctl(get_basedir_fd(), BTRFS_IOC_SNAP_DESTROY, &vol_args); if (ret) {