Skip to content

Commit

Permalink
os/bluestore: null terminate readlink() result
Browse files Browse the repository at this point in the history
readlink() does not guarantee null termination of
result.

Signed-off-by: Yehuda Sadeh <[email protected]>
  • Loading branch information
yehudasa committed Nov 7, 2016
1 parent 20c3fd8 commit bfdf2c6
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/os/bluestore/BlockDevice.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit bfdf2c6

Please sign in to comment.