From: Sage Weil Date: Fri, 24 Mar 2017 16:23:57 +0000 (-0400) Subject: common/blkdev: pass size_t to get_device_by_fd X-Git-Tag: v12.0.2~164^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d102c2e418eda03561f727c98675ccd54ce34a33;p=ceph.git common/blkdev: pass size_t to get_device_by_fd Signed-off-by: Sage Weil --- diff --git a/src/common/blkdev.cc b/src/common/blkdev.cc index bc89eea4cf14..4b1f6998a749 100644 --- a/src/common/blkdev.cc +++ b/src/common/blkdev.cc @@ -245,7 +245,7 @@ int get_device_by_uuid(uuid_d dev_uuid, const char* label, char* partition, return rc; } -int get_device_by_fd(int fd, char *partition, char *device) +int get_device_by_fd(int fd, char *partition, char *device, size_t max) { struct stat st; int r = fstat(fd, &st); @@ -257,10 +257,10 @@ int get_device_by_fd(int fd, char *partition, char *device) if (!t) { return -EINVAL; } - strcpy(partition, t); + strncpy(partition, t, max); free(t); dev_t diskdev; - r = blkid_devno_to_wholedisk(devid, device, PATH_MAX, &diskdev); + r = blkid_devno_to_wholedisk(devid, device, max, &diskdev); if (r < 0) { return -EINVAL; } diff --git a/src/common/blkdev.h b/src/common/blkdev.h index dff0388f8a89..eef3a25cab89 100644 --- a/src/common/blkdev.h +++ b/src/common/blkdev.h @@ -10,7 +10,7 @@ extern int get_block_device_base(const char *path, char *devname, size_t len); // from an fd extern int block_device_discard(int fd, int64_t offset, int64_t len); extern int get_block_device_size(int fd, int64_t *psize); -extern int get_device_by_fd(int fd, char* partition, char* device); +extern int get_device_by_fd(int fd, char* partition, char* device, size_t max); // from a uuid extern int get_device_by_uuid(uuid_d dev_uuid, const char* label, diff --git a/src/os/bluestore/KernelDevice.cc b/src/os/bluestore/KernelDevice.cc index 3ae091ab4b33..1d338b27527d 100644 --- a/src/os/bluestore/KernelDevice.cc +++ b/src/os/bluestore/KernelDevice.cc @@ -120,8 +120,8 @@ int KernelDevice::open(const string& p) } { - char partition[1024], devname[1024]; - r = get_device_by_fd(fd_buffered, partition, devname); + char partition[PATH_MAX], devname[PATH_MAX]; + r = get_device_by_fd(fd_buffered, partition, devname, sizeof(devname)); if (r < 0) { derr << "unable to get device name for " << path << ": " << cpp_strerror(r) << dendl; @@ -217,7 +217,7 @@ int KernelDevice::collect_metadata(string prefix, map *pm) const (*pm)[prefix + "access_mode"] = "blk"; char partition_path[PATH_MAX]; char dev_node[PATH_MAX]; - int rc = get_device_by_fd(fd_buffered, partition_path, dev_node); + int rc = get_device_by_fd(fd_buffered, partition_path, dev_node, PATH_MAX); switch (rc) { case -EOPNOTSUPP: case -EINVAL: