]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Adapted from a more extensive change from Chris Cogdon
authorguy <guy>
Mon, 26 Jan 2004 01:42:17 +0000 (01:42 +0000)
committerguy <guy>
Mon, 26 Jan 2004 01:42:17 +0000 (01:42 +0000)
<[email protected]>: check whether the file number for "-C" is too large
to fit in the buffer we allocated for the file name.

Close the current capture file before trying to allocate the buffer for
the new file's name, so that if that allocation fails we've at least
written out all of the previous file.

CREDITS
tcpdump.c

diff --git a/CREDITS b/CREDITS
index 36b967dda18f5063d4a756bada21d9e859946a7f..b5c286c2b6058aa696e51ffa3bac35d29a37c1e8 100644 (file)
--- a/CREDITS
+++ b/CREDITS
@@ -24,6 +24,7 @@ Additional people who have contributed patches:
        Carles Kishimoto Bisbe          <[email protected]>
        Charlie Lenahan                 <[email protected]>
        Charles M. Hannum               <[email protected]>
+       Chris Cogdon                    <[email protected]>
        Chris G. Demetriou              <[email protected]>
        Chris Jepeway                   <[email protected]>
        Craig Rodrigues                 <[email protected]>
index aa4b39846d55a9b1c9ffdd8107fb2862dfad328c..a1e46c62f5360884d1d2d38dd9735b3706e6e8e5 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -30,7 +30,7 @@ static const char copyright[] _U_ =
     "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\
 The Regents of the University of California.  All rights reserved.\n";
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.216.2.7 2004-01-14 03:25:28 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.216.2.8 2004-01-26 01:42:18 guy Exp $ (LBL)";
 #endif
 
 /*
@@ -941,13 +941,18 @@ dump_packet_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *s
         * file could put it over Cflag.
         */
        if (ftell((FILE *)dump_info->p) > Cflag) {
+               /*
+                * Close the current file and open a new one.
+                */
+               pcap_dump_close(dump_info->p);
                name = (char *) malloc(strlen(dump_info->WFileName) + 4);
                if (name == NULL)
                        error("dump_packet_and_trunc: malloc");
                strcpy(name, dump_info->WFileName);
+               if (cnt >= 1000)
+                       error("too many output files");
                swebitoa(cnt, name + strlen(dump_info->WFileName));
                cnt++;
-               pcap_dump_close(dump_info->p);
                dump_info->p = pcap_dump_open(dump_info->pd, name);
                free(name);
                if (dump_info->p == NULL)