diff options
author | Guy Harris <gharris@sonic.net> | 2020-09-30 11:37:30 -0700 |
---|---|---|
committer | Denis Ovsienko <denis@ovsienko.info> | 2022-02-10 00:32:40 +0000 |
commit | 8ab211a7ec728bb0ad8c766c8eeb12deb0a13b86 (patch) | |
tree | 6d6d3477140767f5621571fedfb41ec1fc4f58a6 /tcpdump.c | |
parent | edeba67b9c01eacde50120e1a152dc67c9562fb2 (diff) | |
download | tcpdump-4.9.tar.gz |
Handle very large -f files by rejecting them.tcpdump-4.9
_read(), on Windows, has a 32-bit size argument and a 32-bit return
value, so reject -f files that have more than 2^31-1 characters.
Add some #defines so that, on Windows, we use _fstati64 to get the size
of that file, to handle large files.
Don't assume that our definition for ssize_t is the same size as size_t;
by the time we want to print the return value of the read, we know it'll
fit into an int, so just cast it to int and print it with %d.
(cherry picked from commit faf8fb70af3a013e5d662b8283dec742fd6b1a77)
Diffstat (limited to 'tcpdump.c')
-rw-r--r-- | tcpdump.c | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -108,6 +108,7 @@ The Regents of the University of California. All rights reserved.\n"; #endif /* HAVE_CAP_NG_H */ #endif /* HAVE_LIBCAP_NG */ +#include "netdissect-stdinc.h" #include "netdissect.h" #include "interface.h" #include "addrtoname.h" @@ -861,15 +862,22 @@ read_infile(char *fname) { register int i, fd, cc; register char *cp; - struct stat buf; + our_statb buf; fd = open(fname, O_RDONLY|O_BINARY); if (fd < 0) error("can't open %s: %s", fname, pcap_strerror(errno)); - if (fstat(fd, &buf) < 0) + if (our_fstat(fd, &buf) < 0) error("can't stat %s: %s", fname, pcap_strerror(errno)); + /* + * Reject files whose size doesn't fit into an int; a filter + * *that* large will probably be too big. + */ + if (buf.st_size > INT_MAX) + error("%s is too large", fname); + cp = malloc((u_int)buf.st_size + 1); if (cp == NULL) error("malloc(%d) for %s: %s", (u_int)buf.st_size + 1, @@ -878,7 +886,8 @@ read_infile(char *fname) if (cc < 0) error("read %s: %s", fname, pcap_strerror(errno)); if (cc != buf.st_size) - error("short read %s (%d != %d)", fname, cc, (int)buf.st_size); + error("short read %s (%d != %d)", fname, (int) cc, + (int)buf.st_size); close(fd); /* replace "# comment" with spaces */ |