From: Frank Cusack Date: Mon, 24 Feb 2003 12:46:37 +0000 (+0000) Subject: device_script(): fix our close() action for the case where in or out <= 2; X-Git-Tag: ppp-2.4.7~326 X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=commitdiff_plain;h=96d6d93dc44fc9c76cdaf7ada6deaf515f18680e device_script(): fix our close() action for the case where in or out <= 2; also don't leak [the original fd of] a dup()'d log_to_fd, when log_to_fd is > 2. --- diff --git a/pppd/main.c b/pppd/main.c index 2c261e7..5f30dd1 100644 --- a/pppd/main.c +++ b/pppd/main.c @@ -40,7 +40,7 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define RCSID "$Id: main.c,v 1.121 2003/02/24 11:26:57 fcusack Exp $" +#define RCSID "$Id: main.c,v 1.122 2003/02/24 12:46:37 fcusack Exp $" #include #include @@ -1455,16 +1455,19 @@ device_script(program, in, out, dont_wait) } /* dup in and out to fds > 2 */ - fd = in; - in = dup(in); - close(fd); - fd = out; - out = dup(out); - close(fd); - if (log_to_fd >= 0) { - errfd = dup(log_to_fd); - } else { - errfd = open(_PATH_CONNERRS, O_WRONLY | O_APPEND | O_CREAT, 0600); + { + int fd1 = in, fd2 = out, fd3 = log_to_fd; + + in = dup(in); + out = dup(out); + if (log_to_fd >= 0) { + errfd = dup(log_to_fd); + } else { + errfd = open(_PATH_CONNERRS, O_WRONLY | O_APPEND | O_CREAT, 0600); + } + close(fd1); + close(fd2); + close(fd3); } /* close fds 0 - 2 and any others we can think of */