summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2013-07-22 11:23:12 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2013-07-22 11:23:13 -0700
commit1d1934caf1c927cb12cd76aa6ced9eab51a3d435 (patch)
tree7221825fc2700eb3b743335c2dc2b55e22b4d0c8
parentMerge branch 'mm/color-auto-default' (diff)
parentrun-command: dup_devnull(): guard against syscalls failing (diff)
downloadtgif-1d1934caf1c927cb12cd76aa6ced9eab51a3d435.tar.xz
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()
-rw-r--r--run-command.c5
-rw-r--r--wrapper.c2
2 files changed, 5 insertions, 2 deletions
diff --git a/run-command.c b/run-command.c
index aece872e33..1b7f88eeb1 100644
--- a/run-command.c
+++ b/run-command.c
@@ -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
diff --git a/wrapper.c b/wrapper.c
index dd7ecbb115..6a015de5f0 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -322,7 +322,7 @@ int git_mkstemps_mode(char *pattern, int suffix_len, int mode)
template[5] = letters[v % num_letters]; v /= num_letters;
fd = open(pattern, O_CREAT | O_EXCL | O_RDWR, mode);
- if (fd > 0)
+ if (fd >= 0)
return fd;
/*
* Fatal error (EPERM, ENOSPC etc).