Skip to content

Commit

Permalink
preload: Fix reading /proc/self/fd/ links
Browse files Browse the repository at this point in the history
readlink() does not NUL-terminate by itself, it needs to be done
manually. Spotted by coverity.
  • Loading branch information
martinpitt committed Nov 24, 2022
1 parent f570371 commit 0bd0292
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/libumockdev-preload.c
Original file line number Diff line number Diff line change
Expand Up @@ -1466,10 +1466,11 @@ static bool is_fd_in_mock(int fd, const char *subdir)
int orig_errno = errno;
ssize_t linklen = _readlink(fdpath, linkpath, sizeof linkpath);
errno = orig_errno;
if (linklen < 0) {
if (linklen < 0 || linklen >= sizeof linkpath) {
perror("umockdev: failed to map fd to a path");
return false;
}
linkpath[linklen] = '\0';

return is_dir_or_contained(linkpath, getenv("UMOCKDEV_DIR"), subdir);
}
Expand Down

0 comments on commit 0bd0292

Please sign in to comment.