From: Ryan Bloom Date: Tue, 14 Dec 1999 20:37:58 +0000 (+0000) Subject: Make CGI's work correctly in Apache 2.0. APR wants the first element in the X-Git-Tag: 1.3.10~94 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bea42aaa3685b9b88b9e6b58af2abef1dc5192ec;p=apache Make CGI's work correctly in Apache 2.0. APR wants the first element in the argument list to be the program name. This is exactly what POSIX requires, and what Windows wants, but Apache 1.3 would create the arg list, and then have another function squeeze the program name in later. This patch fixes that by having mod_cgi put the program name the correct place. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@84293 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/generators/mod_cgi.c b/modules/generators/mod_cgi.c index c0ee8aa7f6..018e700bc8 100644 --- a/modules/generators/mod_cgi.c +++ b/modules/generators/mod_cgi.c @@ -376,32 +376,35 @@ static ap_status_t build_argv_list(char ***argv, request_rec *r, ap_context_t *p const char *args = r->args; if (!args || !args[0] || strchr(args, '=')) { - *argv = NULL; + numwords = 1; } else { /* count the number of keywords */ - for (x = 0, numwords = 1; args[x]; x++) { + for (x = 0, numwords = 2; args[x]; x++) { if (args[x] == '+') { ++numwords; } } - if (numwords > APACHE_ARG_MAX) { - numwords = APACHE_ARG_MAX; /* Truncate args to prevent overrun */ - } - *argv = (char **) ap_palloc(p, (numwords + 1) * sizeof(char *)); - - for (x = 1, idx = 0; x <= numwords; x++) { - w = ap_getword_nulls(p, &args, '+'); - ap_unescape_url(w); - (*argv)[idx++] = ap_escape_shell_cmd(p, w); - } - (*argv)[idx] = NULL; } + /* Everything is - 1 to account for the first parameter which is the + * program name. We didn't used to have to do this, but APR wants it. + */ + if (numwords > APACHE_ARG_MAX - 1) { + numwords = APACHE_ARG_MAX - 1; /* Truncate args to prevent overrun */ + } + *argv = (char **) ap_palloc(p, (numwords + 2) * sizeof(char *)); + + for (x = 1, idx = 1; x < numwords; x++) { + w = ap_getword_nulls(p, &args, '+'); + ap_unescape_url(w); + (*argv)[idx++] = ap_escape_shell_cmd(p, w); + } + (*argv)[idx] = NULL; return APR_SUCCESS; } -static ap_status_t build_command_line(char **c, request_rec *r, ap_context_t *p) +static ap_status_t build_command_line(char **c, request_rec *r, ap_context_t *p) { #ifdef WIN32 char *quoted_filename = NULL; @@ -522,8 +525,9 @@ static int cgi_handler(request_rec *r) "couldn't spawn child process: %s", r->filename); return HTTP_INTERNAL_SERVER_ERROR; } + argv[0] = ap_pstrdup(p, command); /* run the script in its own process */ - else if (run_cgi_child(&script_out, &script_in, &script_err, command, argv, r, p) != APR_SUCCESS) { + if (run_cgi_child(&script_out, &script_in, &script_err, command, argv, r, p) != APR_SUCCESS) { ap_log_rerror(APLOG_MARK, APLOG_ERR, errno, r, "couldn't spawn child process: %s", r->filename); return HTTP_INTERNAL_SERVER_ERROR;