]> granicus.if.org Git - php/commitdiff
Fixed weired behavior in CGI parameter parsing
authorDmitry Stogov <dmitry@php.net>
Mon, 3 Dec 2007 15:08:01 +0000 (15:08 +0000)
committerDmitry Stogov <dmitry@php.net>
Mon, 3 Dec 2007 15:08:01 +0000 (15:08 +0000)
NEWS
sapi/cgi/cgi_main.c

diff --git a/NEWS b/NEWS
index a6ada1d8240981cf21324461d0476d1b7d9a5ba2..ec9aee415e3bcaf9317a91919c2b0ca0aa6ce558 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,8 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2008, PHP 5.2.6
+- Fixed weired behavior in CGI parameter parsing. (Dmitry, Hannes Magnusson)
+
 - Fixed bug #43482 (array_pad() does not warn on very small pad numbers).
   (Ilia)
 - Fixed bug #43457 (Prepared statement with incorrect parms doens't
index cba37fe19a5ebaea979b0b42caa293135872e036..48e62a93c84dfe9e65661588a8b40c737adaa21e 100644 (file)
@@ -1661,12 +1661,12 @@ consult the installation file that came with this distribution, or visit \n\
                                                }
                                                script_file = estrdup(php_optarg);
                                                no_headers = 1;
-                                               /* arguments after the file are considered script args */
-                                               SG(request_info).argc = argc - (php_optind - 1);
-                                               SG(request_info).argv = &argv[php_optind - 1];
                                                break;
 
                                case 'i': /* php info & quit */
+                                               if (script_file) {
+                                                       efree(script_file);
+                                               }
                                                if (php_request_startup(TSRMLS_C) == FAILURE) {
                                                        SG(server_context) = NULL;
                                                        php_module_shutdown(TSRMLS_C);
@@ -1687,6 +1687,9 @@ consult the installation file that came with this distribution, or visit \n\
                                                break;
 
                                case 'm': /* list compiled in modules */
+                                       if (script_file) {
+                                               efree(script_file);
+                                       }
                                        php_output_startup();
                                        php_output_activate(TSRMLS_C);
                                        SG(headers_sent) = 1;
@@ -1710,6 +1713,9 @@ consult the installation file that came with this distribution, or visit \n\
                                                break;
 
                                case 'v': /* show php version & quit */
+                                               if (script_file) {
+                                                       efree(script_file);
+                                               }
                                                no_headers = 1;
                                                if (php_request_startup(TSRMLS_C) == FAILURE) {
                                                        SG(server_context) = NULL;
@@ -1746,6 +1752,18 @@ consult the installation file that came with this distribution, or visit \n\
                                /* override path_translated if -f on command line */
                                STR_FREE(SG(request_info).path_translated);
                                SG(request_info).path_translated = script_file;
+                               /* before registering argv to module exchange the *new* argv[0] */
+                               /* we can achieve this without allocating more memory */
+                               SG(request_info).argc = argc - (php_optind - 1);
+                               SG(request_info).argv = &argv[php_optind - 1];
+                               SG(request_info).argv[0] = script_file;
+                       } else if (argc > php_optind) {
+                               /* file is on command line, but not in -f opt */
+                               STR_FREE(SG(request_info).path_translated);
+                               SG(request_info).path_translated = estrdup(argv[php_optind++]);
+                               /* arguments after the file are considered script args */
+                               SG(request_info).argc = argc - php_optind;
+                               SG(request_info).argv = &argv[php_optind];
                        }
 
                        if (no_headers) {
@@ -1753,14 +1771,6 @@ consult the installation file that came with this distribution, or visit \n\
                                SG(request_info).no_headers = 1;
                        }
 
-                       if (!SG(request_info).path_translated && argc > php_optind) {
-                               /* arguments after the file are considered script args */
-                               SG(request_info).argc = argc - php_optind;
-                               SG(request_info).argv = &argv[php_optind];
-                               /* file is on command line, but not in -f opt */
-                               SG(request_info).path_translated = estrdup(argv[php_optind++]);
-                       }
-
                        /* all remaining arguments are part of the query string
                           this section of code concatenates all remaining arguments
                           into a single string, seperating args with a &