diff --git a/examples/patbench.cc b/examples/patbench.cc index 20de5745..7362095a 100644 --- a/examples/patbench.cc +++ b/examples/patbench.cc @@ -123,6 +123,7 @@ #include #include +#include #include // We use the BSD primitives throughout as they exist on both BSD and Linux. @@ -657,6 +658,10 @@ int main(int argc, char **argv) { break; case 'n': repeatCount = atoi(optarg); + if (repeatCount <= 0 || repeatCount > UINT_MAX) { + cerr << "Invalid repeatCount." << endl; + exit(-1); + } break; default: usage(argv[0]); diff --git a/examples/pcapscan.cc b/examples/pcapscan.cc index 12b94438..913fe607 100644 --- a/examples/pcapscan.cc +++ b/examples/pcapscan.cc @@ -58,6 +58,7 @@ #include #include +#include #include // We use the BSD primitives throughout as they exist on both BSD and Linux. @@ -489,6 +490,10 @@ int main(int argc, char **argv) { // Streaming mode scans. double secsStreamingScan = 0.0, secsStreamingOpenClose = 0.0; + if (repeatCount <= 0 || repeatCount > UINT_MAX) { + cerr << "Invalid repeatCount." << endl; + exit(-1); + } for (unsigned int i = 0; i < repeatCount; i++) { // Open streams. clock.start(); diff --git a/examples/simplegrep.c b/examples/simplegrep.c index d6bd4b39..b2c64f31 100644 --- a/examples/simplegrep.c +++ b/examples/simplegrep.c @@ -57,6 +57,7 @@ #include #include #include +#include #include @@ -152,6 +153,15 @@ int main(int argc, char *argv[]) { char *pattern = argv[1]; char *inputFN = argv[2]; + if (access(inputFN, F_OK) != 0) { + fprintf(stderr, "ERROR: file doesn't exist.\n"); + return -1; + } + if (access(inputFN, R_OK) != 0) { + fprintf(stderr, "ERROR: can't be read.\n"); + return -1; + } + /* First, we attempt to compile the pattern provided on the command line. * We assume 'DOTALL' semantics, meaning that the '.' meta-character will * match newline characters. The compiler will analyse the given pattern and