From 8de0c66a4c16a6a4558a684cdc0888c936393f22 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Thu, 30 Aug 2001 23:24:47 +0000 Subject: When using dup2() to make a socket be stdout, first check that it is not already stdout (fd 1). Otherwise we end up closing stdout which is not the intention. Also use STDOUT_FILENO instead of 1. From a conversation with huntting@glarp.com. --- usr.sbin/lpr/lpd/lpd.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'usr.sbin/lpr/lpd') diff --git a/usr.sbin/lpr/lpd/lpd.c b/usr.sbin/lpr/lpd/lpd.c index a41d85c6f17..9123a23143d 100644 --- a/usr.sbin/lpr/lpd/lpd.c +++ b/usr.sbin/lpr/lpd/lpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lpd.c,v 1.18 2001/08/30 17:38:13 millert Exp $ */ +/* $OpenBSD: lpd.c,v 1.19 2001/08/30 23:24:46 millert Exp $ */ /* $NetBSD: lpd.c,v 1.7 1996/04/24 14:54:06 mrg Exp $ */ /* @@ -45,7 +45,7 @@ static const char copyright[] = #if 0 static const char sccsid[] = "@(#)lpd.c 8.7 (Berkeley) 5/10/95"; #else -static const char rcsid[] = "$OpenBSD: lpd.c,v 1.18 2001/08/30 17:38:13 millert Exp $"; +static const char rcsid[] = "$OpenBSD: lpd.c,v 1.19 2001/08/30 23:24:46 millert Exp $"; #endif #endif /* not lint */ @@ -288,8 +288,10 @@ main(argc, argv) signal(SIGTERM, SIG_IGN); (void) close(funix); (void) close(finet); - dup2(s, 1); - (void) close(s); + if (s != STDOUT_FILENO) { + dup2(s, STDOUT_FILENO); + (void) close(s); + } if (domain == AF_INET) { from_remote = 1; chkhost(&frominet); -- cgit v1.2.3