diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2016-08-09 12:28:15 +0200 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2016-08-09 13:56:59 +0200 |
commit | 4e47fd021a6945aa626eaef4446c5b547d8c2a85 (patch) | |
tree | bd77315e8eef043cd8e53699fa7125390418f9d8 | |
parent | 48178cd649b48196e16e0481ca44dea206fe04d4 (diff) |
trafgen: parser: Check read access to file before invoking cpp
If a non-accessible (or non-existing) file is passed to trafgen and the
-p/--cpp option is used, the preprocessor will fail but trafgen will
continue running and producing follow-up errors messages:
cpp: error: foo.conf: No such file or directory
cpp: warning: ā-x cā after last input file has no effect
cpp: fatal error: no input files
compilation terminated.
0 packets to schedule
Enabled kernel qdisc bypass
0 bytes in total
Running! Hang up with ^C!
Enabled kernel qdisc bypass
TX,V2: 0.50 MiB, 256 Frames, each 2048 Byte allocated
TX,V2: 0.50 MiB, 256 Frames, each 2048 Byte allocated
0 packets outgoing
0 bytes outgoing
0 sec, 0 usec on CPU0 (0 packets)
0 sec, 0 usec on CPU1 (0 packets)
To avoid this, check that the file is readable before passing it to the
preprocessor and error out if is not readable.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
-rw-r--r-- | trafgen_parser.y | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/trafgen_parser.y b/trafgen_parser.y index 035d9c1..cd87c12 100644 --- a/trafgen_parser.y +++ b/trafgen_parser.y @@ -12,11 +12,12 @@ #include <stdio.h> #include <stdlib.h> -#include <signal.h> #include <stdint.h> -#include <errno.h> #include <stdbool.h> +#include <errno.h> #include <libgen.h> +#include <signal.h> +#include <unistd.h> #include <net/if_arp.h> #include <netinet/in.h> #include <linux/icmp.h> @@ -1037,6 +1038,11 @@ void compile_packets(char *file, bool verbose, unsigned int cpu, char tmp_file[128]; int ret = -1; + if (access(file, R_OK)) { + fprintf(stderr, "Cannot access %s: %s!\n", file, strerror(errno)); + die(); + } + memset(tmp_file, 0, sizeof(tmp_file)); our_cpu = cpu; |