Remove S_ISREG check from sudo_edit_open(), it is already done in

the caller.
This commit is contained in:
Todd C. Miller
2015-10-02 20:35:55 -06:00
parent 37dff5fbcb
commit 6dc5151d5d

View File

@@ -159,20 +159,12 @@ static int
sudo_edit_open(const char *path, int oflags, mode_t mode, int sflags)
{
int fd;
struct stat sb;
if (!ISSET(sflags, CD_SUDOEDIT_FOLLOW))
oflags |= O_NOFOLLOW;
fd = open(path, oflags|O_NONBLOCK, mode);
if (fd != -1) {
if (!ISSET(oflags, O_NONBLOCK))
(void) fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) & ~O_NONBLOCK);
if (fstat(fd, &sb) == -1 || !S_ISREG(sb.st_mode)) {
close(fd);
fd = -1;
errno = EINVAL;
}
}
if (fd != -1 && !ISSET(oflags, O_NONBLOCK))
(void) fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) & ~O_NONBLOCK);
return fd;
}
#else
@@ -197,15 +189,6 @@ sudo_edit_open(const char *path, int oflags, mode_t mode, int sflags)
return -1;
}
/*
* Only open regular files.
*/
if (!S_ISREG(sb1.st_mode)) {
close(fd);
errno = EINVAL;
return -1;
}
/*
* Make sure we did not open a link and that what we opened
* matches what is currently on the file system.