From f434b61dbe4c282e76f56704c9aad3af5b0b1f07 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 29 May 2019 17:48:21 +0800 Subject: [PATCH] os/filestore: always always add `\0' after strncpy() see also f35fa1c58cf24275458cb83097c57bdfd1184cf8 Signed-off-by: Kefu Chai --- src/os/filestore/BtrfsFileStoreBackend.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/os/filestore/BtrfsFileStoreBackend.cc b/src/os/filestore/BtrfsFileStoreBackend.cc index 2ff2000d709..d2d016e790f 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) { -- 2.47.3