readlink() does not guarantee null termination of
result.
Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
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";