From 4e47fd021a6945aa626eaef4446c5b547d8c2a85 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 9 Aug 2016 12:28:15 +0200 Subject: trafgen: parser: Check read access to file before invoking cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- trafgen_parser.y | 10 ++++++++-- 1 file 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 #include -#include #include -#include #include +#include #include +#include +#include #include #include #include @@ -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; -- cgit v1.2.3-54-g00ecf