From cf399edbc85b744450dfdb02b37efe37d1674cd6 Mon Sep 17 00:00:00 2001 From: YASUOKA Masahiko Date: Sun, 31 Mar 2019 03:36:19 +0000 Subject: 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 --- usr.sbin/ldpd/ldpd.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'usr.sbin/ldpd') diff --git a/usr.sbin/ldpd/ldpd.c b/usr.sbin/ldpd/ldpd.c index 7425d2030e5..d074b9e2329 100644 --- a/usr.sbin/ldpd/ldpd.c +++ b/usr.sbin/ldpd/ldpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ldpd.c,v 1.63 2019/01/23 02:02:04 dlg Exp $ */ +/* $OpenBSD: ldpd.c,v 1.64 2019/03/31 03:36:18 yasuoka Exp $ */ /* * Copyright (c) 2013, 2016 Renato Westphal @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -330,7 +331,10 @@ start_child(enum ldpd_process 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; -- cgit v1.2.3