diff options
author | Guy Harris <guy@alum.mit.edu> | 2018-09-10 11:43:56 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2018-09-10 11:43:56 -0700 |
commit | ea4fb6ebfec645988eedb707411e84bb2646d326 (patch) | |
tree | 5db06e3785f34d06ec84819a36ae3f0e11ec0c47 /testprogs/filtertest.c | |
parent | 33156e96094ffe8303d8026fe71839ac55641d35 (diff) | |
download | libpcap-ea4fb6ebfec645988eedb707411e84bb2646d326.tar.gz |
Clean up -Wshorten-64-to-32 warnings in the test programs.
Clean up some other stuff while we're at it.
Diffstat (limited to 'testprogs/filtertest.c')
-rw-r--r-- | testprogs/filtertest.c | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/testprogs/filtertest.c b/testprogs/filtertest.c index 7e2d6d6e..17c07e10 100644 --- a/testprogs/filtertest.c +++ b/testprogs/filtertest.c @@ -36,6 +36,7 @@ The Regents of the University of California. All rights reserved.\n"; #include <stdlib.h> #include <string.h> #include <stdarg.h> +#include <limits.h> #ifdef _WIN32 #include "getopt.h" #include "unix.h" @@ -56,6 +57,8 @@ The Regents of the University of California. All rights reserved.\n"; #include "pcap/funcattrs.h" +#define MAXIMUM_SNAPLEN 262144 + #ifdef BDEBUG /* * We have pcap_set_optimizer_debug() and pcap_set_print_dot_graph() in @@ -99,11 +102,21 @@ read_infile(char *fname) if (fstat(fd, &buf) < 0) error("can't stat %s: %s", fname, pcap_strerror(errno)); + /* + * _read(), on Windows, has an unsigned int byte count and an + * int return value, so we can't handle a file bigger than + * INT_MAX - 1 bytes (and have no reason to do so; a filter *that* + * big will take forever to compile). (The -1 is for the '\0' at + * the end of the string.) + */ + if (buf.st_size > INT_MAX - 1) + error("%s is larger than %d bytes; that's too large", fname, + INT_MAX - 1); cp = malloc((u_int)buf.st_size + 1); if (cp == NULL) error("malloc(%d) for %s: %s", (u_int)buf.st_size + 1, fname, pcap_strerror(errno)); - cc = read(fd, cp, (u_int)buf.st_size); + cc = (int)read(fd, cp, (u_int)buf.st_size); if (cc < 0) error("read %s: %s", fname, pcap_strerror(errno)); if (cc != buf.st_size) @@ -199,7 +212,7 @@ main(int argc, char **argv) int gflag; char *infile; int Oflag; - long snaplen; + int snaplen; char *p; int dlt; int have_fcode = 0; @@ -218,7 +231,7 @@ main(int argc, char **argv) infile = NULL; Oflag = 1; - snaplen = 68; + snaplen = MAXIMUM_SNAPLEN; if ((cp = strrchr(argv[0], '/')) != NULL) program_name = cp + 1; @@ -272,13 +285,19 @@ main(int argc, char **argv) case 's': { char *end; + long long_snaplen; - snaplen = strtol(optarg, &end, 0); + long_snaplen = strtol(optarg, &end, 0); if (optarg == end || *end != '\0' - || snaplen < 0 || snaplen > 65535) + || long_snaplen < 0 + || long_snaplen > MAXIMUM_SNAPLEN) error("invalid snaplen %s", optarg); - else if (snaplen == 0) - snaplen = 65535; + else { + if (snaplen == 0) + snaplen = MAXIMUM_SNAPLEN; + else + snaplen = (int)long_snaplen; + } break; } |