From: Zeev Suraski Date: Mon, 6 Nov 2000 09:55:53 +0000 (+0000) Subject: Fixed a bug in $argv and $argc not being properly defined in command-line mode X-Git-Tag: php-4.0.4RC3~302 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=efd8117fd4342a62d22ead90b9ff8722649b03c4;p=php Fixed a bug in $argv and $argc not being properly defined in command-line mode @- Fixed a bug that prevented $argv and $argc from being defined in the command @ line version of PHP (Stas) --- diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index 01ca27fdbe..c320fa2891 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -645,6 +645,25 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine EG(interactive) = interactive; #endif + if (!cgi) { + if (!SG(request_info).query_string) { + for (i = ap_php_optind, len = 0; i < argc; i++) { + len += strlen(argv[i]) + 1; + } + + s = malloc(len + 1); /* leak - but only for command line version, so ok */ + *s = '\0'; /* we are pretending it came from the environment */ + for (i = ap_php_optind, len = 0; i < argc; i++) { + strcat(s, argv[i]); + if (i < (argc - 1)) { + strcat(s, "+"); + } + } + SG(request_info).query_string = s; + } + } + + if (!cgi_started) { if (php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC)==FAILURE) { php_module_shutdown(); @@ -664,21 +683,9 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine zend_llist_destroy(&global_vars); if (!cgi) { - if (!SG(request_info).query_string) { - for (i = ap_php_optind, len = 0; i < argc; i++) - len += strlen(argv[i]) + 1; - - s = malloc(len + 1); /* leak - but only for command line version, so ok */ - *s = '\0'; /* we are pretending it came from the environment */ - for (i = ap_php_optind, len = 0; i < argc; i++) { - strcat(s, argv[i]); - if (i < (argc - 1)) - strcat(s, "+"); - } - SG(request_info).query_string = s; - } - if (!SG(request_info).path_translated && argc > ap_php_optind) + if (!SG(request_info).path_translated && argc > ap_php_optind) { SG(request_info).path_translated = estrdup(argv[ap_php_optind]); + } } else { /* If for some reason the CGI interface is not setting the PATH_TRANSLATED correctly, SG(request_info).path_translated is NULL.