]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/filestore: always always add `\0' after strncpy() 28289/head
authorKefu Chai <kchai@redhat.com>
Wed, 29 May 2019 09:48:21 +0000 (17:48 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 29 May 2019 09:49:44 +0000 (17:49 +0800)
see also f35fa1c58cf24275458cb83097c57bdfd1184cf8

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/os/filestore/BtrfsFileStoreBackend.cc

index 2ff2000d709166cb7f91fca2374741d92c11773f..d2d016e790fe471e466348ea41c3333050f12f01 100644 (file)
@@ -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) {