diff options
author | Anil Madhavapeddy <avsm@cvs.openbsd.org> | 2004-04-03 10:20:52 +0000 |
---|---|---|
committer | Anil Madhavapeddy <avsm@cvs.openbsd.org> | 2004-04-03 10:20:52 +0000 |
commit | 117e324e20911fbfec77141636db44afc9650cab (patch) | |
tree | 6f7144fc6fa88cdf5b73068293ff4549cd8ec3ae | |
parent | ffb1845ba5f98ec0a4b7f8c4f626b8ad4c76f7a6 (diff) |
- dont send junk err in parent_open_dump() if filename is NULL
- dont close an invalid fd
canacar@ ok
-rw-r--r-- | usr.sbin/tcpdump/privsep.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/usr.sbin/tcpdump/privsep.c b/usr.sbin/tcpdump/privsep.c index feed7d69d5f..1223e83e4a3 100644 --- a/usr.sbin/tcpdump/privsep.c +++ b/usr.sbin/tcpdump/privsep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: privsep.c,v 1.5 2004/03/14 19:17:05 otto Exp $ */ +/* $OpenBSD: privsep.c,v 1.6 2004/04/03 10:20:51 avsm Exp $ */ /* * Copyright (c) 2003 Can Erkin Acar @@ -301,7 +301,7 @@ parent_open_bpf(int fd, int *bpfd) static void parent_open_dump(int fd, const char *RFileName) { - int file, err; + int file, err = 0; logmsg(LOG_DEBUG, "[priv]: msg PRIV_OPEN_DUMP received"); @@ -317,7 +317,8 @@ parent_open_dump(int fd, const char *RFileName) } send_fd(fd, file); must_write(fd, &err, sizeof(int)); - close(file); + if (file >= 0) + close(file); } static void @@ -329,13 +330,13 @@ parent_open_output(int fd, const char *WFileName) file = open(WFileName, O_WRONLY|O_CREAT|O_TRUNC, 0666); err = errno; + send_fd(fd, file); + must_write(fd, &err, sizeof(int)); if (file < 0) logmsg(LOG_DEBUG, "[priv]: failed to open %s: %s", WFileName, strerror(errno)); - - send_fd(fd, file); - must_write(fd, &err, sizeof(int)); - close(file); + else + close(file); } static void |