correct snprintf truncation check in closefrom()

Truncation cannot happen unless the system has set PATH_MAX to some
nonsensically low value.

bz#2862, patch from Daniel Le
This commit is contained in:
Damien Miller 2018-07-27 14:15:28 +10:00
parent 149cab325a
commit 4492e2ec4e

View File

@ -77,7 +77,7 @@ closefrom(int lowfd)
/* Check for a /proc/$$/fd directory. */
len = snprintf(fdpath, sizeof(fdpath), "/proc/%ld/fd", (long)getpid());
if (len > 0 && (size_t)len <= sizeof(fdpath) && (dirp = opendir(fdpath))) {
if (len > 0 && (size_t)len < sizeof(fdpath) && (dirp = opendir(fdpath))) {
while ((dent = readdir(dirp)) != NULL) {
fd = strtol(dent->d_name, &endp, 10);
if (dent->d_name != endp && *endp == '\0' &&