diff options
author | yasuoka <yasuoka@openbsd.org> | 2019-03-31 03:36:18 +0000 |
---|---|---|
committer | yasuoka <yasuoka@openbsd.org> | 2019-03-31 03:36:18 +0000 |
commit | ef4f5895abd850e5705ba18ff094fe48eb3d06cd (patch) | |
tree | f62d986aaee36319a44d595489a7dad07f385254 /usr.sbin/rad | |
parent | If using retguard, we do not also need the stack protector. (diff) | |
download | wireguard-openbsd-ef4f5895abd850e5705ba18ff094fe48eb3d06cd.tar.xz wireguard-openbsd-ef4f5895abd850e5705ba18ff094fe48eb3d06cd.zip |
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 'usr.sbin/rad')
-rw-r--r-- | usr.sbin/rad/rad.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/usr.sbin/rad/rad.c b/usr.sbin/rad/rad.c index d6e139a612f..f4e96ab319e 100644 --- a/usr.sbin/rad/rad.c +++ b/usr.sbin/rad/rad.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rad.c,v 1.19 2019/03/12 18:47:57 pamela Exp $ */ +/* $OpenBSD: rad.c,v 1.20 2019/03/31 03:36:18 yasuoka Exp $ */ /* * Copyright (c) 2018 Florian Obser <florian@openbsd.org> @@ -36,6 +36,7 @@ #include <err.h> #include <errno.h> #include <event.h> +#include <fcntl.h> #include <imsg.h> #include <netdb.h> #include <pwd.h> @@ -361,7 +362,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; |