Skip to content

Commit

Permalink
run-command: dup_devnull(): guard against syscalls failing
Browse files Browse the repository at this point in the history
dup_devnull() did not check the return values of open() and dup2().
Fix this omission.

Signed-off-by: Thomas Rast <trast@inf.ethz.ch>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Thomas Rast authored and Junio C Hamano committed Jul 12, 2013
1 parent a2cb86c commit a77f106
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion run-command.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ static inline void close_pair(int fd[2])
static inline void dup_devnull(int to)
{
int fd = open("/dev/null", O_RDWR);
dup2(fd, to);
if (fd < 0)
die_errno(_("open /dev/null failed"));
if (dup2(fd, to) < 0)
die_errno(_("dup2(%d,%d) failed"), fd, to);
close(fd);
}
#endif
Expand Down

0 comments on commit a77f106

Please sign in to comment.