diff options
author | YASUOKA Masahiko <yasuoka@cvs.openbsd.org> | 2019-03-31 03:36:19 +0000 |
---|---|---|
committer | YASUOKA Masahiko <yasuoka@cvs.openbsd.org> | 2019-03-31 03:36:19 +0000 |
commit | cf399edbc85b744450dfdb02b37efe37d1674cd6 (patch) | |
tree | c37c8be974fd886794ed8ea97f1302e68ff789e2 /sbin/unwind | |
parent | fd28b16511cd31e835d2f1d4bcce7238d07285a6 (diff) |
Avoid calling dup2(oldd, newd) when oldd == newd. In that case the
descriptor keeps CLOEXEC flag then it will be closed unexpectedly by
exec().
ok tedu florian
Diffstat (limited to 'sbin/unwind')
-rw-r--r-- | sbin/unwind/unwind.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/sbin/unwind/unwind.c b/sbin/unwind/unwind.c index 74b8c6ca37e..65da1475953 100644 --- a/sbin/unwind/unwind.c +++ b/sbin/unwind/unwind.c @@ -1,4 +1,4 @@ -/* $OpenBSD: unwind.c,v 1.21 2019/03/31 00:57:06 tedu Exp $ */ +/* $OpenBSD: unwind.c,v 1.22 2019/03/31 03:36:18 yasuoka Exp $ */ /* * Copyright (c) 2018 Florian Obser <florian@openbsd.org> @@ -372,7 +372,10 @@ start_child(int p, char *argv0, int fd, int debug, int verbose) return (pid); } - if (dup2(fd, 3) == -1) + if (fd != 3) { + if (dup2(fd, 3) == -1) + fatal("cannot setup imsg fd"); + } else if (fcntl(fd, F_SETFD, 0) == -1) fatal("cannot setup imsg fd"); argv[argc++] = argv0; |