From: Yehuda Sadeh Date: Mon, 7 Nov 2016 23:42:04 +0000 (-0800) Subject: os/bluestore: null terminate readlink() result X-Git-Tag: v11.1.0~362^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=bfdf2c62297a2a21d93646af65ae055e6eb90e8c;p=ceph.git os/bluestore: null terminate readlink() result readlink() does not guarantee null termination of result. Signed-off-by: Yehuda Sadeh --- diff --git a/src/os/bluestore/BlockDevice.cc b/src/os/bluestore/BlockDevice.cc index 829b47e69414..bd2b09090ffa 100644 --- a/src/os/bluestore/BlockDevice.cc +++ b/src/os/bluestore/BlockDevice.cc @@ -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";