From: Christian Kastner Date: Tue, 22 Dec 2015 18:56:31 +0100 Subject: Limit number of command arguments Set an upper limit for the number of arguments in a command, instead of hardcoding 100 (and not checking for that limit). Fix provided by Steve Greenland . Forwarded: no Last-Update: 2015-12-22 --- popen.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/popen.c b/popen.c index ba59b97..d0c2621 100644 --- a/popen.c +++ b/popen.c @@ -32,6 +32,7 @@ static char sccsid[] = "@(#)popen.c 5.7 (Berkeley) 2/14/89"; #include +#define MAX_ARGS 100 #define WANT_GLOBBING 0 /* @@ -50,7 +51,7 @@ cron_popen(program, type) FILE *iop; int argc, pdes[2]; PID_T pid; - char *argv[100]; + char *argv[MAX_ARGS + 1]; #if WANT_GLOBBING char **pop, *vv[2]; int gargc; @@ -72,9 +73,10 @@ cron_popen(program, type) return(NULL); /* break up string into pieces */ - for (argc = 0, cp = program;; cp = NULL) + for (argc = 0, cp = program; argc < MAX_ARGS; cp = NULL) if (!(argv[argc++] = strtok(cp, " \t\n"))) break; + argv[MAX_ARGS] = NULL; #if WANT_GLOBBING /* glob each piece */