summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Borkmann <dborkman@redhat.com>2013-03-16 13:40:19 +0100
committerDaniel Borkmann <dborkman@redhat.com>2013-03-16 13:40:19 +0100
commit30e1aafbae487e63a1f1f294391bbdc993808c4b (patch)
tree9c9bee0368574c020df7ebcc1ac0a42abf9f292c
parent7cd3e9e94ae848974d52b929fd28652f4c7d48c5 (diff)
netsniff-ng: do not leak file descriptors on exit
Covertiy detected that when we redirect sdtin/stdout either via ``-i -'' or ``-o -'', we also need to properly close it when it goes out of scope. Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
-rw-r--r--netsniff-ng.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/netsniff-ng.c b/netsniff-ng.c
index ad5fd04..94fb313 100644
--- a/netsniff-ng.c
+++ b/netsniff-ng.c
@@ -289,10 +289,9 @@ static void pcap_to_xmit(struct ctx *ctx)
if (__pcap_io->prepare_close_pcap)
__pcap_io->prepare_close_pcap(fd, PCAP_MODE_RD);
- if (strncmp("-", ctx->device_in, strlen("-")))
- close(fd);
- else
+ if (!strncmp("-", ctx->device_in, strlen("-")))
dup2(fd, fileno(stdin));
+ close(fd);
close(tx_sock);
@@ -619,16 +618,14 @@ static void read_pcap(struct ctx *ctx)
printf("\r%12lu bytes outgoing\n", ctx->tx_bytes);
printf("\r%12lu sec, %lu usec in total\n", diff.tv_sec, diff.tv_usec);
- if (strncmp("-", ctx->device_in, strlen("-")))
- close(fd);
- else
+ if (!strncmp("-", ctx->device_in, strlen("-")))
dup2(fd, fileno(stdin));
+ close(fd);
if (ctx->device_out) {
- if (strncmp("-", ctx->device_out, strlen("-")))
- close(fdo);
- else
+ if (!strncmp("-", ctx->device_out, strlen("-")))
dup2(fdo, fileno(stdout));
+ close(fdo);
}
}