Replace 'system' call by proc_exec function from proc.c module. It allows to easy extend cpp invoking with additional options (like -D) in more secure way.
Signed-off-by: Vadim Kochan <[email protected]> --- bpfc/Makefile | 1 + cpp.c | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/bpfc/Makefile b/bpfc/Makefile index f011706..7e6fd45 100644 --- a/bpfc/Makefile +++ b/bpfc/Makefile @@ -7,6 +7,7 @@ bpfc-objs = xmalloc.o \ bpf_parser.tab.o \ die.o \ sysctl.o \ + proc.o \ cpp.o \ bpfc.o diff --git a/cpp.c b/cpp.c index 6734eac..d4ec2a6 100644 --- a/cpp.c +++ b/cpp.c @@ -2,21 +2,26 @@ #include <libgen.h> #include "str.h" +#include "proc.h" #include "xmalloc.h" int cpp_exec(char *in_file, char *out_file, size_t out_len) { char *tmp = xstrdup(in_file); - char cmd[256], *base; + char *argv[7] = { + "cpp", + "-I", ETCDIRE_STRING, + "-o", out_file, + in_file, + NULL, + }; int ret = 0; + char *base; base = basename(tmp); - slprintf(out_file, out_len, "/tmp/.tmp-%u-%s", rand(), base); - slprintf(cmd, sizeof(cmd), "cpp -I" ETCDIRE_STRING " %s > %s", - in_file, out_file); - if (system(cmd) != 0) + if (proc_exec("cpp", argv)) ret = -1; xfree(tmp); -- 2.6.3 -- You received this message because you are subscribed to the Google Groups "netsniff-ng" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
