[PHP-CVS] cvs: php4(PHP_4_3) /sapi/cgi cgi_main.c getopt.c php_getopt.h /sapi/cli getopt.c php_cli.c php_getopt.h
helly Fri May 30 22:20:08 2003 EDT Modified files: (Branch: PHP_4_3) /php4/sapi/cli getopt.c php_cli.c php_getopt.h /php4/sapi/cgi cgi_main.c getopt.c php_getopt.h Log: Reapply long opts Index: php4/sapi/cli/getopt.c diff -u php4/sapi/cli/getopt.c:1.3.4.2 php4/sapi/cli/getopt.c:1.3.4.3 --- php4/sapi/cli/getopt.c:1.3.4.2 Fri May 30 21:37:45 2003 +++ php4/sapi/cli/getopt.c Fri May 30 22:20:08 2003 @@ -1,4 +1,22 @@ -/* Borrowed from Apache NT Port */ +/* + +--+ + | PHP Version 4| + +--+ + | Copyright (c) 1997-2003 The PHP Group| + +--+ + | This source file is subject to version 2.02 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is| + | available at through the world-wide-web at | + | http://www.php.net/license/2_02.txt. | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | [EMAIL PROTECTED] so we can mail you a copy immediately. | + +--+ + | Author: Marcus Boerger [EMAIL PROTECTED] | + +--+ +*/ + +/* $Id: getopt.c,v 1.3.4.3 2003/05/31 02:20:08 helly Exp $ */ #include stdio.h #include string.h @@ -10,164 +28,129 @@ #define OPTERRARG (3) -char *ap_php_optarg; -int ap_php_optind = 1; -static int ap_php_opterr = 1; - -static int -ap_php_optiserr(int argc, char * const *argv, int oint, const char *optstr, - int optchr, int err) +static int php_opt_error(int argc, char * const *argv, int oint, int optchr, int err, int show_err) { -if (ap_php_opterr) -{ -fprintf(stderr, Error in argument %d, char %d: , oint, optchr+1); -switch(err) -{ -case OPTERRCOLON: -fprintf(stderr, : in flags\n); -break; -case OPTERRNF: -fprintf(stderr, option not found %c\n, argv[oint][optchr]); -break; -case OPTERRARG: -fprintf(stderr, no argument for option %c\n, argv[oint][optchr]); -break; -default: -fprintf(stderr, unknown\n); -break; -} -} -return('?'); + if (show_err) + { + fprintf(stderr, Error in argument %d, char %d: , oint, optchr+1); + switch(err) + { + case OPTERRCOLON: + fprintf(stderr, : in flags\n); + break; + case OPTERRNF: + fprintf(stderr, option not found %c\n, argv[oint][optchr]); + break; + case OPTERRARG: + fprintf(stderr, no argument for option %c\n, argv[oint][optchr]); + break; + default: + fprintf(stderr, unknown\n); + break; + } + } + return('?'); } - -int ap_php_getopt(int argc, char* const *argv, const char *optstr) -{ -static int optchr = 0; -static int dash = 0; /* have already seen the - */ - -char *cp; -if (ap_php_optind = argc) -return(EOF); -if (!dash (argv[ap_php_optind][0] != '-')) -return(EOF); -if (!dash (argv[ap_php_optind][0] == '-') !argv[ap_php_optind][1]) -{ -/* - * use to specify stdin. Need to let pgm process this and - * the following args - */ -return(EOF); -} -if ((argv[ap_php_optind][0] == '-') (argv[ap_php_optind][1] == '-')) -{ -/* -- indicates end of args */ -ap_php_optind++; -return(EOF); -} -if (!dash) -{ -assert((argv[ap_php_optind][0] == '-') argv[ap_php_optind][1]); -dash = 1; -optchr = 1; -} - -/* Check if the guy tries to do a -: kind of flag */ -assert(dash); -if (argv[ap_php_optind][optchr] == ':') -{ -dash = 0; -ap_php_optind++; -return(ap_php_optiserr(argc, argv, ap_php_optind-1, optstr, optchr, OPTERRCOLON)); -} -if (!(cp = strchr(optstr, argv[ap_php_optind][optchr]))) -{ -int errind = ap_php_optind; -int errchr = optchr; - -if (!argv[ap_php_optind][optchr+1]) -{ -dash = 0; -ap_php_optind++; -} -else -optchr++; -return(ap_php_optiserr(argc, argv, errind, optstr, errchr, OPTERRNF)); -} -if (cp[1] ==
[PHP-CVS] cvs: php4(PHP_4_3) /sapi/cgi cgi_main.c
moriyoshi Sat Mar 29 11:14:41 2003 EDT Modified files: (Branch: PHP_4_3) /php4/sapi/cgi cgi_main.c Log: MFH(r-1.223): CS WS fixes Index: php4/sapi/cgi/cgi_main.c diff -u php4/sapi/cgi/cgi_main.c:1.190.2.21 php4/sapi/cgi/cgi_main.c:1.190.2.22 --- php4/sapi/cgi/cgi_main.c:1.190.2.21 Fri Mar 28 13:25:01 2003 +++ php4/sapi/cgi/cgi_main.cSat Mar 29 11:14:41 2003 @@ -20,7 +20,7 @@ +--+ */ -/* $Id: cgi_main.c,v 1.190.2.21 2003/03/28 18:25:01 moriyoshi Exp $ */ +/* $Id: cgi_main.c,v 1.190.2.22 2003/03/29 16:14:41 moriyoshi Exp $ */ #include php.h #include php_globals.h @@ -228,8 +228,7 @@ uint remaining = str_length; size_t ret; - while (remaining 0) - { + while (remaining 0) { ret = sapi_cgibin_single_write(ptr, remaining TSRMLS_CC); if (!ret) { php_handle_aborted_connection(); @@ -251,7 +250,8 @@ if(!request || FCGX_FFlush( request-out ) == -1 ) { php_handle_aborted_connection(); } - } else + return; + } #endif if (fflush(stdout)==EOF) { php_handle_aborted_connection(); @@ -333,9 +333,10 @@ FCGX_Request *request = (FCGX_Request *)SG(server_context); tmp_read_bytes = FCGX_GetStr( pos, count_bytes-read_bytes, request-in ); pos += tmp_read_bytes; - } else + } else { #endif tmp_read_bytes = read(0, buffer+read_bytes, count_bytes-read_bytes); + } if (tmp_read_bytes=0) { break; @@ -366,7 +367,9 @@ { int len=0; char *buf = NULL; - if (!name) return NULL; + if (!name) { + return NULL; + } len = strlen(name) + (value?strlen(value):0) + sizeof(=) + 2; buf = (char *)malloc(len); if (buf == NULL) { @@ -458,7 +461,7 @@ static int php_cgi_startup(sapi_module_struct *sapi_module) { - if (php_module_startup(sapi_module, NULL, 0)==FAILURE) { + if (php_module_startup(sapi_module, NULL, 0) == FAILURE) { return FAILURE; } return SUCCESS; @@ -618,8 +621,9 @@ /* some broken servers do not have script_filename or argv0 an example, IIS configured in some ways. then they do more broken stuff and set path_translated to the cgi script location */ - if (!script_path_translated env_path_translated) - script_path_translated = env_path_translated; + if (!script_path_translated env_path_translated) { + script_path_translated = env_path_translated; + } #endif /* initialize the defaults */ @@ -649,22 +653,25 @@ if (fix_pathinfo) { /* save the originals first for anything we change later */ - if (env_path_translated) + if (env_path_translated) { _sapi_cgibin_putenv(ORIG_PATH_TRANSLATED,env_path_translated TSRMLS_CC); - if (env_path_info) + } + if (env_path_info) { _sapi_cgibin_putenv(ORIG_PATH_INFO,env_path_info TSRMLS_CC); - if (env_script_name) + } + if (env_script_name) { _sapi_cgibin_putenv(ORIG_SCRIPT_NAME,env_script_name TSRMLS_CC); - if (env_script_filename) + } + if (env_script_filename) { _sapi_cgibin_putenv(ORIG_SCRIPT_FILENAME,env_script_filename TSRMLS_CC); - + } if (!env_document_root) { /* IIS version of DOCUMENT_ROOT, not avail in cgi, but is in fastcgi */ env_document_root = sapi_cgibin_getenv(APPL_PHYSICAL_PATH,0 TSRMLS_CC); /* ini version of document root */ - if (!env_document_root) + if (!env_document_root) { env_document_root = PG(doc_root); - + } /* set the document root, this makes a more consistent env for php scripts */ if (env_document_root) { @@ -735,7 +742,9 @@ int l = strlen(env_document_root); int path_translated_len = 0; char *path_translated = NULL; -
[PHP-CVS] cvs: php4(PHP_4_3) /sapi/cgi cgi_main.c
moriyoshi Sat Mar 29 11:18:12 2003 EDT Modified files: (Branch: PHP_4_3) /php4/sapi/cgi cgi_main.c Log: MFH Index: php4/sapi/cgi/cgi_main.c diff -u php4/sapi/cgi/cgi_main.c:1.190.2.22 php4/sapi/cgi/cgi_main.c:1.190.2.23 --- php4/sapi/cgi/cgi_main.c:1.190.2.22 Sat Mar 29 11:14:41 2003 +++ php4/sapi/cgi/cgi_main.cSat Mar 29 11:18:11 2003 @@ -20,7 +20,7 @@ +--+ */ -/* $Id: cgi_main.c,v 1.190.2.22 2003/03/29 16:14:41 moriyoshi Exp $ */ +/* $Id: cgi_main.c,v 1.190.2.23 2003/03/29 16:18:11 moriyoshi Exp $ */ #include php.h #include php_globals.h @@ -334,9 +334,11 @@ tmp_read_bytes = FCGX_GetStr( pos, count_bytes-read_bytes, request-in ); pos += tmp_read_bytes; } else { -#endif tmp_read_bytes = read(0, buffer+read_bytes, count_bytes-read_bytes); } +#else + tmp_read_bytes = read(0, buffer+read_bytes, count_bytes-read_bytes); +#endif if (tmp_read_bytes=0) { break; -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4(PHP_4_3) /sapi/cgi cgi_main.c
moriyoshi Fri Mar 28 12:55:08 2003 EDT Modified files: (Branch: PHP_4_3) /php4/sapi/cgi cgi_main.c Log: MFH(r-1.221): fixed bug #22773 Index: php4/sapi/cgi/cgi_main.c diff -u php4/sapi/cgi/cgi_main.c:1.190.2.19 php4/sapi/cgi/cgi_main.c:1.190.2.20 --- php4/sapi/cgi/cgi_main.c:1.190.2.19 Thu Mar 27 12:57:58 2003 +++ php4/sapi/cgi/cgi_main.cFri Mar 28 12:55:08 2003 @@ -20,7 +20,7 @@ +--+ */ -/* $Id: cgi_main.c,v 1.190.2.19 2003/03/27 17:57:58 shane Exp $ */ +/* $Id: cgi_main.c,v 1.190.2.20 2003/03/28 17:55:08 moriyoshi Exp $ */ #include php.h #include php_globals.h @@ -787,8 +787,8 @@ } else { /* make sure path_info/translated are empty */ script_path_translated = _sapi_cgibin_putenv(SCRIPT_FILENAME,script_path_translated TSRMLS_CC); - _sapi_cgibin_putenv(PATH_INFO,NULL TSRMLS_CC); - _sapi_cgibin_putenv(PATH_TRANSLATED,NULL TSRMLS_CC); + _sapi_cgibin_putenv(PATH_INFO, TSRMLS_CC); + _sapi_cgibin_putenv(PATH_TRANSLATED, TSRMLS_CC); } SG(request_info).request_uri = sapi_cgibin_getenv(SCRIPT_NAME,0 TSRMLS_CC); } else { -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4(PHP_4_3) /sapi/cgi cgi_main.c
moriyoshi Fri Mar 28 13:25:01 2003 EDT Modified files: (Branch: PHP_4_3) /php4/sapi/cgi cgi_main.c Log: MFH(r-1.222): do the right fix.. Index: php4/sapi/cgi/cgi_main.c diff -u php4/sapi/cgi/cgi_main.c:1.190.2.20 php4/sapi/cgi/cgi_main.c:1.190.2.21 --- php4/sapi/cgi/cgi_main.c:1.190.2.20 Fri Mar 28 12:55:08 2003 +++ php4/sapi/cgi/cgi_main.cFri Mar 28 13:25:01 2003 @@ -20,7 +20,7 @@ +--+ */ -/* $Id: cgi_main.c,v 1.190.2.20 2003/03/28 17:55:08 moriyoshi Exp $ */ +/* $Id: cgi_main.c,v 1.190.2.21 2003/03/28 18:25:01 moriyoshi Exp $ */ #include php.h #include php_globals.h @@ -368,7 +368,10 @@ char *buf = NULL; if (!name) return NULL; len = strlen(name) + (value?strlen(value):0) + sizeof(=) + 2; - buf = (char *)emalloc(len); + buf = (char *)malloc(len); + if (buf == NULL) { + return getenv(name); + } if (value) { snprintf(buf,len-1,%s=%s, name, value); } else { @@ -382,7 +385,7 @@ if (!FCGX_IsCGI()) { FCGX_Request *request = (FCGX_Request *)SG(server_context); FCGX_PutEnv(request,buf); - efree(buf); + free(buf); return sapi_cgibin_getenv(name,0 TSRMLS_CC); } #endif @@ -391,11 +394,7 @@ this leaks, but it's only cgi anyway, we'll fix it for 5.0 */ - if (value) - putenv(strdup(buf)); - else - putenv(buf); - efree(buf); + putenv(buf); return getenv(name); } @@ -787,8 +786,8 @@ } else { /* make sure path_info/translated are empty */ script_path_translated = _sapi_cgibin_putenv(SCRIPT_FILENAME,script_path_translated TSRMLS_CC); - _sapi_cgibin_putenv(PATH_INFO, TSRMLS_CC); - _sapi_cgibin_putenv(PATH_TRANSLATED, TSRMLS_CC); + _sapi_cgibin_putenv(PATH_INFO, NULL TSRMLS_CC); + _sapi_cgibin_putenv(PATH_TRANSLATED, NULL TSRMLS_CC); } SG(request_info).request_uri = sapi_cgibin_getenv(SCRIPT_NAME,0 TSRMLS_CC); } else { -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4(PHP_4_3) /sapi/cgi cgi_main.c /sapi/isapi php4isapi.c
shane Thu Mar 27 12:57:58 2003 EDT Modified files: (Branch: PHP_4_3) /php4/sapi/cgi cgi_main.c /php4/sapi/isapiphp4isapi.c Log: MFH Index: php4/sapi/cgi/cgi_main.c diff -u php4/sapi/cgi/cgi_main.c:1.190.2.18 php4/sapi/cgi/cgi_main.c:1.190.2.19 --- php4/sapi/cgi/cgi_main.c:1.190.2.18 Sun Mar 9 21:35:59 2003 +++ php4/sapi/cgi/cgi_main.cThu Mar 27 12:57:58 2003 @@ -20,7 +20,7 @@ +--+ */ -/* $Id: cgi_main.c,v 1.190.2.18 2003/03/10 02:35:59 shane Exp $ */ +/* $Id: cgi_main.c,v 1.190.2.19 2003/03/27 17:57:58 shane Exp $ */ #include php.h #include php_globals.h @@ -806,7 +806,9 @@ #endif SG(request_info).request_method = sapi_cgibin_getenv(REQUEST_METHOD,0 TSRMLS_CC); SG(request_info).query_string = sapi_cgibin_getenv(QUERY_STRING,0 TSRMLS_CC); - if (script_path_translated) + /* some server configurations allow '..' to slip through in the + translated path. We'll just refuse to handle such a path. */ + if (script_path_translated !strstr(script_path_translated,..)) SG(request_info).path_translated = estrdup(script_path_translated); SG(request_info).content_type = (content_type ? content_type : ); SG(request_info).content_length = (content_length?atoi(content_length):0); Index: php4/sapi/isapi/php4isapi.c diff -u php4/sapi/isapi/php4isapi.c:1.92.2.3 php4/sapi/isapi/php4isapi.c:1.92.2.4 --- php4/sapi/isapi/php4isapi.c:1.92.2.3Mon Mar 24 06:21:26 2003 +++ php4/sapi/isapi/php4isapi.c Thu Mar 27 12:57:58 2003 @@ -744,16 +744,22 @@ * variable won't be present, so fall back to old behaviour. */ efree( file_handle.filename ); - file_handle.filename = SG(request_info.path_translated); + file_handle.filename = SG(request_info).path_translated; file_handle.free_filename = 0; } } #else - file_handle.filename = SG(request_info.path_translated); + file_handle.filename = SG(request_info).path_translated; file_handle.free_filename = 0; #endif file_handle.type = ZEND_HANDLE_FILENAME; file_handle.opened_path = NULL; + /* some server configurations allow '..' to slip through in the + translated path. We'll just refuse to handle such a path. */ + if (strstr(SG(request_info).path_translated,..)) { + SG(sapi_headers).http_response_code = 404; + SG(request_info).path_translated = NULL; + } php_request_startup(TSRMLS_C); php_execute_script(file_handle TSRMLS_CC); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4(PHP_4_3) /sapi/cgi cgi_main.c
sniper Sun Mar 9 21:17:06 2003 EDT Modified files: (Branch: PHP_4_3) /php4/sapi/cgi cgi_main.c Log: MFH Index: php4/sapi/cgi/cgi_main.c diff -u php4/sapi/cgi/cgi_main.c:1.190.2.16 php4/sapi/cgi/cgi_main.c:1.190.2.17 --- php4/sapi/cgi/cgi_main.c:1.190.2.16 Sat Feb 15 08:26:05 2003 +++ php4/sapi/cgi/cgi_main.cSun Mar 9 21:17:06 2003 @@ -20,7 +20,7 @@ +--+ */ -/* $Id: cgi_main.c,v 1.190.2.16 2003/02/15 13:26:05 edink Exp $ */ +/* $Id: cgi_main.c,v 1.190.2.17 2003/03/10 02:17:06 sniper Exp $ */ #include php.h #include php_globals.h @@ -233,6 +233,7 @@ ret = sapi_cgibin_single_write(ptr, remaining TSRMLS_CC); if (!ret) { php_handle_aborted_connection(); + return str_length - remaining; } ptr += ret; remaining -= ret; -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4(PHP_4_3) /sapi/cgi cgi_main.c
edink Sat Feb 15 08:26:05 2003 EDT Modified files: (Branch: PHP_4_3) /php4/sapi/cgi cgi_main.c Log: Option -b needs an argument. This fixes #9. # Note -b still seems to be broken: # sapi/cgi/php -b # Status: 404 # Content-type: text/html # X-Powered-By: PHP/4.3.1-dev # # No input file specified. Index: php4/sapi/cgi/cgi_main.c diff -u php4/sapi/cgi/cgi_main.c:1.190.2.15 php4/sapi/cgi/cgi_main.c:1.190.2.16 --- php4/sapi/cgi/cgi_main.c:1.190.2.15 Fri Feb 14 09:38:01 2003 +++ php4/sapi/cgi/cgi_main.cSat Feb 15 08:26:05 2003 @@ -20,7 +20,7 @@ +--+ */ -/* $Id: cgi_main.c,v 1.190.2.15 2003/02/14 14:38:01 sniper Exp $ */ +/* $Id: cgi_main.c,v 1.190.2.16 2003/02/15 13:26:05 edink Exp $ */ #include php.h #include php_globals.h @@ -138,7 +138,7 @@ #define TRANSLATE_SLASHES(path) #endif -#define OPTSTRING abCc:d:ef:g:hilmnqsw?vz: +#define OPTSTRING ab:Cc:d:ef:g:hilmnqsw?vz: static int print_module_info(zend_module_entry *module, void *arg TSRMLS_DC) { -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4(PHP_4_3) /sapi/cgi cgi_main.c
sniper Fri Feb 14 09:38:02 2003 EDT Modified files: (Branch: PHP_4_3) /php4/sapi/cgi cgi_main.c Log: Added missing $Id$ tag Index: php4/sapi/cgi/cgi_main.c diff -u php4/sapi/cgi/cgi_main.c:1.190.2.14 php4/sapi/cgi/cgi_main.c:1.190.2.15 --- php4/sapi/cgi/cgi_main.c:1.190.2.14 Thu Feb 13 15:58:41 2003 +++ php4/sapi/cgi/cgi_main.cFri Feb 14 09:38:01 2003 @@ -20,6 +20,7 @@ +--+ */ +/* $Id: cgi_main.c,v 1.190.2.15 2003/02/14 14:38:01 sniper Exp $ */ #include php.h #include php_globals.h -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4(PHP_4_3) /sapi/cgi cgi_main.c
shane Thu Feb 13 13:21:23 2003 EDT Modified files: (Branch: PHP_4_3) /php4/sapi/cgi cgi_main.c Log: MFH Index: php4/sapi/cgi/cgi_main.c diff -u php4/sapi/cgi/cgi_main.c:1.190.2.12 php4/sapi/cgi/cgi_main.c:1.190.2.13 --- php4/sapi/cgi/cgi_main.c:1.190.2.12 Sat Jan 25 17:02:45 2003 +++ php4/sapi/cgi/cgi_main.cThu Feb 13 13:21:23 2003 @@ -613,11 +613,13 @@ char *env_path_translated = sapi_cgibin_getenv(PATH_TRANSLATED,0 TSRMLS_CC); char *script_path_translated = env_script_filename; +#if !DISCARD_PATH /* some broken servers do not have script_filename or argv0 an example, IIS configured in some ways. then they do more broken stuff and set path_translated to the cgi script location */ if (!script_path_translated env_path_translated) script_path_translated = env_path_translated; +#endif /* initialize the defaults */ SG(request_info).path_translated = NULL; @@ -636,10 +638,10 @@ const char *auth; char *content_length = sapi_cgibin_getenv(CONTENT_LENGTH,0 TSRMLS_CC); char *content_type = sapi_cgibin_getenv(CONTENT_TYPE,0 TSRMLS_CC); -#if ENABLE_PATHINFO_CHECK - struct stat st; char *env_path_info = sapi_cgibin_getenv(PATH_INFO,0 TSRMLS_CC); char *env_script_name = sapi_cgibin_getenv(SCRIPT_NAME,0 TSRMLS_CC); +#if ENABLE_PATHINFO_CHECK + struct stat st; char *env_redirect_url = sapi_cgibin_getenv(REDIRECT_URL,0 TSRMLS_CC); char *env_document_root = sapi_cgibin_getenv(DOCUMENT_ROOT,0 TSRMLS_CC); @@ -786,12 +788,22 @@ _sapi_cgibin_putenv(PATH_INFO,NULL TSRMLS_CC); _sapi_cgibin_putenv(PATH_TRANSLATED,NULL TSRMLS_CC); } + SG(request_info).request_uri = +sapi_cgibin_getenv(SCRIPT_NAME,0 TSRMLS_CC); + } else { +#endif + /* pre 4.3 behaviour, shouldn't be used but provides BC */ + if (env_path_info) + SG(request_info).request_uri = env_path_info; + else + SG(request_info).request_uri = env_script_name; +#if !DISCARD_PATH + script_path_translated = env_path_translated; +#endif +#if ENABLE_PATHINFO_CHECK } #endif - SG(request_info).request_method = sapi_cgibin_getenv(REQUEST_METHOD,0 TSRMLS_CC); SG(request_info).query_string = sapi_cgibin_getenv(QUERY_STRING,0 TSRMLS_CC); - SG(request_info).request_uri = sapi_cgibin_getenv(SCRIPT_NAME,0 TSRMLS_CC); if (script_path_translated) SG(request_info).path_translated = estrdup(script_path_translated); SG(request_info).content_type = (content_type ? content_type : ); @@ -872,7 +884,6 @@ int no_headers=0; int orig_optind=ap_php_optind; char *orig_optarg=ap_php_optarg; - char *argv0=NULL; char *script_file=NULL; zend_llist global_vars; int interactive=0; @@ -938,11 +949,6 @@ || getenv(GATEWAY_INTERFACE) || getenv(REQUEST_METHOD)) { cgi = 1; - if (argc 1) { - argv0 = strdup(argv[1]); - } else { - argv0 = NULL; - } } #if PHP_FASTCGI } @@ -1211,8 +1217,6 @@ init_request_info(TSRMLS_C); - SG(request_info).argv0 = argv0; - zend_llist_init(global_vars, sizeof(char *), NULL, 0); CG(interactive) = 0; @@ -1390,21 +1394,27 @@ /* file is on command line, but not in -f opt */ SG(request_info).path_translated = estrdup(argv[ap_php_optind]); } - } + } /* end !cgi !fastcgi */ + /* + we never take stdin if we're (f)cgi, always + rely on the web server giving us the info + we need in the environment. + */ + if (cgi #if PHP_FASTCGI - if (fastcgi) { + || fastcgi) +#endif + { file_handle.type = ZEND_HANDLE_FILENAME; file_handle.filename = SG(request_info).path_translated; file_handle.handle.fp = NULL; } else { -#endif file_handle.filename = -; file_handle.type = ZEND_HANDLE_FP; file_handle.handle.fp = stdin; -#if PHP_FASTCGI } -#endif + file_handle.opened_path = NULL;
[PHP-CVS] cvs: php4(PHP_4_3) /sapi/cgi cgi_main.c
shane Sat Jan 25 17:02:46 2003 EDT Modified files: (Branch: PHP_4_3) /php4/sapi/cgi cgi_main.c Log: MFH fix bug 21261 putenv on some platforms requires we provide the memory cleanup env parsing logic fix bug 21367 missed optargs in a previous patch Index: php4/sapi/cgi/cgi_main.c diff -u php4/sapi/cgi/cgi_main.c:1.190.2.11 php4/sapi/cgi/cgi_main.c:1.190.2.12 --- php4/sapi/cgi/cgi_main.c:1.190.2.11 Tue Jan 7 19:44:58 2003 +++ php4/sapi/cgi/cgi_main.cSat Jan 25 17:02:45 2003 @@ -137,7 +137,7 @@ #define TRANSLATE_SLASHES(path) #endif -#define OPTSTRING aCc:d:ef:g:hilmnqsw?vz: +#define OPTSTRING abCc:d:ef:g:hilmnqsw?vz: static int print_module_info(zend_module_entry *module, void *arg TSRMLS_DC) { @@ -360,11 +360,11 @@ return getenv(name); } -static int _sapi_cgibin_putenv(char *name, char *value TSRMLS_DC) +static char *_sapi_cgibin_putenv(char *name, char *value TSRMLS_DC) { int len=0; char *buf = NULL; - if (!name) return -1; + if (!name) return NULL; len = strlen(name) + (value?strlen(value):0) + sizeof(=) + 2; buf = (char *)emalloc(len); if (value) { @@ -372,7 +372,6 @@ } else { snprintf(buf,len-1,%s=, name); } - #if PHP_FASTCGI /* when php is started by mod_fastcgi, no regular environment is provided to PHP. It is always sent to PHP at the start @@ -382,16 +381,23 @@ FCGX_Request *request = (FCGX_Request *)SG(server_context); FCGX_PutEnv(request,buf); efree(buf); - return 0; + return sapi_cgibin_getenv(name,0 TSRMLS_CC); } #endif /* if cgi, or fastcgi and not found in fcgi env - check the regular environment */ - putenv(buf); + check the regular environment + this leaks, but it's only cgi anyway, we'll fix + it for 5.0 + */ + if (value) + putenv(strdup(buf)); + else + putenv(buf); efree(buf); - return 0; + return getenv(name); } + static char *sapi_cgi_read_cookies(TSRMLS_D) { return sapi_cgibin_getenv((char *)HTTP_COOKIE,0 TSRMLS_CC); @@ -534,95 +540,161 @@ } /* }}} */ + /* {{{ init_request_info + + initializes request_info structure + + specificly in this section we handle proper translations + for: + + PATH_INFO + derived from the portion of the URI path following + the script name but preceding any query data + may be empty + + PATH_TRANSLATED +derived by taking any path-info component of the + request URI and performing any virtual-to-physical + translation appropriate to map it onto the server's + document repository structure + + empty if PATH_INFO is empty + + The env var PATH_TRANSLATED **IS DIFFERENT** than the + request_info.path_translated variable, the latter should + match SCRIPT_FILENAME instead. + + SCRIPT_NAME +set to a URL path that could identify the CGI script + rather than the interpreter. PHP_SELF is set to this. + + REQUEST_URI +uri section following the domain:port part of a URI + + SCRIPT_FILENAME +The virtual-to-physical translation of SCRIPT_NAME (as per + PATH_TRANSLATED) + + These settings are documented at + http://cgi-spec.golux.com/ + + + Based on the following URL request: + + http://localhost/info.php/test?a=b + + should produce, which btw is the same as if + we were running under mod_cgi on apache (ie. not + using ScriptAlias directives): + + PATH_INFO=/test + PATH_TRANSLATED=/docroot/test + SCRIPT_NAME=/info.php + REQUEST_URI=/info.php/test?a=b + SCRIPT_FILENAME=/docroot/info.php + QUERY_STRING=a=b + + but what we get is (cgi/mod_fastcgi under apache): + + PATH_INFO=/info.php/test + PATH_TRANSLATED=/docroot/info.php/test + SCRIPT_NAME=/php/php-cgi (from the Action setting I suppose) + REQUEST_URI=/info.php/test?a=b + SCRIPT_FILENAME=/path/to/php/bin/php-cgi (Action setting translated) + QUERY_STRING=a=b + + Comments in the code below refer to using the above URL in a request + */ static void init_request_info(TSRMLS_D) { - char *content_length = sapi_cgibin_getenv(CONTENT_LENGTH,0 TSRMLS_CC); - char *content_type = sapi_cgibin_getenv(CONTENT_TYPE,0 TSRMLS_CC); - const char *auth; - char *env_path_translated; + char *env_script_filename = sapi_cgibin_getenv(SCRIPT_FILENAME,0 TSRMLS_CC); + char *env_path_translated = sapi_cgibin_getenv(PATH_TRANSLATED,0 TSRMLS_CC); + char *script_path_translated = env_script_filename; + + /* some broken servers do not have script_filename or argv0 + an example, IIS configured in some ways. then they do more + broken stuff and set path_translated to the cgi script location */ + if
[PHP-CVS] cvs: php4(PHP_4_3) /sapi/cgi cgi_main.c /sapi/cli php_cli.c
iliaa Tue Jan 7 19:44:59 2003 EDT Modified files: (Branch: PHP_4_3) /php4/sapi/cli php_cli.c /php4/sapi/cgi cgi_main.c Log: MFH Index: php4/sapi/cli/php_cli.c diff -u php4/sapi/cli/php_cli.c:1.51.2.5 php4/sapi/cli/php_cli.c:1.51.2.6 --- php4/sapi/cli/php_cli.c:1.51.2.5Tue Dec 31 11:27:07 2002 +++ php4/sapi/cli/php_cli.c Tue Jan 7 19:44:58 2003 @@ -697,6 +697,13 @@ while (c != 10 c != 13) { c = fgetc(file_handle.handle.fp); /* skip to end of line */ } + /* handle situations where line is terminated by \r\n +*/ + if (c == 13) { + if (fgetc(file_handle.handle.fp) != 10) { + long pos = +ftell(file_handle.handle.fp); + fseek(file_handle.handle.fp, pos - 1, +SEEK_SET); + } + } CG(zend_lineno) = -2; } else { rewind(file_handle.handle.fp); Index: php4/sapi/cgi/cgi_main.c diff -u php4/sapi/cgi/cgi_main.c:1.190.2.10 php4/sapi/cgi/cgi_main.c:1.190.2.11 --- php4/sapi/cgi/cgi_main.c:1.190.2.10 Tue Dec 31 11:27:05 2002 +++ php4/sapi/cgi/cgi_main.cTue Jan 7 19:44:58 2003 @@ -1413,6 +1413,13 @@ while (c != 10 c != 13) { c = fgetc(file_handle.handle.fp); /* skip to end of line */ } + /* handle situations where line is terminated by \r\n +*/ + if (c == 13) { + if (fgetc(file_handle.handle.fp) != 10) { + long pos = +ftell(file_handle.handle.fp); + fseek(file_handle.handle.fp, pos - 1, +SEEK_SET); + } + } CG(zend_lineno) = -2; } else { rewind(file_handle.handle.fp); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4(PHP_4_3) /sapi/cgi cgi_main.c
sesser Tue Dec 24 18:50:21 2002 EDT Modified files: (Branch: PHP_4_3) /php4/sapi/cgi cgi_main.c Log: MFH Index: php4/sapi/cgi/cgi_main.c diff -u php4/sapi/cgi/cgi_main.c:1.190.2.7 php4/sapi/cgi/cgi_main.c:1.190.2.8 --- php4/sapi/cgi/cgi_main.c:1.190.2.7 Sun Dec 1 21:21:01 2002 +++ php4/sapi/cgi/cgi_main.cTue Dec 24 18:50:21 2002 @@ -121,7 +121,7 @@ #if ENABLE_PATHINFO_CHECK /* true global. this is retreived once only, even for fastcgi */ -int fix_pathinfo=1; +long fix_pathinfo=1; #endif #ifdef PHP_WIN32 -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4(PHP_4_3) /sapi/cgi cgi_main.c
shane Sun Dec 1 21:21:01 2002 EDT Modified files: (Branch: PHP_4_3) /php4/sapi/cgi cgi_main.c Log: MFH Index: php4/sapi/cgi/cgi_main.c diff -u php4/sapi/cgi/cgi_main.c:1.190.2.6 php4/sapi/cgi/cgi_main.c:1.190.2.7 --- php4/sapi/cgi/cgi_main.c:1.190.2.6 Sun Dec 1 18:27:14 2002 +++ php4/sapi/cgi/cgi_main.cSun Dec 1 21:21:01 2002 @@ -369,6 +369,7 @@ } else { snprintf(buf,len-1,%s=, name); } + #if PHP_FASTCGI /* when php is started by mod_fastcgi, no regular environment is provided to PHP. It is always sent to PHP at the start @@ -597,8 +598,10 @@ struct stat st; char *env_script_name = sapi_cgibin_getenv(SCRIPT_NAME,0 TSRMLS_CC); char *env_path_info = sapi_cgibin_getenv(PATH_INFO,0 TSRMLS_CC); + char *env_redirect_url = sapi_cgibin_getenv(REDIRECT_URL,0 +TSRMLS_CC); if (env_path_info) env_path_info = estrdup(env_path_info); - if (sapi_cgibin_getenv(REDIRECT_URL,0 TSRMLS_CC) || + + if (env_redirect_url || (env_script_name env_path_info strcmp(env_path_info,env_script_name)==0)) { /* @@ -611,6 +614,8 @@ */ _sapi_cgibin_putenv(SCRIPT_FILENAME,env_path_translated TSRMLS_CC); _sapi_cgibin_putenv(PATH_INFO,NULL TSRMLS_CC); + if (env_redirect_url) + +_sapi_cgibin_putenv(SCRIPT_NAME,env_redirect_url TSRMLS_CC); } if (stat( env_path_translated, st ) == -1 ) { @@ -620,7 +625,7 @@ while( (ptr = strrchr(pt,'/')) || (ptr = strrchr(pt,'\\')) ) { *ptr = 0; - if ( lstat(pt, st) == 0 S_ISREG(st.st_mode) ) { + if ( stat(pt, st) == 0 S_ISREG(st.st_mode) +) { /* * okay, we found the base script! * work out how many chars we had to strip off; -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php4(PHP_4_3) /sapi/cgi cgi_main.c
Wouldn't it look better to use sizeof() instead of a macro? Moriyoshi Edin Kadribasic [EMAIL PROTECTED] wrote: edink Fri Nov 22 10:47:44 2002 EDT Modified files: (Branch: PHP_4_3) /php4/sapi/cgicgi_main.c Log: MFH: Avoid possible buffer overflow. Index: php4/sapi/cgi/cgi_main.c diff -u php4/sapi/cgi/cgi_main.c:1.190.2.4 php4/sapi/cgi/cgi_main.c:1.190.2.5 --- php4/sapi/cgi/cgi_main.c:1.190.2.4Fri Nov 22 08:50:40 2002 +++ php4/sapi/cgi/cgi_main.c Fri Nov 22 10:47:44 2002 @@ -234,10 +234,11 @@ } } +#define SAPI_CGI_MAX_HEADER_LENGTH 1024 static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) { - char buf[1024]; + char buf[SAPI_CGI_MAX_HEADER_LENGTH]; sapi_header_struct *h; zend_llist_position pos; long rfc2616_headers = 0; @@ -255,7 +256,13 @@ int len; if (rfc2616_headers) { - len = sprintf(buf, %s\r\n, SG(sapi_headers).http_status_line); + len = snprintf(buf, SAPI_CGI_MAX_HEADER_LENGTH, +%s\r\n, SG(sapi_headers).http_status_line); + + if (len SAPI_CGI_MAX_HEADER_LENGTH) { + len = SAPI_CGI_MAX_HEADER_LENGTH; + } + } else { len = sprintf(buf, Status: %d\r\n, SG(sapi_headers).http_response_code); } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4(PHP_4_3) /sapi/cgi cgi_main.c
edink Fri Nov 22 08:50:41 2002 EDT Modified files: (Branch: PHP_4_3) /php4/sapi/cgi cgi_main.c Log: Don't send default http status (200) (Thanks to Sascha Schumann for idea). Index: php4/sapi/cgi/cgi_main.c diff -u php4/sapi/cgi/cgi_main.c:1.190.2.3 php4/sapi/cgi/cgi_main.c:1.190.2.4 --- php4/sapi/cgi/cgi_main.c:1.190.2.3 Fri Nov 22 05:16:36 2002 +++ php4/sapi/cgi/cgi_main.cFri Nov 22 08:50:40 2002 @@ -238,7 +238,6 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) { char buf[1024]; - int len; sapi_header_struct *h; zend_llist_position pos; long rfc2616_headers = 0; @@ -252,13 +251,17 @@ rfc2616_headers = 0; } - if (rfc2616_headers SG(sapi_headers).http_status_line) { - len = sprintf(buf, %s\r\n, SG(sapi_headers).http_status_line); - } else { - len = sprintf(buf, Status: %d\r\n, SG(sapi_headers).http_response_code); - } + if (SG(sapi_headers).http_response_code != 200) { + int len; + + if (rfc2616_headers) { + len = sprintf(buf, %s\r\n, +SG(sapi_headers).http_status_line); + } else { + len = sprintf(buf, Status: %d\r\n, +SG(sapi_headers).http_response_code); + } - PHPWRITE_H(buf, len); + PHPWRITE_H(buf, len); + } if (SG(sapi_headers).send_default_content_type) { char *hd; -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4(PHP_4_3) /sapi/cgi cgi_main.c /sapi/cli php_cli.c
andrei Thu Nov 14 16:09:43 2002 EDT Modified files: (Branch: PHP_4_3) /php4/sapi/cgi cgi_main.c /php4/sapi/cli php_cli.c Log: MFH Index: php4/sapi/cgi/cgi_main.c diff -u php4/sapi/cgi/cgi_main.c:1.190 php4/sapi/cgi/cgi_main.c:1.190.2.1 --- php4/sapi/cgi/cgi_main.c:1.190 Tue Nov 12 15:56:46 2002 +++ php4/sapi/cgi/cgi_main.cThu Nov 14 16:09:42 2002 -117,18 +117,59 #define OPTSTRING aCc:d:ef:g:hilmnqsw?vz: -static int _print_module_info(zend_module_entry *module, void *arg TSRMLS_DC) +static int print_module_info(zend_module_entry *module, void *arg TSRMLS_DC) { php_printf(%s\n, module-name); return 0; } -static int _print_extension_info(zend_extension *module, void *arg TSRMLS_DC) +static int module_name_cmp(const void *a, const void *b TSRMLS_DC) { - php_printf(%s\n, module-name); + Bucket *f = *((Bucket **) a); + Bucket *s = *((Bucket **) b); + + return strcmp(((zend_module_entry *)f-pData)-name, + ((zend_module_entry *)s-pData)-name); +} + +static void print_modules(TSRMLS_D) +{ + HashTable sorted_registry; + zend_module_entry tmp; + + zend_hash_init(sorted_registry, 50, NULL, NULL, 1); + zend_hash_copy(sorted_registry, module_registry, NULL, tmp, +sizeof(zend_module_entry)); + zend_hash_sort(sorted_registry, zend_qsort, module_name_cmp, 0 TSRMLS_CC); + zend_hash_apply_with_argument(sorted_registry, (apply_func_arg_t) +print_module_info, NULL TSRMLS_CC); + zend_hash_destroy(sorted_registry); +} + +static int print_extension_info(zend_extension *ext, void *arg TSRMLS_DC) +{ + php_printf(%s\n, ext-name); return 0; } +static int extension_name_cmp(const zend_llist_element *a, + const zend_llist_element *b +TSRMLS_DC) +{ + zend_llist_element *f = *((zend_llist_element **)a); + zend_llist_element *s = *((zend_llist_element **)b); + + return strcmp(((zend_extension *)f-data)-name, + ((zend_extension *)s-data)-name); +} + +static void print_extensions(TSRMLS_D) +{ + zend_llist sorted_exts; + + zend_llist_copy(sorted_exts, zend_extensions); + zend_llist_sort(sorted_exts, extension_name_cmp TSRMLS_CC); + zend_llist_apply_with_argument(sorted_exts, (llist_apply_with_arg_func_t) +print_extension_info, NULL TSRMLS_CC); + zend_llist_destroy(sorted_exts); +} + #ifndef STDOUT_FILENO #define STDOUT_FILENO 1 #endif -966,9 +1007,9 php_output_activate(TSRMLS_C); SG(headers_sent) = 1; php_printf([PHP Modules]\n); - zend_hash_apply_with_argument(module_registry, (apply_func_arg_t) _print_module_info, NULL TSRMLS_CC); + print_modules(TSRMLS_C); php_printf(\n[Zend Modules]\n); - zend_llist_apply_with_argument(zend_extensions, (llist_apply_with_arg_func_t) _print_extension_info, NULL TSRMLS_CC); + print_extensions(TSRMLS_C); php_printf(\n); php_end_ob_buffers(1 TSRMLS_CC); exit(1); Index: php4/sapi/cli/php_cli.c diff -u php4/sapi/cli/php_cli.c:1.51 php4/sapi/cli/php_cli.c:1.51.2.1 --- php4/sapi/cli/php_cli.c:1.51Wed Nov 13 07:41:05 2002 +++ php4/sapi/cli/php_cli.c Thu Nov 14 16:09:42 2002 -87,18 +87,56 #define OPTSTRING aCc:d:ef:g:hilmnqr:sw?vz: -static int _print_module_info(zend_module_entry *module, void *arg TSRMLS_DC) +static int print_module_info(zend_module_entry *module, void *arg TSRMLS_DC) { php_printf(%s\n, module-name); return 0; } -static int _print_extension_info(zend_extension *module, void *arg TSRMLS_DC) +static int module_name_cmp(const void *a, const void *b TSRMLS_DC) { - php_printf(%s\n, module-name); + Bucket *f = *((Bucket **) a); + Bucket *s = *((Bucket **) b); + + return strcmp(((zend_module_entry *)f-pData)-name, + ((zend_module_entry *)s-pData)-name); +} + +static void print_modules(TSRMLS_D) +{ + HashTable sorted_registry; + zend_module_entry tmp; + + zend_hash_init(sorted_registry, 50, NULL, NULL, 1); + zend_hash_copy(sorted_registry, module_registry, NULL, tmp, +sizeof(zend_module_entry)); + zend_hash_sort(sorted_registry, zend_qsort, module_name_cmp, 0 TSRMLS_CC); + zend_hash_apply_with_argument(sorted_registry, (apply_func_arg_t) +print_module_info, NULL TSRMLS_CC); + zend_hash_destroy(sorted_registry); +} + +static int print_extension_info(zend_extension *ext, void *arg TSRMLS_DC) +{ +
[PHP-CVS] cvs: php4(PHP_4_3) /sapi/cgi cgi_main.c
andrei Thu Nov 14 19:33:18 2002 EDT Modified files: (Branch: PHP_4_3) /php4/sapi/cgi cgi_main.c Log: MFH Index: php4/sapi/cgi/cgi_main.c diff -u php4/sapi/cgi/cgi_main.c:1.190.2.1 php4/sapi/cgi/cgi_main.c:1.190.2.2 --- php4/sapi/cgi/cgi_main.c:1.190.2.1 Thu Nov 14 16:09:42 2002 +++ php4/sapi/cgi/cgi_main.cThu Nov 14 19:33:18 2002 -150,14 +150,11 return 0; } -static int extension_name_cmp(const zend_llist_element *a, - const zend_llist_element *b TSRMLS_DC) +static int extension_name_cmp(const zend_llist_element **f, + const zend_llist_element **s +TSRMLS_DC) { - zend_llist_element *f = *((zend_llist_element **)a); - zend_llist_element *s = *((zend_llist_element **)b); - - return strcmp(((zend_extension *)f-data)-name, - ((zend_extension *)s-data)-name); + return strcmp(((zend_extension *)(*f)-data)-name, + ((zend_extension *)(*s)-data)-name); } static void print_extensions(TSRMLS_D) -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php