]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
os/bluestore: null terminate readlink() result
authorYehuda Sadeh <yehuda@redhat.com>
Mon, 7 Nov 2016 23:42:04 +0000 (15:42 -0800)
committerYehuda Sadeh <yehuda@redhat.com>
Mon, 7 Nov 2016 23:42:04 +0000 (15:42 -0800)
readlink() does not guarantee null termination of
result.

Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/os/bluestore/BlockDevice.cc

index 829b47e6941485badc6104dbecd8d826d97ebcc8..bd2b09090ffaf33e76cbeb8d48b2b218cb325d18 100644 (file)
@@ -46,9 +46,10 @@ void IOContext::aio_wait()
 BlockDevice *BlockDevice::create(const string& path, aio_callback_t cb, void *cbpriv)
 {
   string type = "kernel";
-  char buf[PATH_MAX];
-  int r = ::readlink(path.c_str(), buf, sizeof(buf));
+  char buf[PATH_MAX + 1];
+  int r = ::readlink(path.c_str(), buf, sizeof(buf) - 1);
   if (r >= 0) {
+    buf[r] = '\0';
     char *bname = ::basename(buf);
     if (strncmp(bname, SPDK_PREFIX, sizeof(SPDK_PREFIX)-1) == 0)
       type = "ust-nvme";