Skip to content

Commit a77f106

Browse files
Thomas Rastgitster
authored andcommitted
run-command: dup_devnull(): guard against syscalls failing
dup_devnull() did not check the return values of open() and dup2(). Fix this omission. Signed-off-by: Thomas Rast <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a2cb86c commit a77f106

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

run-command.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ static inline void close_pair(int fd[2])
7676
static inline void dup_devnull(int to)
7777
{
7878
int fd = open("/dev/null", O_RDWR);
79-
dup2(fd, to);
79+
if (fd < 0)
80+
die_errno(_("open /dev/null failed"));
81+
if (dup2(fd, to) < 0)
82+
die_errno(_("dup2(%d,%d) failed"), fd, to);
8083
close(fd);
8184
}
8285
#endif

0 commit comments

Comments
 (0)