From 44b463529a8a9f2ccd1ec2acb8a4dfc117a636cb Mon Sep 17 00:00:00 2001 From: Daniel Borkmann Date: Wed, 12 Jun 2013 14:11:06 +0200 Subject: netsniff-ng: walk_t3_block: prevent fd from double close Only close the very first pcap file of multi-pcap files once, and not once during next_multi_pcap_file and once during exit. Discovered by Coverty scanner. Signed-off-by: Daniel Borkmann --- netsniff-ng.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/netsniff-ng.c b/netsniff-ng.c index ec4faeb..14ce8f2 100644 --- a/netsniff-ng.c +++ b/netsniff-ng.c @@ -812,7 +812,7 @@ static void print_pcap_file_stats(int sock, struct ctx *ctx) } static void walk_t3_block(struct block_desc *pbd, struct ctx *ctx, - int sock, int fd, unsigned long *frame_count) + int sock, int *fd, unsigned long *frame_count) { uint8_t *packet; int num_pkts = pbd->h1.num_pkts, i, ret; @@ -836,7 +836,7 @@ static void walk_t3_block(struct block_desc *pbd, struct ctx *ctx, if (dump_to_pcap(ctx)) { tpacket3_hdr_to_pcap_pkthdr(hdr, sll, &phdr, ctx->magic); - ret = __pcap_io->write_pcap(fd, &phdr, ctx->magic, packet, + ret = __pcap_io->write_pcap(*fd, &phdr, ctx->magic, packet, pcap_get_length(&phdr, ctx->magic)); if (unlikely(ret != pcap_get_total_length(&phdr, ctx->magic))) panic("Write error to pcap!\n"); @@ -868,7 +868,7 @@ static void walk_t3_block(struct block_desc *pbd, struct ctx *ctx, } if (next_dump) { - fd = next_multi_pcap_file(ctx, fd); + *fd = next_multi_pcap_file(ctx, *fd); next_dump = false; if (unlikely(ctx->verbose)) @@ -971,7 +971,7 @@ static void recv_only_or_dump(struct ctx *ctx) while (likely(sigint == 0)) { while (user_may_pull_from_rx_block((pbd = (void *) rx_ring.frames[it].iov_base))) { - walk_t3_block(pbd, ctx, sock, fd, &frame_count); + walk_t3_block(pbd, ctx, sock, &fd, &frame_count); kernel_may_pull_from_rx_block(pbd); it = (it + 1) % rx_ring.layout3.tp_block_nr; -- cgit v1.2.3-54-g00ecf