Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 1d1934c

Browse files
committed
Merge branch 'tr/fd-gotcha-fixes'
Two places we did not check return value (expected to be a file descriptor) correctly. * tr/fd-gotcha-fixes: run-command: dup_devnull(): guard against syscalls failing git_mkstemps: correctly test return value of open()
2 parents 6a5b9ce + a77f106 commit 1d1934c

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
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

wrapper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ int git_mkstemps_mode(char *pattern, int suffix_len, int mode)
322322
template[5] = letters[v % num_letters]; v /= num_letters;
323323

324324
fd = open(pattern, O_CREAT | O_EXCL | O_RDWR, mode);
325-
if (fd > 0)
325+
if (fd >= 0)
326326
return fd;
327327
/*
328328
* Fatal error (EPERM, ENOSPC etc).

0 commit comments

Comments
 (0)