]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/blkdev: pass size_t to get_device_by_fd
authorSage Weil <sage@redhat.com>
Fri, 24 Mar 2017 16:23:57 +0000 (12:23 -0400)
committerSage Weil <sage@redhat.com>
Wed, 29 Mar 2017 17:25:11 +0000 (13:25 -0400)
Signed-off-by: Sage Weil <sage@redhat.com>
src/common/blkdev.cc
src/common/blkdev.h
src/os/bluestore/KernelDevice.cc

index bc89eea4cf14fdd06a6990bcc82a7af501b1b3da..4b1f6998a7490724af5cd849c3745bc2d1aa3490 100644 (file)
@@ -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;
   }
index dff0388f8a893828d9675d6fa8718b317f57c907..eef3a25cab89b74e1f1e11633611067ed62bb671 100644 (file)
@@ -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,
index 3ae091ab4b33c9244f22b92a513691ffb5b50dbd..1d338b27527dab7e1bf15d1ea12c7c2ef9e9f587 100644 (file)
@@ -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<string,string> *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: