diff options
| author | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 00:37:27 -0400 |
|---|---|---|
| committer | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 00:37:27 -0400 |
| commit | 2d4e5b09576bb4f0ba716cc82cdf29ea04d9184b (patch) | |
| tree | 41ccc042009cba53e4ce43e727fcba4c1cfbf7f3 /sapi | |
| parent | d29a4fd2dd3b5d4cf6e80b602544d7b71d794e76 (diff) | |
| download | php-upstream/5.2.2.tar.gz | |
Imported Upstream version 5.2.2upstream/5.2.2
Diffstat (limited to 'sapi')
78 files changed, 2478 insertions, 575 deletions
diff --git a/sapi/aolserver/aolserver.c b/sapi/aolserver/aolserver.c index 0b88634df..65bb52c87 100644 --- a/sapi/aolserver/aolserver.c +++ b/sapi/aolserver/aolserver.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -22,7 +22,7 @@ * - CGI/1.1 conformance */ -/* $Id: aolserver.c,v 1.81.2.2 2006/01/01 12:50:18 sniper Exp $ */ +/* $Id: aolserver.c,v 1.81.2.2.2.1 2007/01/01 09:36:12 sebastian Exp $ */ /* conflict between PHP and AOLserver headers */ #define Debug php_Debug @@ -205,7 +205,7 @@ static void php_info_aolserver(ZEND_MODULE_INFO_FUNC_ARGS) int i; php_info_print_table_start(); - php_info_print_table_row(2, "SAPI module version", "$Id: aolserver.c,v 1.81.2.2 2006/01/01 12:50:18 sniper Exp $"); + php_info_print_table_row(2, "SAPI module version", "$Id: aolserver.c,v 1.81.2.2.2.1 2007/01/01 09:36:12 sebastian Exp $"); php_info_print_table_row(2, "Build date", Ns_InfoBuildDate()); php_info_print_table_row(2, "Config file path", Ns_InfoConfigFile()); php_info_print_table_row(2, "Error Log path", Ns_InfoErrorLog()); diff --git a/sapi/apache/libpre.c b/sapi/apache/libpre.c index 3556883d2..e8e52c869 100644 --- a/sapi/apache/libpre.c +++ b/sapi/apache/libpre.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: libpre.c,v 1.6.2.1 2006/01/01 12:50:18 sniper Exp $ */ +/* $Id: libpre.c,v 1.6.2.1.2.1 2007/01/01 09:36:12 sebastian Exp $ */ #ifdef NETWARE diff --git a/sapi/apache/mod_php5.c b/sapi/apache/mod_php5.c index 118b9cfc9..d49901ff9 100644 --- a/sapi/apache/mod_php5.c +++ b/sapi/apache/mod_php5.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ | PHP 4.0 patches by Zeev Suraski <zeev@zend.com> | +----------------------------------------------------------------------+ */ -/* $Id: mod_php5.c,v 1.19.2.7.2.6 2006/10/12 20:02:58 bfrance Exp $ */ +/* $Id: mod_php5.c,v 1.19.2.7.2.9 2007/01/01 09:36:12 sebastian Exp $ */ #include "php_apache_http.h" #include "http_conf_globals.h" @@ -246,10 +246,11 @@ static void sapi_apache_register_server_variables(zval *track_vars_array TSRMLS_ table_entry *elts = (table_entry *) arr->elts; zval **path_translated; HashTable *symbol_table; + int new_val_len; for (i = 0; i < arr->nelts; i++) { char *val; - int val_len, new_val_len; + int val_len; if (elts[i].val) { val = elts[i].val; @@ -277,7 +278,9 @@ static void sapi_apache_register_server_variables(zval *track_vars_array TSRMLS_ php_register_variable("PATH_TRANSLATED", Z_STRVAL_PP(path_translated), track_vars_array TSRMLS_CC); } - php_register_variable("PHP_SELF", ((request_rec *) SG(server_context))->uri, track_vars_array TSRMLS_CC); + if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &((request_rec *) SG(server_context))->uri, strlen(((request_rec *) SG(server_context))->uri), &new_val_len TSRMLS_CC)) { + php_register_variable("PHP_SELF", ((request_rec *) SG(server_context))->uri, track_vars_array TSRMLS_CC); + } } /* }}} */ @@ -673,16 +676,10 @@ static int send_php(request_rec *r, int display_source_mode, char *filename) static int send_parsed_php(request_rec * r) { int result = send_php(r, 0, NULL); - -#if MEMORY_LIMIT - { - char *mem_usage; - TSRMLS_FETCH(); + TSRMLS_FETCH(); - mem_usage = ap_psprintf(r->pool, "%u", zend_memory_peak_usage(1 TSRMLS_CC)); - ap_table_setn(r->notes, "mod_php_memory_usage", mem_usage); - } -#endif + ap_table_setn(r->notes, "mod_php_memory_usage", + ap_psprintf(r->pool, "%u", zend_memory_peak_usage(1 TSRMLS_CC))); return result; } diff --git a/sapi/apache/mod_php5.h b/sapi/apache/mod_php5.h index 5a1e4f839..b9bc6cc99 100644 --- a/sapi/apache/mod_php5.h +++ b/sapi/apache/mod_php5.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -15,7 +15,7 @@ | Author: Rasmus Lerdorf <rasmus@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: mod_php5.h,v 1.4.2.1 2006/01/01 12:50:18 sniper Exp $ */ +/* $Id: mod_php5.h,v 1.4.2.1.2.1 2007/01/01 09:36:12 sebastian Exp $ */ #ifndef MOD_PHP5_H #define MOD_PHP5_H diff --git a/sapi/apache/php_apache.c b/sapi/apache/php_apache.c index 18671af8a..70d999bdd 100644 --- a/sapi/apache/php_apache.c +++ b/sapi/apache/php_apache.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ | David Sklar <sklar@student.net> | +----------------------------------------------------------------------+ */ -/* $Id: php_apache.c,v 1.89.2.4.2.1 2006/09/06 11:54:28 nlopess Exp $ */ +/* $Id: php_apache.c,v 1.89.2.4.2.5 2007/02/24 02:17:28 helly Exp $ */ #include "php_apache_http.h" @@ -207,20 +207,20 @@ PHP_MINFO_FUNCTION(apache) } #ifdef APACHE_RELEASE - sprintf(output_buf, "%d", APACHE_RELEASE); + snprintf(output_buf, sizeof(output_buf), "%d", APACHE_RELEASE); php_info_print_table_row(2, "Apache Release", output_buf); #endif - sprintf(output_buf, "%d", MODULE_MAGIC_NUMBER); + snprintf(output_buf, sizeof(output_buf), "%d", MODULE_MAGIC_NUMBER); php_info_print_table_row(2, "Apache API Version", output_buf); - sprintf(output_buf, "%s:%u", serv->server_hostname, serv->port); + snprintf(output_buf, sizeof(output_buf), "%s:%u", serv->server_hostname, serv->port); php_info_print_table_row(2, "Hostname:Port", output_buf); #if !defined(WIN32) && !defined(WINNT) - sprintf(output_buf, "%s(%d)/%d", user_name, (int)user_id, (int)group_id); + snprintf(output_buf, sizeof(output_buf), "%s(%d)/%d", user_name, (int)user_id, (int)group_id); php_info_print_table_row(2, "User/Group", output_buf); - sprintf(output_buf, "Per Child: %d - Keep Alive: %s - Max Per Connection: %d", max_requests_per_child, serv->keep_alive ? "on":"off", serv->keep_alive_max); + snprintf(output_buf, sizeof(output_buf), "Per Child: %d - Keep Alive: %s - Max Per Connection: %d", max_requests_per_child, serv->keep_alive ? "on":"off", serv->keep_alive_max); php_info_print_table_row(2, "Max Requests", output_buf); #endif - sprintf(output_buf, "Connection: %d - Keep-Alive: %d", serv->timeout, serv->keep_alive_timeout); + snprintf(output_buf, sizeof(output_buf), "Connection: %d - Keep-Alive: %d", serv->timeout, serv->keep_alive_timeout); php_info_print_table_row(2, "Timeouts", output_buf); #if !defined(WIN32) && !defined(WINNT) /* @@ -235,9 +235,9 @@ PHP_MINFO_FUNCTION(apache) if ((p = strrchr(name, '.'))) { *p='\0'; /* Cut off ugly .c extensions on module names */ } - strcat(modulenames, name); + strlcat(modulenames, name, sizeof(modulenames)); if (modp->next) { - strcat(modulenames, ", "); + strlcat(modulenames, ", ", sizeof(modulenames)); } } php_info_print_table_row(2, "Loaded Modules", modulenames); diff --git a/sapi/apache/php_apache_http.h b/sapi/apache/php_apache_http.h index 0926d1583..08f41cdc3 100644 --- a/sapi/apache/php_apache_http.h +++ b/sapi/apache/php_apache_http.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_apache_http.h,v 1.13.2.1 2006/01/01 12:50:18 sniper Exp $ */ +/* $Id: php_apache_http.h,v 1.13.2.1.2.1 2007/01/01 09:36:12 sebastian Exp $ */ #define NO_REGEX_EXTRA_H diff --git a/sapi/apache/sapi_apache.c b/sapi/apache/sapi_apache.c index d30a3b1f3..c8aad6c7f 100644 --- a/sapi/apache/sapi_apache.c +++ b/sapi/apache/sapi_apache.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -19,7 +19,7 @@ | Stig Bakken <ssb@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: sapi_apache.c,v 1.47.2.1 2006/01/01 12:50:18 sniper Exp $ */ +/* $Id: sapi_apache.c,v 1.47.2.1.2.1 2007/01/01 09:36:12 sebastian Exp $ */ #include "php_apache_http.h" diff --git a/sapi/apache2filter/apache_config.c b/sapi/apache2filter/apache_config.c index eca894aaa..fe43075e8 100644 --- a/sapi/apache2filter/apache_config.c +++ b/sapi/apache2filter/apache_config.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: apache_config.c,v 1.34.2.1.2.1 2006/06/09 16:29:35 mike Exp $ */ +/* $Id: apache_config.c,v 1.34.2.1.2.2 2007/01/01 09:36:12 sebastian Exp $ */ #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS diff --git a/sapi/apache2filter/php_apache.h b/sapi/apache2filter/php_apache.h index 87e9baaa4..62bf682c3 100644 --- a/sapi/apache2filter/php_apache.h +++ b/sapi/apache2filter/php_apache.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_apache.h,v 1.25.2.1.2.1 2006/07/03 16:51:38 john Exp $ */ +/* $Id: php_apache.h,v 1.25.2.1.2.2 2007/01/01 09:36:12 sebastian Exp $ */ #ifndef PHP_APACHE_H #define PHP_APACHE_H diff --git a/sapi/apache2filter/php_functions.c b/sapi/apache2filter/php_functions.c index 0d23be263..7e4a6d8a8 100644 --- a/sapi/apache2filter/php_functions.c +++ b/sapi/apache2filter/php_functions.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_functions.c,v 1.44.2.2 2006/01/01 12:50:18 sniper Exp $ */ +/* $Id: php_functions.c,v 1.44.2.2.2.2 2007/01/01 09:36:12 sebastian Exp $ */ #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS @@ -289,7 +289,11 @@ PHP_FUNCTION(apache_getenv) static char *php_apache_get_version() { +#if MODULE_MAGIC_NUMBER_MAJOR >= 20060905 + return (char *) ap_get_server_banner(); +#else return (char *) ap_get_server_version(); +#endif } /* {{{ proto string apache_get_version(void) diff --git a/sapi/apache2filter/sapi_apache2.c b/sapi/apache2filter/sapi_apache2.c index 1ed582b40..9af6fa823 100644 --- a/sapi/apache2filter/sapi_apache2.c +++ b/sapi/apache2filter/sapi_apache2.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: sapi_apache2.c,v 1.136.2.2.2.3 2006/07/25 13:40:05 dmitry Exp $ */ +/* $Id: sapi_apache2.c,v 1.136.2.2.2.8 2007/01/01 09:36:12 sebastian Exp $ */ #include <fcntl.h> @@ -210,13 +210,21 @@ php_apache_sapi_register_variables(zval *track_vars_array TSRMLS_DC) php_struct *ctx = SG(server_context); const apr_array_header_t *arr = apr_table_elts(ctx->r->subprocess_env); char *key, *val; + int new_val_len; APR_ARRAY_FOREACH_OPEN(arr, key, val) - if (!val) val = ""; - php_register_variable(key, val, track_vars_array TSRMLS_CC); + if (!val) { + val = ""; + } + if (sapi_module.input_filter(PARSE_SERVER, key, &val, strlen(val), &new_val_len TSRMLS_CC)) { + php_register_variable_safe(key, val, new_val_len, track_vars_array TSRMLS_CC); + } APR_ARRAY_FOREACH_CLOSE() php_register_variable("PHP_SELF", ctx->r->uri, track_vars_array TSRMLS_CC); + if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &ctx->r->uri, strlen(ctx->r->uri), &new_val_len TSRMLS_CC)) { + php_register_variable_safe("PHP_SELF", ctx->r->uri, new_val_len, track_vars_array TSRMLS_CC); + } } static void @@ -434,10 +442,10 @@ static int php_output_filter(ap_filter_t *f, apr_bucket_brigade *bb) php_struct *ctx; void *conf = ap_get_module_config(f->r->per_dir_config, &php5_module); char *p = get_php_config(conf, "engine", sizeof("engine")); - TSRMLS_FETCH(); zend_file_handle zfd; php_apr_bucket_brigade *pbb; apr_bucket *b; + TSRMLS_FETCH(); if (f->r->proxyreq) { zend_try { @@ -503,6 +511,7 @@ static int php_output_filter(ap_filter_t *f, apr_bucket_brigade *bb) return ap_pass_brigade(f->next, bb); } + apply_config(conf); php_apache_request_ctor(f, ctx TSRMLS_CC); // It'd be nice if we could highlight based of a zend_file_handle here.... @@ -522,14 +531,8 @@ static int php_output_filter(ap_filter_t *f, apr_bucket_brigade *bb) php_execute_script(&zfd TSRMLS_CC); -#if MEMORY_LIMIT - { - char *mem_usage; - - mem_usage = apr_psprintf(ctx->r->pool, "%u", zend_memory_peak_usage(1 TSRMLS_CC)); - apr_table_set(ctx->r->notes, "mod_php_memory_usage", mem_usage); - } -#endif + apr_table_set(ctx->r->notes, "mod_php_memory_usage", + apr_psprintf(ctx->r->pool, "%u", zend_memory_peak_usage(1 TSRMLS_CC))); php_apache_request_dtor(f TSRMLS_CC); diff --git a/sapi/apache2handler/apache_config.c b/sapi/apache2handler/apache_config.c index bd80bb86f..64bcb0bc1 100644 --- a/sapi/apache2handler/apache_config.c +++ b/sapi/apache2handler/apache_config.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: apache_config.c,v 1.7.2.1.2.1 2006/06/09 15:13:39 mike Exp $ */ +/* $Id: apache_config.c,v 1.7.2.1.2.2 2007/01/01 09:36:12 sebastian Exp $ */ #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS diff --git a/sapi/apache2handler/mod_php5.c b/sapi/apache2handler/mod_php5.c index ad1be19fe..6c1ea1655 100644 --- a/sapi/apache2handler/mod_php5.c +++ b/sapi/apache2handler/mod_php5.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: mod_php5.c,v 1.5.2.1 2006/01/01 12:50:18 sniper Exp $ */ +/* $Id: mod_php5.c,v 1.5.2.1.2.1 2007/01/01 09:36:12 sebastian Exp $ */ #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS diff --git a/sapi/apache2handler/php_apache.h b/sapi/apache2handler/php_apache.h index e4030cbbe..51a8a9bbd 100644 --- a/sapi/apache2handler/php_apache.h +++ b/sapi/apache2handler/php_apache.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_apache.h,v 1.8.2.1.2.1 2006/05/28 20:32:00 mike Exp $ */ +/* $Id: php_apache.h,v 1.8.2.1.2.2 2007/01/01 09:36:12 sebastian Exp $ */ #ifndef PHP_APACHE_H #define PHP_APACHE_H diff --git a/sapi/apache2handler/php_functions.c b/sapi/apache2handler/php_functions.c index d1ffb22e8..ab60415cb 100644 --- a/sapi/apache2handler/php_functions.c +++ b/sapi/apache2handler/php_functions.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_functions.c,v 1.18.2.6 2006/01/03 20:13:07 iliaa Exp $ */ +/* $Id: php_functions.c,v 1.18.2.6.2.5 2007/02/24 02:17:28 helly Exp $ */ #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS @@ -42,7 +42,7 @@ #include "util_script.h" #include "http_core.h" #include "ap_mpm.h" -#if !defined(WIN32) && !defined(WINNT) +#if !defined(WIN32) && !defined(WINNT) && !defined(NETWARE) #include "unixd.h" #endif @@ -333,7 +333,11 @@ PHP_FUNCTION(apache_getenv) static char *php_apache_get_version() { +#if MODULE_MAGIC_NUMBER_MAJOR >= 20060905 + return (char *) ap_get_server_banner(); +#else return (char *) ap_get_server_version(); +#endif } /* {{{ proto string apache_get_version(void) @@ -378,7 +382,7 @@ PHP_MINFO_FUNCTION(apache) int n, max_requests; char *p; server_rec *serv = ((php_struct *) SG(server_context))->r->server; -#if !defined(WIN32) && !defined(WINNT) +#if !defined(WIN32) && !defined(WINNT) && !defined(NETWARE) AP_DECLARE_DATA extern unixd_config_rec unixd_config; #endif @@ -399,23 +403,23 @@ PHP_MINFO_FUNCTION(apache) if (apv && *apv) { php_info_print_table_row(2, "Apache Version", apv); } - sprintf(tmp, "%d", MODULE_MAGIC_NUMBER); + snprintf(tmp, sizeof(tmp), "%d", MODULE_MAGIC_NUMBER); php_info_print_table_row(2, "Apache API Version", tmp); if (serv->server_admin && *(serv->server_admin)) { php_info_print_table_row(2, "Server Administrator", serv->server_admin); } - sprintf(tmp, "%s:%u", serv->server_hostname, serv->port); + snprintf(tmp, sizeof(tmp), "%s:%u", serv->server_hostname, serv->port); php_info_print_table_row(2, "Hostname:Port", tmp); -#if !defined(WIN32) && !defined(WINNT) - sprintf(tmp, "%s(%d)/%d", unixd_config.user_name, unixd_config.user_id, unixd_config.group_id); +#if !defined(WIN32) && !defined(WINNT) && !defined(NETWARE) + snprintf(tmp, sizeof(tmp), "%s(%d)/%d", unixd_config.user_name, unixd_config.user_id, unixd_config.group_id); php_info_print_table_row(2, "User/Group", tmp); #endif ap_mpm_query(AP_MPMQ_MAX_REQUESTS_DAEMON, &max_requests); - sprintf(tmp, "Per Child: %d - Keep Alive: %s - Max Per Connection: %d", max_requests, (serv->keep_alive ? "on":"off"), serv->keep_alive_max); + snprintf(tmp, sizeof(tmp), "Per Child: %d - Keep Alive: %s - Max Per Connection: %d", max_requests, (serv->keep_alive ? "on":"off"), serv->keep_alive_max); php_info_print_table_row(2, "Max Requests", tmp); apr_snprintf(tmp, sizeof tmp, diff --git a/sapi/apache2handler/sapi_apache2.c b/sapi/apache2handler/sapi_apache2.c index 21bce6128..56b449c74 100644 --- a/sapi/apache2handler/sapi_apache2.c +++ b/sapi/apache2handler/sapi_apache2.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: sapi_apache2.c,v 1.57.2.10.2.6 2006/08/10 13:43:18 tony2001 Exp $ */ +/* $Id: sapi_apache2.c,v 1.57.2.10.2.13 2007/01/01 09:36:12 sebastian Exp $ */ #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS @@ -129,9 +129,14 @@ php_apache_sapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) /* httpd requires that r->status_line is set to the first digit of * the status-code: */ - if (sline && strlen(sline) > 12 && strncmp(sline, "HTTP/1.", 7) == 0 - && sline[8] == ' ') { + if (sline && strlen(sline) > 12 && strncmp(sline, "HTTP/1.", 7) == 0 && sline[8] == ' ') { ctx->r->status_line = apr_pstrdup(ctx->r->pool, sline + 9); + ctx->r->proto_num = 1000 + (sline[7]-'0'); + if ((sline[7]-'0') == 0) { + apr_table_set(ctx->r->subprocess_env, "force-response-1.0", "true"); + } else { + apr_table_set(ctx->r->subprocess_env, "force-response-1.1", "true"); + } } /* call ap_set_content_type only once, else each time we call it, @@ -232,13 +237,20 @@ php_apache_sapi_register_variables(zval *track_vars_array TSRMLS_DC) php_struct *ctx = SG(server_context); const apr_array_header_t *arr = apr_table_elts(ctx->r->subprocess_env); char *key, *val; + int new_val_len; APR_ARRAY_FOREACH_OPEN(arr, key, val) - if (!val) val = ""; - php_register_variable(key, val, track_vars_array TSRMLS_CC); + if (!val) { + val = ""; + } + if (sapi_module.input_filter(PARSE_SERVER, key, &val, strlen(val), &new_val_len TSRMLS_CC)) { + php_register_variable_safe(key, val, new_val_len, track_vars_array TSRMLS_CC); + } APR_ARRAY_FOREACH_CLOSE() - php_register_variable("PHP_SELF", ctx->r->uri, track_vars_array TSRMLS_CC); + if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &ctx->r->uri, strlen(ctx->r->uri), &new_val_len TSRMLS_CC)) { + php_register_variable_safe("PHP_SELF", ctx->r->uri, new_val_len, track_vars_array TSRMLS_CC); + } } static void @@ -455,6 +467,20 @@ static void php_apache_ini_dtor(request_rec *r, request_rec *p TSRMLS_DC) { if (strcmp(r->protocol, "INCLUDED")) { zend_try { zend_ini_deactivate(TSRMLS_C); } zend_end_try(); + } else { +typedef struct { + HashTable config; +} php_conf_rec; + char *str; + uint str_len; + php_conf_rec *c = ap_get_module_config(r->per_dir_config, &php5_module); + + for (zend_hash_internal_pointer_reset(&c->config); + zend_hash_get_current_key_ex(&c->config, &str, &str_len, NULL, 0, NULL) == HASH_KEY_IS_STRING; + zend_hash_move_forward(&c->config) + ) { + zend_restore_ini_entry(str, str_len, ZEND_INI_STAGE_SHUTDOWN); + } } if (p) { ((php_struct *)SG(server_context))->r = p; @@ -561,8 +587,13 @@ zend_first_try { } } - /* check if comming due to ErrorDocument */ - if (parent_req && parent_req->status != HTTP_OK) { + /* + * check if comming due to ErrorDocument + * We make a special exception of 413 (Invalid POST request) as the invalidity of the request occurs + * during processing of the request by PHP during POST processing. Therefor we need to re-use the exiting + * PHP instance to handle the request rather then creating a new one. + */ + if (parent_req && parent_req->status != HTTP_OK && parent_req->status != 413 && strcmp(r->protocol, "INCLUDED")) { parent_req = NULL; goto normal; } @@ -593,14 +624,9 @@ zend_first_try { } else { zend_execute_scripts(ZEND_INCLUDE TSRMLS_CC, NULL, 1, &zfd); } -#if MEMORY_LIMIT - { - char *mem_usage; - mem_usage = apr_psprintf(ctx->r->pool, "%u", zend_memory_peak_usage(1 TSRMLS_CC)); - apr_table_set(r->notes, "mod_php_memory_usage", mem_usage); - } -#endif + apr_table_set(r->notes, "mod_php_memory_usage", + apr_psprintf(ctx->r->pool, "%u", zend_memory_peak_usage(1 TSRMLS_CC))); } } zend_end_try(); diff --git a/sapi/apache_hooks/mod_php5.c b/sapi/apache_hooks/mod_php5.c index cc3236f38..0c0e33535 100644 --- a/sapi/apache_hooks/mod_php5.c +++ b/sapi/apache_hooks/mod_php5.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ | PHP 4.0 patches by Zeev Suraski <zeev@zend.com> | +----------------------------------------------------------------------+ */ -/* $Id: mod_php5.c,v 1.11.2.1.2.3 2006/08/03 09:56:50 dmitry Exp $ */ +/* $Id: mod_php5.c,v 1.11.2.1.2.5 2007/01/01 09:36:12 sebastian Exp $ */ #include "php_apache_http.h" @@ -736,16 +736,10 @@ static int send_php(request_rec *r, int display_source_mode, char *filename) static int send_parsed_php(request_rec * r) { int result = send_php(r, 0, NULL); - -#if MEMORY_LIMIT - { - char *mem_usage; - TSRMLS_FETCH(); + TSRMLS_FETCH(); - mem_usage = ap_psprintf(r->pool, "%u", zend_memory_peak_usage(1 TSRMLS_CC)); - ap_table_setn(r->notes, "mod_php_memory_usage", mem_usage); - } -#endif + ap_table_setn(r->notes, "mod_php_memory_usage", + ap_psprintf(r->pool, "%u", zend_memory_peak_usage(1 TSRMLS_CC))); return result; } diff --git a/sapi/apache_hooks/mod_php5.h b/sapi/apache_hooks/mod_php5.h index 4fa7339dd..975fc1634 100644 --- a/sapi/apache_hooks/mod_php5.h +++ b/sapi/apache_hooks/mod_php5.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -15,7 +15,7 @@ | Author: Rasmus Lerdorf <rasmus@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: mod_php5.h,v 1.2.2.1 2006/01/01 12:50:18 sniper Exp $ */ +/* $Id: mod_php5.h,v 1.2.2.1.2.1 2007/01/01 09:36:12 sebastian Exp $ */ #ifndef MOD_PHP5_H #define MOD_PHP5_H diff --git a/sapi/apache_hooks/php_apache.c b/sapi/apache_hooks/php_apache.c index 256d5e08b..83d86f658 100644 --- a/sapi/apache_hooks/php_apache.c +++ b/sapi/apache_hooks/php_apache.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ | David Sklar <sklar@student.net> | +----------------------------------------------------------------------+ */ -/* $Id: php_apache.c,v 1.19.2.3.2.1 2006/09/06 11:54:29 nlopess Exp $ */ +/* $Id: php_apache.c,v 1.19.2.3.2.5 2007/02/24 02:17:28 helly Exp $ */ #include "php_apache_http.h" @@ -1609,20 +1609,20 @@ PHP_MINFO_FUNCTION(apache) php_info_print_table_row(2, "Apache Version", SERVER_VERSION); #ifdef APACHE_RELEASE - sprintf(output_buf, "%d", APACHE_RELEASE); + snprintf(output_buf, sizeof(output_buf), "%d", APACHE_RELEASE); php_info_print_table_row(2, "Apache Release", output_buf); #endif - sprintf(output_buf, "%d", MODULE_MAGIC_NUMBER); + snprintf(output_buf, sizeof(output_buf), "%d", MODULE_MAGIC_NUMBER); php_info_print_table_row(2, "Apache API Version", output_buf); - sprintf(output_buf, "%s:%u", serv->server_hostname, serv->port); + snprintf(output_buf, sizeof(output_buf), "%s:%u", serv->server_hostname, serv->port); php_info_print_table_row(2, "Hostname:Port", output_buf); #if !defined(WIN32) && !defined(WINNT) - sprintf(output_buf, "%s(%d)/%d", user_name, (int)user_id, (int)group_id); + snprintf(output_buf, sizeof(output_buf), "%s(%d)/%d", user_name, (int)user_id, (int)group_id); php_info_print_table_row(2, "User/Group", output_buf); - sprintf(output_buf, "Per Child: %d - Keep Alive: %s - Max Per Connection: %d", max_requests_per_child, serv->keep_alive ? "on":"off", serv->keep_alive_max); + snprintf(output_buf, sizeof(output_buf), "Per Child: %d - Keep Alive: %s - Max Per Connection: %d", max_requests_per_child, serv->keep_alive ? "on":"off", serv->keep_alive_max); php_info_print_table_row(2, "Max Requests", output_buf); #endif - sprintf(output_buf, "Connection: %d - Keep-Alive: %d", serv->timeout, serv->keep_alive_timeout); + snprintf(output_buf, sizeof(output_buf), "Connection: %d - Keep-Alive: %d", serv->timeout, serv->keep_alive_timeout); php_info_print_table_row(2, "Timeouts", output_buf); #if !defined(WIN32) && !defined(WINNT) /* @@ -1637,9 +1637,9 @@ PHP_MINFO_FUNCTION(apache) if ((p = strrchr(name, '.'))) { *p='\0'; /* Cut off ugly .c extensions on module names */ } - strcat(modulenames, name); + strlcat(modulenames, name, sizeof(modulenames)); if (modp->next) { - strcat(modulenames, ", "); + strlcat(modulenames, ", ", sizeof(modulenames)); } } php_info_print_table_row(2, "Loaded Modules", modulenames); diff --git a/sapi/apache_hooks/sapi_apache.c b/sapi/apache_hooks/sapi_apache.c index be22fb3a2..ac1e4cc78 100644 --- a/sapi/apache_hooks/sapi_apache.c +++ b/sapi/apache_hooks/sapi_apache.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -19,7 +19,7 @@ | Stig Bakken <ssb@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: sapi_apache.c,v 1.9.2.1 2006/01/01 12:50:18 sniper Exp $ */ +/* $Id: sapi_apache.c,v 1.9.2.1.2.1 2007/01/01 09:36:12 sebastian Exp $ */ #include "php_apache_http.h" diff --git a/sapi/caudium/caudium.c b/sapi/caudium/caudium.c index 5ae2e0f45..ea0467ee2 100644 --- a/sapi/caudium/caudium.c +++ b/sapi/caudium/caudium.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: caudium.c,v 1.36.2.1 2006/01/01 12:50:18 sniper Exp $ */ +/* $Id: caudium.c,v 1.36.2.1.2.1 2007/01/01 09:36:12 sebastian Exp $ */ #include "php.h" #ifdef HAVE_CAUDIUM @@ -444,7 +444,7 @@ static void php_info_caudium(ZEND_MODULE_INFO_FUNC_ARGS) { /* char buf[512]; */ php_info_print_table_start(); - php_info_print_table_row(2, "SAPI module version", "$Id: caudium.c,v 1.36.2.1 2006/01/01 12:50:18 sniper Exp $"); + php_info_print_table_row(2, "SAPI module version", "$Id: caudium.c,v 1.36.2.1.2.1 2007/01/01 09:36:12 sebastian Exp $"); /* php_info_print_table_row(2, "Build date", Ns_InfoBuildDate()); php_info_print_table_row(2, "Config file path", Ns_InfoConfigFile()); php_info_print_table_row(2, "Error Log path", Ns_InfoErrorLog()); diff --git a/sapi/cgi/CREDITS b/sapi/cgi/CREDITS index a1c6a0be5..1a2ec4901 100644 --- a/sapi/cgi/CREDITS +++ b/sapi/cgi/CREDITS @@ -1,2 +1,2 @@ CGI / FastCGI -Rasmus Lerdorf, Stig Bakken, Shane Caraveo +Rasmus Lerdorf, Stig Bakken, Shane Caraveo, Dmitry Stogov diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index 51fc7c4c3..7ce569466 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: cgi_main.c,v 1.267.2.15.2.13 2006/09/23 12:27:40 tony2001 Exp $ */ +/* $Id: cgi_main.c,v 1.267.2.15.2.36 2007/04/17 20:00:53 sniper Exp $ */ #include "php.h" #include "php_globals.h" @@ -119,12 +119,11 @@ static pid_t pgroup; static char *php_optarg = NULL; static int php_optind = 1; +static zend_module_entry cgi_module_entry; static const opt_struct OPTIONS[] = { {'a', 0, "interactive"}, -#ifndef PHP_WIN32 {'b', 1, "bindpath"}, -#endif {'C', 0, "no-chdir"}, {'c', 1, "php-ini"}, {'d', 1, "define"}, @@ -145,17 +144,32 @@ static const opt_struct OPTIONS[] = { {'-', 0, NULL} /* end of args */ }; +typedef struct _php_cgi_globals_struct { + zend_bool rfc2616_headers; + zend_bool nph; + zend_bool check_shebang_line; #if ENABLE_PATHINFO_CHECK -/* true global. this is retreived once only, even for fastcgi */ -long fix_pathinfo = 1; + zend_bool fix_pathinfo; +#endif +#if FORCE_CGI_REDIRECT + zend_bool force_redirect; + char *redirect_status_env; #endif - #if PHP_FASTCGI -long fcgi_logging = 1; + zend_bool fcgi_logging; +# ifdef PHP_WIN32 + zend_bool impersonate; +# endif #endif +} php_cgi_globals_struct; -static long rfc2616_headers = 0; -static long cgi_nph = 0; +#ifdef ZTS +static int php_cgi_globals_id; +#define CGIG(v) TSRMG(php_cgi_globals_id, php_cgi_globals_struct *, v) +#else +static php_cgi_globals_struct php_cgi_globals; +#define CGIG(v) (php_cgi_globals.v) +#endif #ifdef PHP_WIN32 #define TRANSLATE_SLASHES(path) \ @@ -304,12 +318,12 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) return SAPI_HEADER_SENT_SUCCESSFULLY; } - if (cgi_nph || SG(sapi_headers).http_response_code != 200) + if (CGIG(nph) || SG(sapi_headers).http_response_code != 200) { int len; - if (rfc2616_headers && SG(sapi_headers).http_status_line) { - len = snprintf(buf, SAPI_CGI_MAX_HEADER_LENGTH, + if (CGIG(rfc2616_headers) && SG(sapi_headers).http_status_line) { + len = slprintf(buf, SAPI_CGI_MAX_HEADER_LENGTH, "%s\r\n", SG(sapi_headers).http_status_line); if (len > SAPI_CGI_MAX_HEADER_LENGTH) { @@ -317,7 +331,7 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) } } else { - len = sprintf(buf, "Status: %d\r\n", SG(sapi_headers).http_response_code); + len = slprintf(buf, sizeof(buf), "Status: %d\r\n", SG(sapi_headers).http_response_code); } PHPWRITE_H(buf, len); @@ -340,18 +354,14 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) static int sapi_cgi_read_post(char *buffer, uint count_bytes TSRMLS_DC) { - uint read_bytes=0, tmp_read_bytes; -#if PHP_FASTCGI - char *pos = buffer; -#endif + int read_bytes=0, tmp_read_bytes; count_bytes = MIN(count_bytes, (uint) SG(request_info).content_length - SG(read_post_bytes)); while (read_bytes < count_bytes) { #if PHP_FASTCGI if (fcgi_is_fastcgi()) { fcgi_request *request = (fcgi_request*) SG(server_context); - tmp_read_bytes = fcgi_read(request, pos, count_bytes - read_bytes); - pos += tmp_read_bytes; + tmp_read_bytes = fcgi_read(request, buffer + read_bytes, count_bytes - read_bytes); } else { tmp_read_bytes = read(0, buffer + read_bytes, count_bytes - read_bytes); } @@ -432,13 +442,13 @@ static char *_sapi_cgibin_putenv(char *name, char *value TSRMLS_DC) #endif #if !HAVE_SETENV if (value) { - len = snprintf(buf, len - 1, "%s=%s", name, value); + len = slprintf(buf, len - 1, "%s=%s", name, value); putenv(buf); } #endif #if !HAVE_UNSETENV if (!value) { - len = snprintf(buf, len - 1, "%s=", name); + len = slprintf(buf, len - 1, "%s=", name); putenv(buf); } #endif @@ -483,6 +493,7 @@ void cgi_php_import_environment_variables(zval *array_ptr TSRMLS_DC) char *var, **val; uint var_len; ulong idx; + int filter_arg = (array_ptr == PG(http_globals)[TRACK_VARS_ENV])?PARSE_ENV:PARSE_SERVER; /* turn off magic_quotes while importing environment variables */ PG(magic_quotes_gpc) = 0; @@ -490,7 +501,10 @@ void cgi_php_import_environment_variables(zval *array_ptr TSRMLS_DC) zend_hash_get_current_key_ex(&request->env, &var, &var_len, &idx, 0, &pos) == HASH_KEY_IS_STRING && zend_hash_get_current_data_ex(&request->env, (void **) &val, &pos) == SUCCESS; zend_hash_move_forward_ex(&request->env, &pos)) { - php_register_variable(var, *val, array_ptr TSRMLS_CC); + unsigned int new_val_len; + if (sapi_module.input_filter(filter_arg, var, val, strlen(*val), &new_val_len TSRMLS_CC)) { + php_register_variable_safe(var, *val, new_val_len, array_ptr TSRMLS_CC); + } } PG(magic_quotes_gpc) = magic_quotes_gpc; } @@ -499,20 +513,25 @@ void cgi_php_import_environment_variables(zval *array_ptr TSRMLS_DC) static void sapi_cgi_register_variables(zval *track_vars_array TSRMLS_DC) { + unsigned int new_val_len; + char *val = SG(request_info).request_uri ? SG(request_info).request_uri : ""; /* In CGI mode, we consider the environment to be a part of the server * variables */ php_import_environment_variables(track_vars_array TSRMLS_CC); /* Build the special-case PHP_SELF variable for the CGI version */ - php_register_variable("PHP_SELF", (SG(request_info).request_uri ? SG(request_info).request_uri : ""), track_vars_array TSRMLS_CC); + if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &val, strlen(val), &new_val_len TSRMLS_CC)) { + php_register_variable_safe("PHP_SELF", val, new_val_len, track_vars_array TSRMLS_CC); + } } static void sapi_cgi_log_message(char *message) { #if PHP_FASTCGI - if (fcgi_is_fastcgi() && fcgi_logging) { + TSRMLS_FETCH(); + + if (fcgi_is_fastcgi() && CGIG(fcgi_logging)) { fcgi_request *request; - TSRMLS_FETCH(); request = (fcgi_request*) SG(server_context); if (request) { @@ -547,7 +566,7 @@ static int sapi_cgi_deactivate(TSRMLS_D) 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, &cgi_module_entry, 1) == FAILURE) { return FAILURE; } return SUCCESS; @@ -609,7 +628,7 @@ static void php_cgi_usage(char *argv0) php_printf("Usage: %s [-q] [-h] [-s] [-v] [-i] [-f <file>]\n" " %s <file> [args...]\n" " -a Run interactively\n" -#if PHP_FASTCGI && !defined(PHP_WIN32) +#if PHP_FASTCGI " -b <address:port>|<port> Bind Path for external FASTCGI Server mode\n" #endif " -C Do not chdir to the script's directory\n" @@ -737,34 +756,18 @@ static void init_request_info(TSRMLS_D) char *env_redirect_url = sapi_cgibin_getenv("REDIRECT_URL", sizeof("REDIRECT_URL")-1 TSRMLS_CC); char *env_document_root = sapi_cgibin_getenv("DOCUMENT_ROOT", sizeof("DOCUMENT_ROOT")-1 TSRMLS_CC); - if (fix_pathinfo) { + if (CGIG(fix_pathinfo)) { + char *real_path; + char *orig_path_translated = env_path_translated; + char *orig_path_info = env_path_info; + char *orig_script_name = env_script_name; + char *orig_script_filename = env_script_filename; - /* save the originals first for anything we change later */ - if (env_path_translated) { - _sapi_cgibin_putenv("ORIG_PATH_TRANSLATED", env_path_translated TSRMLS_CC); - } - if (env_path_info) { - _sapi_cgibin_putenv("ORIG_PATH_INFO", env_path_info TSRMLS_CC); - } - if (env_script_name) { - _sapi_cgibin_putenv("ORIG_SCRIPT_NAME", env_script_name TSRMLS_CC); - } - if (env_script_filename) { - _sapi_cgibin_putenv("ORIG_SCRIPT_FILENAME", env_script_filename TSRMLS_CC); - } - if (!env_document_root) { - /* ini version of 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) { - env_document_root = _sapi_cgibin_putenv("DOCUMENT_ROOT", env_document_root TSRMLS_CC); - /* fix docroot */ - TRANSLATE_SLASHES(env_document_root); - } - } + if (!env_document_root && PG(doc_root)) { + env_document_root = _sapi_cgibin_putenv("DOCUMENT_ROOT", PG(doc_root) TSRMLS_CC); + /* fix docroot */ + TRANSLATE_SLASHES(env_document_root); + } if (env_path_translated != NULL && env_redirect_url != NULL) { /* @@ -774,7 +777,7 @@ static void init_request_info(TSRMLS_D) */ script_path_translated = env_path_translated; /* we correct SCRIPT_NAME now in case we don't have PATH_INFO */ - env_script_name = _sapi_cgibin_putenv("SCRIPT_NAME", env_redirect_url TSRMLS_CC); + env_script_name = env_redirect_url; } #ifdef __riscos__ @@ -788,7 +791,8 @@ static void init_request_info(TSRMLS_D) * of it by stat'ing back through the '/' * this fixes url's like /info.php/test */ - if (script_path_translated && stat(script_path_translated, &st) == -1 ) { + if (script_path_translated && + (real_path = tsrm_realpath(script_path_translated, NULL TSRMLS_CC)) == NULL) { char *pt = estrdup(script_path_translated); int len = strlen(pt); char *ptr; @@ -815,8 +819,19 @@ static void init_request_info(TSRMLS_D) int pilen = strlen(env_path_info); char *path_info = env_path_info + pilen - slen; - env_path_info = _sapi_cgibin_putenv("PATH_INFO", path_info TSRMLS_CC); - script_path_translated = _sapi_cgibin_putenv("SCRIPT_FILENAME", pt TSRMLS_CC); + if (orig_path_info != path_info) { + if (orig_path_info) { + _sapi_cgibin_putenv("ORIG_PATH_INFO", orig_path_info TSRMLS_CC); + } + env_path_info = _sapi_cgibin_putenv("PATH_INFO", path_info TSRMLS_CC); + } + if (!orig_script_filename || + strcmp(orig_script_filename, pt) != 0) { + if (orig_script_filename) { + _sapi_cgibin_putenv("ORIG_SCRIPT_FILENAME", orig_script_filename TSRMLS_CC); + } + script_path_translated = _sapi_cgibin_putenv("SCRIPT_FILENAME", pt TSRMLS_CC); + } TRANSLATE_SLASHES(pt); /* figure out docroot @@ -829,7 +844,7 @@ static void init_request_info(TSRMLS_D) int path_translated_len = 0; char *path_translated = NULL; - if (env_document_root[l - 1] == '/') { + if (l && env_document_root[l - 1] == '/') { --l; } @@ -839,14 +854,17 @@ static void init_request_info(TSRMLS_D) * * SCRIPT_NAME is the portion of the path beyond docroot */ - env_script_name = _sapi_cgibin_putenv("SCRIPT_NAME", pt + l TSRMLS_CC); + env_script_name = pt + l; /* PATH_TRANSATED = DOCUMENT_ROOT + PATH_INFO */ - path_translated_len = l + strlen(env_path_info) + 2; - path_translated = (char *) emalloc(path_translated_len); - *path_translated = 0; - strncat(path_translated, env_document_root, l); - strcat(path_translated, env_path_info); + path_translated_len = l + strlen(env_path_info); + path_translated = (char *) emalloc(path_translated_len + 1); + memcpy(path_translated, env_document_root, l); + memcpy(path_translated + l, env_path_info, (path_translated_len - l)); + path_translated[path_translated_len] = '\0'; + if (orig_path_translated) { + _sapi_cgibin_putenv("ORIG_PATH_TRANSLATED", orig_path_translated TSRMLS_CC); + } env_path_translated = _sapi_cgibin_putenv("PATH_TRANSLATED", path_translated TSRMLS_CC); efree(path_translated); } else if (env_script_name && @@ -854,13 +872,16 @@ static void init_request_info(TSRMLS_D) ) { /* PATH_TRANSATED = PATH_TRANSATED - SCRIPT_NAME + PATH_INFO */ int ptlen = strlen(pt) - strlen(env_script_name); - int path_translated_len = ptlen + strlen(env_path_info) + 2; + int path_translated_len = ptlen + strlen(env_path_info); char *path_translated = NULL; - path_translated = (char *) emalloc(path_translated_len); - *path_translated = 0; - strncat(path_translated, pt, ptlen); - strcat(path_translated, env_path_info); + path_translated = (char *) emalloc(path_translated_len + 1); + memcpy(path_translated, pt, ptlen); + memcpy(path_translated + ptlen, env_path_info, path_translated_len - ptlen); + path_translated[path_translated_len] = '\0'; + if (orig_path_translated) { + _sapi_cgibin_putenv("ORIG_PATH_TRANSLATED", orig_path_translated TSRMLS_CC); + } env_path_translated = _sapi_cgibin_putenv("PATH_TRANSLATED", path_translated TSRMLS_CC); efree(path_translated); } @@ -873,19 +894,52 @@ static void init_request_info(TSRMLS_D) * a valid path... we will fail, badly. of course we would * have failed anyway... we output 'no input file' now. */ + if (orig_script_filename) { + _sapi_cgibin_putenv("ORIG_SCRIPT_FILENAME", orig_script_filename TSRMLS_CC); + } script_path_translated = _sapi_cgibin_putenv("SCRIPT_FILENAME", NULL TSRMLS_CC); SG(sapi_headers).http_response_code = 404; } + if (!orig_script_name || + strcmp(orig_script_name, env_script_name) != 0) { + if (orig_script_name) { + _sapi_cgibin_putenv("ORIG_SCRIPT_NAME", orig_script_name TSRMLS_CC); + } + SG(request_info).request_uri = _sapi_cgibin_putenv("SCRIPT_NAME", env_script_name TSRMLS_CC); + } else { + SG(request_info).request_uri = orig_script_name; + } if (pt) { efree(pt); } } 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); - } - SG(request_info).request_uri = sapi_cgibin_getenv("SCRIPT_NAME", sizeof("SCRIPT_NAME")-1 TSRMLS_CC); + if (!orig_script_filename || + (script_path_translated != orig_script_filename) || + strcmp(script_path_translated, orig_script_filename) != 0) { + if (orig_script_filename) { + _sapi_cgibin_putenv("ORIG_SCRIPT_FILENAME", orig_script_filename TSRMLS_CC); + } + script_path_translated = _sapi_cgibin_putenv("SCRIPT_FILENAME", script_path_translated TSRMLS_CC); + } + if (orig_path_info) { + _sapi_cgibin_putenv("ORIG_PATH_INFO", orig_path_info TSRMLS_CC); + _sapi_cgibin_putenv("PATH_INFO", NULL TSRMLS_CC); + } + if (orig_path_translated) { + _sapi_cgibin_putenv("ORIG_PATH_TRANSLATED", orig_path_translated TSRMLS_CC); + _sapi_cgibin_putenv("PATH_TRANSLATED", NULL TSRMLS_CC); + } + if (env_script_name != orig_script_name) { + if (orig_script_name) { + _sapi_cgibin_putenv("ORIG_SCRIPT_NAME", orig_script_name TSRMLS_CC); + } + SG(request_info).request_uri = _sapi_cgibin_putenv("SCRIPT_NAME", env_script_name TSRMLS_CC); + } else { + SG(request_info).request_uri = env_script_name; + } + } + free(real_path); } else { #endif /* pre 4.3 behaviour, shouldn't be used but provides BC */ @@ -941,20 +995,95 @@ void fastcgi_cleanup(int signal) } #endif +PHP_INI_BEGIN() + STD_PHP_INI_ENTRY("cgi.rfc2616_headers", "0", PHP_INI_ALL, OnUpdateBool, rfc2616_headers, php_cgi_globals_struct, php_cgi_globals) + STD_PHP_INI_ENTRY("cgi.nph", "0", PHP_INI_ALL, OnUpdateBool, nph, php_cgi_globals_struct, php_cgi_globals) + STD_PHP_INI_ENTRY("cgi.check_shebang_line", "1", PHP_INI_SYSTEM, OnUpdateBool, check_shebang_line, php_cgi_globals_struct, php_cgi_globals) +#if FORCE_CGI_REDIRECT + STD_PHP_INI_ENTRY("cgi.force_redirect", "1", PHP_INI_SYSTEM, OnUpdateBool, force_redirect, php_cgi_globals_struct, php_cgi_globals) + STD_PHP_INI_ENTRY("cgi.redirect_status_env", NULL, PHP_INI_SYSTEM, OnUpdateString, redirect_status_env, php_cgi_globals_struct, php_cgi_globals) +#endif +#if ENABLE_PATHINFO_CHECK + STD_PHP_INI_ENTRY("cgi.fix_pathinfo", "1", PHP_INI_SYSTEM, OnUpdateBool, fix_pathinfo, php_cgi_globals_struct, php_cgi_globals) +#endif #if PHP_FASTCGI -#ifndef PHP_WIN32 -static int is_port_number(const char *bindpath) + STD_PHP_INI_ENTRY("fastcgi.logging", "1", PHP_INI_SYSTEM, OnUpdateBool, fcgi_logging, php_cgi_globals_struct, php_cgi_globals) +# ifdef PHP_WIN32 + STD_PHP_INI_ENTRY("fastcgi.impersonate", "0", PHP_INI_SYSTEM, OnUpdateBool, impersonate, php_cgi_globals_struct, php_cgi_globals) +# endif +#endif +PHP_INI_END() + +/* {{{ php_cgi_globals_ctor + */ +static void php_cgi_globals_ctor(php_cgi_globals_struct *php_cgi_globals TSRMLS_DC) { - while (*bindpath) { - if (*bindpath < '0' || *bindpath > '9') { - return 0; - } - bindpath++; - } - return 1; -} + php_cgi_globals->rfc2616_headers = 0; + php_cgi_globals->nph = 0; + php_cgi_globals->check_shebang_line = 1; +#if FORCE_CGI_REDIRECT + php_cgi_globals->force_redirect = 1; + php_cgi_globals->redirect_status_env = NULL; +#endif +#if ENABLE_PATHINFO_CHECK + php_cgi_globals->fix_pathinfo = 1; #endif +#if PHP_FASTCGI + php_cgi_globals->fcgi_logging = 1; +# ifdef PHP_WIN32 + php_cgi_globals->impersonate = 0; +# endif +#endif +} +/* }}} */ + +/* {{{ PHP_MINIT_FUNCTION + */ +static PHP_MINIT_FUNCTION(cgi) +{ +#ifdef ZTS + ts_allocate_id(&php_cgi_globals_id, sizeof(php_cgi_globals_struct), (ts_allocate_ctor) php_cgi_globals_ctor, NULL); +#else + php_cgi_globals_ctor(&php_cgi_globals TSRMLS_CC); #endif + REGISTER_INI_ENTRIES(); + return SUCCESS; +} +/* }}} */ + +/* {{{ PHP_MSHUTDOWN_FUNCTION + */ +static PHP_MSHUTDOWN_FUNCTION(cgi) +{ + UNREGISTER_INI_ENTRIES(); + return SUCCESS; +} +/* }}} */ + +/* {{{ PHP_MINFO_FUNCTION + */ +static PHP_MINFO_FUNCTION(cgi) +{ + DISPLAY_INI_ENTRIES(); +} +/* }}} */ + +static zend_module_entry cgi_module_entry = { + STANDARD_MODULE_HEADER, +#if PHP_FASTCGI + "cgi-fcgi", +#else + "cgi", +#endif + NULL, + PHP_MINIT(cgi), + PHP_MSHUTDOWN(cgi), + NULL, + NULL, + PHP_MINFO(cgi), + NO_VERSION_YET, + STANDARD_MODULE_PROPERTIES +}; /* {{{ main */ @@ -973,10 +1102,6 @@ int main(int argc, char *argv[]) char *orig_optarg = php_optarg; char *script_file = NULL; int ini_entries_len = 0; -#if FORCE_CGI_REDIRECT - long force_redirect = 1; - char *redirect_status_env = NULL; -#endif /* end of temporary locals */ #ifdef ZTS @@ -991,14 +1116,10 @@ int main(int argc, char *argv[]) int max_requests = 500; int requests = 0; int fastcgi = fcgi_is_fastcgi(); -#ifndef PHP_WIN32 char *bindpath = NULL; -#endif int fcgi_fd = 0; fcgi_request request; -#ifdef PHP_WIN32 - long impersonate = 0; -#else +#ifndef PHP_WIN32 int status = 0; #endif #endif /* PHP_FASTCGI */ @@ -1030,6 +1151,7 @@ int main(int argc, char *argv[]) #endif sapi_startup(&cgi_sapi_module); + cgi_sapi_module.php_ini_path_override = NULL; #ifdef PHP_WIN32 _fmode = _O_BINARY; /* sets default for file streams to binary */ @@ -1057,6 +1179,9 @@ int main(int argc, char *argv[]) while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0)) != -1) { switch (c) { case 'c': + if (cgi_sapi_module.php_ini_path_override) { + free(cgi_sapi_module.php_ini_path_override); + } cgi_sapi_module.php_ini_path_override = strdup(php_optarg); break; case 'n': @@ -1094,7 +1219,6 @@ int main(int argc, char *argv[]) break; } #if PHP_FASTCGI -#ifndef PHP_WIN32 /* if we're started on command line, check to see if we are being started as an 'external' fastcgi server by accepting a bindpath parameter. */ @@ -1104,7 +1228,10 @@ int main(int argc, char *argv[]) } break; #endif -#endif + case 's': /* generate highlighted HTML from source */ + behavior = PHP_MODE_HIGHLIGHT; + break; + } } @@ -1123,7 +1250,7 @@ int main(int argc, char *argv[]) cgi_sapi_module.executable_location = argv[0]; /* startup after we get the above ini override se we get things right */ - if (php_module_startup(&cgi_sapi_module, NULL, 0) == FAILURE) { + if (cgi_sapi_module.startup(&cgi_sapi_module) == FAILURE) { #ifdef ZTS tsrm_shutdown(); #endif @@ -1132,13 +1259,7 @@ int main(int argc, char *argv[]) #if FORCE_CGI_REDIRECT /* check force_cgi after startup, so we have proper output */ - if (cfg_get_long("cgi.force_redirect", &force_redirect) == FAILURE) { - force_redirect = 1; - } - if (cgi && force_redirect) { - if (cfg_get_string("cgi.redirect_status_env", &redirect_status_env) == FAILURE) { - redirect_status_env = NULL; - } + if (cgi && CGIG(force_redirect)) { /* Apache will generate REDIRECT_STATUS, * Netscape and redirect.so will generate HTTP_REDIRECT_STATUS. * redirect.so and installation instructions available from @@ -1149,7 +1270,7 @@ int main(int argc, char *argv[]) && !getenv ("HTTP_REDIRECT_STATUS") /* this is to allow a different env var to be configured in case some server does something different than above */ - && (!redirect_status_env || !getenv(redirect_status_env)) + && (!CGIG(redirect_status_env) || !getenv(CGIG(redirect_status_env))) ) { SG(sapi_headers).http_response_code = 400; PUTS("<b>Security Alert!</b> The PHP CGI cannot be accessed directly.\n\n\ @@ -1176,52 +1297,11 @@ consult the installation file that came with this distribution, or visit \n\ } #endif /* FORCE_CGI_REDIRECT */ -#if ENABLE_PATHINFO_CHECK - if (cfg_get_long("cgi.fix_pathinfo", &fix_pathinfo) == FAILURE) { - fix_pathinfo = 1; - } -#endif - -#if PHP_FASTCGI - if (cfg_get_long("fastcgi.logging", &fcgi_logging) == FAILURE) { - fcgi_logging = 1; - } -#endif - - /* Check wheater to send RFC2616 style headers compatible with - * PHP versions 4.2.3 and earlier compatible with web servers - * such as IIS. Default is informal CGI RFC header compatible - * with Apache. - */ - if (cfg_get_long("cgi.rfc2616_headers", &rfc2616_headers) == FAILURE) { - rfc2616_headers = 0; - } - - if (cfg_get_long("cgi.nph", &cgi_nph) == FAILURE) { - cgi_nph = 0; - } - #if PHP_FASTCGI -#ifndef PHP_WIN32 /* for windows, socket listening is broken in the fastcgi library itself so dissabling this feature on windows till time is available to fix it */ if (bindpath) { - /* Pass on the arg to the FastCGI library, with one exception. - * If just a port is specified, then we prepend a ':' onto the - * path (it's what the fastcgi library expects) - */ - if (strchr(bindpath, ':') == NULL && is_port_number(bindpath)) { - char *tmp; - - tmp = malloc(strlen(bindpath) + 2); - tmp[0] = ':'; - memcpy(tmp + 1, bindpath, strlen(bindpath) + 1); - - fcgi_fd = fcgi_listen(tmp, 128); - free(tmp); - } else { - fcgi_fd = fcgi_listen(bindpath, 128); - } + fcgi_fd = fcgi_listen(bindpath, 128); if (fcgi_fd < 0) { fprintf(stderr, "Couldn't create FastCGI listen socket on port %s\n", bindpath); #ifdef ZTS @@ -1231,7 +1311,7 @@ consult the installation file that came with this distribution, or visit \n\ } fastcgi = fcgi_is_fastcgi(); } -#endif + if (fastcgi) { /* How many times to run PHP scripts before dying */ if (getenv("PHP_FCGI_MAX_REQUESTS")) { @@ -1280,6 +1360,10 @@ consult the installation file that came with this distribution, or visit \n\ exit(1); } + if (fcgi_in_shutdown()) { + exit(0); + } + while (parent) { do { #ifdef DEBUG_FASTCGI @@ -1351,11 +1435,8 @@ consult the installation file that came with this distribution, or visit \n\ #ifdef PHP_WIN32 /* attempt to set security impersonation for fastcgi will only happen on NT based OS, others will ignore it. */ - if (fastcgi) { - if (cfg_get_long("fastcgi.impersonate", &impersonate) == FAILURE) { - impersonate = 0; - } - if (impersonate) fcgi_impersonate(); + if (fastcgi && CGIG(impersonate)) { + fcgi_impersonate(); } #endif while (!fastcgi || fcgi_accept_request(&request) >= 0) { @@ -1401,6 +1482,9 @@ consult the installation file that came with this distribution, or visit \n\ break; case 'f': /* parse file */ + if (script_file) { + efree(script_file); + } script_file = estrdup(php_optarg); no_headers = 1; /* arguments after the file are considered script args */ @@ -1410,6 +1494,7 @@ consult the installation file that came with this distribution, or visit \n\ case 'i': /* php info & quit */ if (php_request_startup(TSRMLS_C) == FAILURE) { + SG(server_context) = NULL; php_module_shutdown(TSRMLS_C); return FAILURE; } @@ -1450,13 +1535,10 @@ consult the installation file that came with this distribution, or visit \n\ no_headers = 1; break; - case 's': /* generate highlighted HTML from source */ - behavior = PHP_MODE_HIGHLIGHT; - break; - case 'v': /* show php version & quit */ no_headers = 1; if (php_request_startup(TSRMLS_C) == FAILURE) { + SG(server_context) = NULL; php_module_shutdown(TSRMLS_C); return FAILURE; } @@ -1465,9 +1547,9 @@ consult the installation file that came with this distribution, or visit \n\ SG(request_info).no_headers = 1; } #if ZEND_DEBUG - php_printf("PHP %s (%s) (built: %s %s) (DEBUG)\nCopyright (c) 1997-2006 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version()); + php_printf("PHP %s (%s) (built: %s %s) (DEBUG)\nCopyright (c) 1997-2007 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version()); #else - php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) 1997-2006 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version()); + php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) 1997-2007 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version()); #endif php_end_ob_buffers(1 TSRMLS_CC); exit(0); @@ -1515,17 +1597,23 @@ consult the installation file that came with this distribution, or visit \n\ test.php v1=test "v2=hello world!" */ if (!SG(request_info).query_string && argc > php_optind) { + int slen = strlen(PG(arg_separator).input); len = 0; for (i = php_optind; i < argc; i++) { - len += strlen(argv[i]) + 1; + if (i < (argc - 1)) { + len += strlen(argv[i]) + slen; + } else { + len += strlen(argv[i]); + } } - s = malloc(len + 1); + len += 2; + s = malloc(len); *s = '\0'; /* we are pretending it came from the environment */ - for (i = php_optind, len = 0; i < argc; i++) { - strcat(s, argv[i]); + for (i = php_optind; i < argc; i++) { + strlcat(s, argv[i], len); if (i < (argc - 1)) { - strcat(s, PG(arg_separator).input); + strlcat(s, PG(arg_separator).input, len); } } SG(request_info).query_string = s; @@ -1564,6 +1652,7 @@ consult the installation file that came with this distribution, or visit \n\ fcgi_finish_request(&request); } #endif + SG(server_context) = NULL; php_module_shutdown(TSRMLS_C); return FAILURE; } @@ -1577,6 +1666,7 @@ consult the installation file that came with this distribution, or visit \n\ 1. we are running from shell and got filename was there 2. we are running as cgi or fastcgi */ + retval = FAILURE; if (cgi || SG(request_info).path_translated) { retval = php_fopen_primary_script(&file_handle TSRMLS_CC); } @@ -1585,8 +1675,13 @@ consult the installation file that came with this distribution, or visit \n\ running from shell (so fp == NULL), then fail. */ if (retval == FAILURE && file_handle.handle.fp == NULL) { - SG(sapi_headers).http_response_code = 404; - PUTS("No input file specified.\n"); + if (errno == EACCES) { + SG(sapi_headers).http_response_code = 403; + PUTS("Access denied.\n"); + } else { + SG(sapi_headers).http_response_code = 404; + PUTS("No input file specified.\n"); + } #if PHP_FASTCGI /* we want to serve more requests if this is fastcgi so cleanup and continue, request shutdown is @@ -1596,11 +1691,12 @@ consult the installation file that came with this distribution, or visit \n\ } #endif php_request_shutdown((void *) 0); + SG(server_context) = NULL; php_module_shutdown(TSRMLS_C); return FAILURE; } - if (file_handle.handle.fp && (file_handle.handle.fp != stdin)) { + if (CGIG(check_shebang_line) && file_handle.handle.fp && (file_handle.handle.fp != stdin)) { /* #!php support */ c = fgetc(file_handle.handle.fp); if (c == '#') { @@ -1648,6 +1744,11 @@ consult the installation file that came with this distribution, or visit \n\ if (open_file_for_scanning(&file_handle TSRMLS_CC) == SUCCESS) { php_get_highlight_struct(&syntax_highlighter_ini); zend_highlight(&syntax_highlighter_ini TSRMLS_CC); +#if PHP_FASTCGI + if (fastcgi) { + goto fastcgi_request_done; + } +#endif fclose(file_handle.handle.fp); php_end_ob_buffers(1 TSRMLS_CC); } @@ -1702,11 +1803,9 @@ fastcgi_request_done: requests++; if (max_requests && (requests == max_requests)) { fcgi_finish_request(&request); -#ifndef PHP_WIN32 if (bindpath) { free(bindpath); } -#endif break; } /* end of fastcgi loop */ diff --git a/sapi/cgi/config9.m4 b/sapi/cgi/config9.m4 index f4f3ffe13..fd933576d 100644 --- a/sapi/cgi/config9.m4 +++ b/sapi/cgi/config9.m4 @@ -1,5 +1,5 @@ dnl -dnl $Id: config9.m4,v 1.17.2.2.2.1 2006/09/28 09:37:52 dmitry Exp $ +dnl $Id: config9.m4,v 1.17.2.2.2.2 2007/02/20 20:11:11 tony2001 Exp $ dnl AC_ARG_ENABLE(cgi, @@ -50,36 +50,6 @@ AC_ARG_ENABLE(path-info-check, PHP_ENABLE_PATHINFO_CHECK=yes ]) -AC_DEFUN([PHP_TEST_WRITE_STDOUT],[ - AC_CACHE_CHECK(whether writing to stdout works,ac_cv_write_stdout,[ - AC_TRY_RUN([ -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif - -#define TEXT "This is the test message -- " - -main() -{ - int n; - - n = write(1, TEXT, sizeof(TEXT)-1); - return (!(n == sizeof(TEXT)-1)); -} - ],[ - ac_cv_write_stdout=yes - ],[ - ac_cv_write_stdout=no - ],[ - ac_cv_write_stdout=no - ]) - ]) - if test "$ac_cv_write_stdout" = "yes"; then - AC_DEFINE(PHP_WRITE_STDOUT, 1, [whether write(2) works]) - fi -]) - - if test "$PHP_SAPI" = "default"; then AC_MSG_CHECKING(for CGI build) if test "$PHP_SAPI_CGI" != "no"; then @@ -96,8 +66,6 @@ if test "$PHP_SAPI" = "default"; then esac PHP_SUBST(SAPI_CGI_PATH) - PHP_TEST_WRITE_STDOUT - AC_MSG_CHECKING(whether to force Apache CGI redirect) if test "$PHP_FORCE_CGI_REDIRECT" = "yes"; then REDIRECT=1 diff --git a/sapi/cgi/fastcgi.c b/sapi/cgi/fastcgi.c index 6f528109f..7fd1fa86b 100644 --- a/sapi/cgi/fastcgi.c +++ b/sapi/cgi/fastcgi.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: fastcgi.c,v 1.4.2.13.2.11 2006/10/16 10:46:59 dmitry Exp $ */ +/* $Id: fastcgi.c,v 1.4.2.13.2.24 2007/04/09 15:39:59 dmitry Exp $ */ #include "php.h" #include "fastcgi.h" @@ -31,7 +31,7 @@ #include <windows.h> - typedef unsigned int size_t; + typedef unsigned int in_addr_t; struct sockaddr_un { short sun_family; @@ -71,6 +71,15 @@ # include <netdb.h> # include <signal.h> +# define closesocket(s) close(s) + +# if defined(HAVE_SYS_POLL_H) && defined(HAVE_POLL) +# include <sys/poll.h> +# endif +# if defined(HAVE_SYS_SELECT_H) +# include <sys/select.h> +# endif + #ifndef INADDR_NONE #define INADDR_NONE ((unsigned long) -1) #endif @@ -126,7 +135,7 @@ typedef union _sa_t { typedef struct _fcgi_mgmt_rec { char* name; - size_t name_len; + char name_len; char val; } fcgi_mgmt_rec; @@ -140,6 +149,7 @@ static const fcgi_mgmt_rec fcgi_mgmt_vars[] = { static int is_initialized = 0; static int is_fastcgi = 0; static int in_shutdown = 0; +static in_addr_t *allowed_clients = NULL; #ifdef _WIN32 @@ -162,6 +172,11 @@ static void fcgi_signal_handler(int signo) #endif +int fcgi_in_shutdown(void) +{ + return in_shutdown; +} + int fcgi_init(void) { if (!is_initialized) { @@ -240,12 +255,89 @@ int fcgi_is_fastcgi(void) } } +#ifdef _WIN32 +/* Do some black magic with the NT security API. + * We prepare a DACL (Discretionary Access Control List) so that + * we, the creator, are allowed all access, while "Everyone Else" + * is only allowed to read and write to the pipe. + * This avoids security issues on shared hosts where a luser messes + * with the lower-level pipe settings and screws up the FastCGI service. + */ +static PACL prepare_named_pipe_acl(PSECURITY_DESCRIPTOR sd, LPSECURITY_ATTRIBUTES sa) +{ + DWORD req_acl_size; + char everyone_buf[32], owner_buf[32]; + PSID sid_everyone, sid_owner; + SID_IDENTIFIER_AUTHORITY + siaWorld = SECURITY_WORLD_SID_AUTHORITY, + siaCreator = SECURITY_CREATOR_SID_AUTHORITY; + PACL acl; + + sid_everyone = (PSID)&everyone_buf; + sid_owner = (PSID)&owner_buf; + + req_acl_size = sizeof(ACL) + + (2 * ((sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD)) + GetSidLengthRequired(1))); + + acl = malloc(req_acl_size); + + if (acl == NULL) { + return NULL; + } + + if (!InitializeSid(sid_everyone, &siaWorld, 1)) { + goto out_fail; + } + *GetSidSubAuthority(sid_everyone, 0) = SECURITY_WORLD_RID; + + if (!InitializeSid(sid_owner, &siaCreator, 1)) { + goto out_fail; + } + *GetSidSubAuthority(sid_owner, 0) = SECURITY_CREATOR_OWNER_RID; + + if (!InitializeAcl(acl, req_acl_size, ACL_REVISION)) { + goto out_fail; + } + + if (!AddAccessAllowedAce(acl, ACL_REVISION, FILE_GENERIC_READ | FILE_GENERIC_WRITE, sid_everyone)) { + goto out_fail; + } + + if (!AddAccessAllowedAce(acl, ACL_REVISION, FILE_ALL_ACCESS, sid_owner)) { + goto out_fail; + } + + if (!InitializeSecurityDescriptor(sd, SECURITY_DESCRIPTOR_REVISION)) { + goto out_fail; + } + + if (!SetSecurityDescriptorDacl(sd, TRUE, acl, FALSE)) { + goto out_fail; + } + + sa->lpSecurityDescriptor = sd; + + return acl; + +out_fail: + free(acl); + return NULL; +} +#endif + +static int is_port_number(const char *bindpath) +{ + while (*bindpath) { + if (*bindpath < '0' || *bindpath > '9') { + return 0; + } + bindpath++; + } + return 1; +} + int fcgi_listen(const char *path, int backlog) { -#ifdef _WIN32 - /* TODO: Support for manual binding on TCP sockets (php -b <port>) */ - return -1; -#else char *s; int tcp = 0; char host[MAXPATHLEN]; @@ -261,6 +353,12 @@ int fcgi_listen(const char *path, int backlog) host[s-path] = '\0'; tcp = 1; } + } else if (is_port_number(path)) { + port = atoi(path); + if (port != 0) { + host[0] = '\0'; + tcp = 1; + } } /* Prepare socket address */ @@ -289,6 +387,33 @@ int fcgi_listen(const char *path, int backlog) } } } else { +#ifdef _WIN32 + SECURITY_DESCRIPTOR sd; + SECURITY_ATTRIBUTES sa; + PACL acl; + HANDLE namedPipe; + + memset(&sa, 0, sizeof(sa)); + sa.nLength = sizeof(sa); + sa.bInheritHandle = FALSE; + acl = prepare_named_pipe_acl(&sd, &sa); + + namedPipe = CreateNamedPipe(path, + PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, + PIPE_TYPE_BYTE | PIPE_WAIT | PIPE_READMODE_BYTE, + PIPE_UNLIMITED_INSTANCES, + 8192, 8192, 0, &sa); + if (namedPipe == INVALID_HANDLE_VALUE) { + return -1; + } + listen_socket = _open_osfhandle((long)namedPipe, 0); + if (!is_initialized) { + fcgi_init(); + } + is_fastcgi = 1; + return listen_socket; + +#else int path_len = strlen(path); if (path_len >= sizeof(sa.sa_unix.sun_path)) { @@ -304,6 +429,7 @@ int fcgi_listen(const char *path, int backlog) sa.sa_unix.sun_len = sock_len; #endif unlink(path); +#endif } /* Create, bind socket and start listen on it */ @@ -317,14 +443,51 @@ int fcgi_listen(const char *path, int backlog) if (!tcp) { chmod(path, 0777); + } else { + char *ip = getenv("FCGI_WEB_SERVER_ADDRS"); + char *cur, *end; + int n; + + if (ip) { + ip = strdup(ip); + cur = ip; + n = 0; + while (*cur) { + if (*cur == ',') n++; + cur++; + } + allowed_clients = malloc(sizeof(in_addr_t) * (n+2)); + n = 0; + cur = ip; + while (cur) { + end = strchr(cur, ','); + if (end) { + *end = 0; + end++; + } + allowed_clients[n] = inet_addr(cur); + if (allowed_clients[n] == INADDR_NONE) { + fprintf(stderr, "Wrong IP address '%s' in FCGI_WEB_SERVER_ADDRS\n", cur); + } + n++; + cur = end; + } + allowed_clients[n] = INADDR_NONE; + free(ip); + } } if (!is_initialized) { fcgi_init(); } is_fastcgi = 1; - return listen_socket; + +#ifdef _WIN32 + if (tcp) { + listen_socket = _open_osfhandle((long)listen_socket, 0); + } #endif + return listen_socket; } void fcgi_init_request(fcgi_request *req, int listen_socket) @@ -339,6 +502,10 @@ void fcgi_init_request(fcgi_request *req, int listen_socket) req->out_hdr = NULL; req->out_pos = req->out_buf; + +#ifdef _WIN32 + req->tcp = !GetNamedPipeInfo((HANDLE)_get_osfhandle(req->listen_socket), NULL, NULL, NULL, NULL); +#endif } static inline ssize_t safe_write(fcgi_request *req, const void *buf, size_t count) @@ -347,7 +514,19 @@ static inline ssize_t safe_write(fcgi_request *req, const void *buf, size_t coun size_t n = 0; do { + errno = 0; +#ifdef _WIN32 + if (!req->tcp) { + ret = write(req->fd, ((char*)buf)+n, count-n); + } else { + ret = send(req->fd, ((char*)buf)+n, count-n, 0); + if (ret <= 0) { + errno = WSAGetLastError(); + } + } +#else ret = write(req->fd, ((char*)buf)+n, count-n); +#endif if (ret > 0) { n += ret; } else if (ret <= 0 && errno != 0 && errno != EINTR) { @@ -363,7 +542,19 @@ static inline ssize_t safe_read(fcgi_request *req, const void *buf, size_t count size_t n = 0; do { + errno = 0; +#ifdef _WIN32 + if (!req->tcp) { + ret = read(req->fd, ((char*)buf)+n, count-n); + } else { + ret = recv(req->fd, ((char*)buf)+n, count-n, 0); + if (ret <= 0) { + errno = WSAGetLastError(); + } + } +#else ret = read(req->fd, ((char*)buf)+n, count-n); +#endif if (ret > 0) { n += ret; } else if (ret == 0 && errno == 0) { @@ -540,8 +731,8 @@ static int fcgi_read_request(fcgi_request *req) for (j = 0; j < sizeof(fcgi_mgmt_vars)/sizeof(fcgi_mgmt_vars[0]); j++) { if (zend_hash_exists(&req->env, fcgi_mgmt_vars[j].name, fcgi_mgmt_vars[j].name_len+1) == 0) { - sprintf((char*)p, "%c%c%s%c", fcgi_mgmt_vars[j].name_len, 1, fcgi_mgmt_vars[j].name, fcgi_mgmt_vars[j].val); - p += fcgi_mgmt_vars[j].name_len + 3; + sprintf((char*)p, "%c%c%s%c", fcgi_mgmt_vars[j].name_len, 1, fcgi_mgmt_vars[j].name, fcgi_mgmt_vars[j].val); + p += fcgi_mgmt_vars[j].name_len + 3; } } len = p - buf - sizeof(fcgi_header); @@ -616,16 +807,30 @@ static inline void fcgi_close(fcgi_request *req, int force, int destroy) if (destroy) { zend_hash_destroy(&req->env); } + +#ifdef _WIN32 + if (is_impersonate && !req->tcp) { + RevertToSelf(); + } +#endif + if ((force || !req->keep) && req->fd >= 0) { #ifdef _WIN32 - HANDLE pipe = (HANDLE)_get_osfhandle(req->fd); + if (!req->tcp) { + HANDLE pipe = (HANDLE)_get_osfhandle(req->fd); - if (!force) { - FlushFileBuffers(pipe); - } - DisconnectNamedPipe(pipe); - if (is_impersonate) { - RevertToSelf(); + if (!force) { + FlushFileBuffers(pipe); + } + DisconnectNamedPipe(pipe); + } else { + if (!force) { + char buf[8]; + + shutdown(req->fd, 1); + while (recv(req->fd, buf, sizeof(buf), 0) > 0) {} + } + closesocket(req->fd); } #else if (!force) { @@ -655,41 +860,57 @@ int fcgi_accept_request(fcgi_request *req) return -1; } #ifdef _WIN32 - pipe = (HANDLE)_get_osfhandle(req->listen_socket); - - FCGI_LOCK(req->listen_socket); - ov.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); - if (!ConnectNamedPipe(pipe, &ov)) { - errno = GetLastError(); - if (errno == ERROR_IO_PENDING) { - while (WaitForSingleObject(ov.hEvent, 1000) == WAIT_TIMEOUT) { - if (in_shutdown) { - CloseHandle(ov.hEvent); - FCGI_UNLOCK(req->listen_socket); - return -1; + if (!req->tcp) { + pipe = (HANDLE)_get_osfhandle(req->listen_socket); + FCGI_LOCK(req->listen_socket); + ov.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + if (!ConnectNamedPipe(pipe, &ov)) { + errno = GetLastError(); + if (errno == ERROR_IO_PENDING) { + while (WaitForSingleObject(ov.hEvent, 1000) == WAIT_TIMEOUT) { + if (in_shutdown) { + CloseHandle(ov.hEvent); + FCGI_UNLOCK(req->listen_socket); + return -1; + } } + } else if (errno != ERROR_PIPE_CONNECTED) { } - } else if (errno != ERROR_PIPE_CONNECTED) { } - } - CloseHandle(ov.hEvent); - if (is_impersonate && !ImpersonateNamedPipeClient(pipe)) { - DisconnectNamedPipe(pipe); - req->fd = -1; - } else { + CloseHandle(ov.hEvent); req->fd = req->listen_socket; - } - FCGI_UNLOCK(req->listen_socket); + FCGI_UNLOCK(req->listen_socket); + } else { + SOCKET listen_socket = (SOCKET)_get_osfhandle(req->listen_socket); #else { + int listen_socket = req->listen_socket; +#endif sa_t sa; socklen_t len = sizeof(sa); FCGI_LOCK(req->listen_socket); - req->fd = accept(req->listen_socket, (struct sockaddr *)&sa, &len); + req->fd = accept(listen_socket, (struct sockaddr *)&sa, &len); FCGI_UNLOCK(req->listen_socket); + if (req->fd >= 0 && allowed_clients) { + int n = 0; + int allowed = 0; + + while (allowed_clients[n] != INADDR_NONE) { + if (allowed_clients[n] == sa.sa_inet.sin_addr.s_addr) { + allowed = 1; + break; + } + n++; + } + if (!allowed) { + fprintf(stderr, "Connection from disallowed IP address '%s' is dropped.\n", inet_ntoa(sa.sa_inet.sin_addr)); + closesocket(req->fd); + req->fd = -1; + continue; + } + } } -#endif if (req->fd < 0 && (in_shutdown || errno != EINTR)) { return -1; @@ -699,18 +920,42 @@ int fcgi_accept_request(fcgi_request *req) break; #else if (req->fd >= 0) { - struct timeval tv = {5,0}; - fd_set set; - - FD_ZERO(&set); - FD_SET(req->fd, &set); -try_again: - errno = 0; - if (select(req->fd + 1, &set, NULL, NULL, &tv) >= 0 && FD_ISSET(req->fd, &set)) { +#if defined(HAVE_SYS_POLL_H) && defined(HAVE_POLL) + struct pollfd fds; + int ret; + + fds.fd = req->fd; + fds.events = POLLIN; + fds.revents = 0; + do { + errno = 0; + ret = poll(&fds, 1, 5000); + } while (ret < 0 && errno == EINTR); + if (ret > 0 && (fds.revents & POLLIN)) { break; } - if (errno == EINTR) goto try_again; fcgi_close(req, 1, 0); +#else + if (req->fd < FD_SETSIZE) { + struct timeval tv = {5,0}; + fd_set set; + int ret; + + FD_ZERO(&set); + FD_SET(req->fd, &set); + do { + errno = 0; + ret = select(req->fd + 1, &set, NULL, NULL, &tv) >= 0; + } while (ret < 0 && errno == EINTR); + if (ret > 0 && FD_ISSET(req->fd, &set)) { + break; + } + fcgi_close(req, 1, 0); + } else { + fprintf(stderr, "Too many open file descriptors. FD_SETSIZE limit exceeded."); + fcgi_close(req, 1, 0); + } +#endif } #endif } @@ -718,6 +963,15 @@ try_again: return -1; } if (fcgi_read_request(req)) { +#ifdef _WIN32 + if (is_impersonate && !req->tcp) { + pipe = (HANDLE)_get_osfhandle(req->fd); + if (!ImpersonateNamedPipeClient(pipe)) { + fcgi_close(req, 1, 1); + continue; + } + } +#endif return req->fd; } else { fcgi_close(req, 1, 1); @@ -908,14 +1162,15 @@ char* fcgi_getenv(fcgi_request *req, const char* var, int var_len) char* fcgi_putenv(fcgi_request *req, char* var, int var_len, char* val) { if (var && req) { - char **ret; - if (val == NULL) { - val = ""; - } - val = strdup(val); - if (zend_hash_update(&req->env, var, var_len+1, &val, sizeof(char*), (void**)&ret) == SUCCESS) { - return *ret; + zend_hash_del(&req->env, var, var_len+1); + } else { + char **ret; + + val = strdup(val); + if (zend_hash_update(&req->env, var, var_len+1, &val, sizeof(char*), (void**)&ret) == SUCCESS) { + return *ret; + } } } return NULL; diff --git a/sapi/cgi/fastcgi.h b/sapi/cgi/fastcgi.h index 5a9fcb9de..43885c26a 100644 --- a/sapi/cgi/fastcgi.h +++ b/sapi/cgi/fastcgi.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: fastcgi.h,v 1.2.2.4.2.1 2006/05/15 14:30:31 dmitry Exp $ */ +/* $Id: fastcgi.h,v 1.2.2.4.2.4 2007/03/28 15:39:22 dmitry Exp $ */ /* FastCGI protocol */ @@ -93,6 +93,9 @@ typedef struct _fcgi_end_request_rec { typedef struct _fcgi_request { int listen_socket; +#ifdef _WIN32 + int tcp; +#endif int fd; int id; int keep; @@ -110,6 +113,7 @@ typedef struct _fcgi_request { int fcgi_init(void); int fcgi_is_fastcgi(void); +int fcgi_in_shutdown(void); int fcgi_listen(const char *path, int backlog); void fcgi_init_request(fcgi_request *req, int listen_socket); int fcgi_accept_request(fcgi_request *req); diff --git a/sapi/cgi/getopt.c b/sapi/cgi/getopt.c index 1c86f1e4e..e2988fbf0 100644 --- a/sapi/cgi/getopt.c +++ b/sapi/cgi/getopt.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,6 +16,8 @@ +----------------------------------------------------------------------+ */ +/* $Id: getopt.c,v 1.9.2.1.2.4 2007/04/23 11:05:16 tony2001 Exp $ */ + #include <stdio.h> #include <string.h> #include <assert.h> @@ -77,29 +79,35 @@ int php_getopt(int argc, char* const *argv, const opt_struct opts[], char **opta } if ((argv[*optind][0] == '-') && (argv[*optind][1] == '-')) { /* '--' indicates end of args if not followed by a known long option name */ + if (argv[*optind][2] == '\0') { + (*optind)++; + return(EOF); + } + while (1) { opts_idx++; if (opts[opts_idx].opt_char == '-') { (*optind)++; - return(EOF); + return(php_opt_error(argc, argv, *optind-1, optchr, OPTERRARG, show_err)); } else if (opts[opts_idx].opt_name && !strcmp(&argv[*optind][2], opts[opts_idx].opt_name)) { break; } } optchr = 0; - dash = 1; - arg_start = 2 + strlen(opts[opts_idx].opt_name); - } - if (!dash) { - dash = 1; - optchr = 1; - } - - /* Check if the guy tries to do a -: kind of flag */ - if (argv[*optind][optchr] == ':') { dash = 0; - (*optind)++; - return (php_opt_error(argc, argv, *optind-1, optchr, OPTERRCOLON, show_err)); + arg_start = 2 + strlen(opts[opts_idx].opt_name); + } else { + if (!dash) { + dash = 1; + optchr = 1; + } + /* Check if the guy tries to do a -: kind of flag */ + if (argv[*optind][optchr] == ':') { + dash = 0; + (*optind)++; + return (php_opt_error(argc, argv, *optind-1, optchr, OPTERRCOLON, show_err)); + } + arg_start = 1 + optchr; } if (opts_idx < 0) { while (1) { @@ -113,6 +121,7 @@ int php_getopt(int argc, char* const *argv, const opt_struct opts[], char **opta (*optind)++; } else { optchr++; + arg_start++; } return(php_opt_error(argc, argv, errind, errchr, OPTERRNF, show_err)); } else if (argv[*optind][optchr] == opts[opts_idx].opt_char) { @@ -136,7 +145,8 @@ int php_getopt(int argc, char* const *argv, const opt_struct opts[], char **opta } return opts[opts_idx].opt_char; } else { - if (arg_start == 2) { + /* multiple options specified as one (exclude long opts) */ + if (arg_start >= 2 && !((argv[*optind][0] == '-') && (argv[*optind][1] == '-'))) { if (!argv[*optind][optchr+1]) { dash = 0; diff --git a/sapi/cgi/php_getopt.h b/sapi/cgi/php_getopt.h index ad10f423b..e040313da 100644 --- a/sapi/cgi/php_getopt.h +++ b/sapi/cgi/php_getopt.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,8 +16,17 @@ +----------------------------------------------------------------------+ */ +/* $Id: php_getopt.h,v 1.7.2.1.2.2 2007/04/15 22:50:58 sniper Exp $ */ + #include "php.h" +#ifdef NETWARE +/* +As NetWare LibC has optind and optarg macros defined in unistd.h our local variables were getting mistakenly preprocessed so undeffing optind and optarg +*/ +#undef optarg +#undef optind +#endif /* Define structure for one recognized option (both single char and long name). * If short_open is '-' this is the last option. */ diff --git a/sapi/cgi/tests/001.phpt b/sapi/cgi/tests/001.phpt new file mode 100644 index 000000000..74c694f7c --- /dev/null +++ b/sapi/cgi/tests/001.phpt @@ -0,0 +1,22 @@ +--TEST-- +version string +--SKIPIF-- +<?php include "skipif.inc"; ?> +--FILE-- +<?php + +include "include.inc"; + +$php = get_cgi_path(); +reset_env_vars(); + +var_dump(`$php -n -v`); + +echo "Done\n"; +?> +--EXPECTF-- +string(%d) "PHP %s (cgi%s (built: %s +Copyright (c) 1997-20%s The PHP Group +Zend Engine v%s, Copyright (c) 1998-20%s Zend Technologies +" +Done diff --git a/sapi/cgi/tests/002.phpt b/sapi/cgi/tests/002.phpt new file mode 100644 index 000000000..66e2424f2 --- /dev/null +++ b/sapi/cgi/tests/002.phpt @@ -0,0 +1,52 @@ +--TEST-- +defining INI options with -d +--SKIPIF-- +<?php +include "skipif.inc"; +?> +--FILE-- +<?php +include "include.inc"; + +$php = get_cgi_path(); +reset_env_vars(); + +$file = dirname(__FILE__)."/002.test.php"; + +file_put_contents($file, '<?php var_dump(ini_get("max_execution_time")); ?>'); + +var_dump(`$php -n -d max_execution_time=111 $file`); +var_dump(`$php -n -d max_execution_time=500 $file`); +var_dump(`$php -n -d max_execution_time=500 -d max_execution_time=555 $file`); + +file_put_contents($file, '<?php var_dump(ini_get("max_execution_time")); var_dump(ini_get("upload_tmp_dir")); ?>'); + +var_dump(`$php -n -d upload_tmp_dir=/test/path -d max_execution_time=555 $file`); + +unlink($file); + +echo "Done\n"; +?> +--EXPECTF-- +string(%d) "X-Powered-By: PHP/%s +Content-type: text/html + +string(3) "111" +" +string(%d) "X-Powered-By: PHP/%s +Content-type: text/html + +string(3) "500" +" +string(%d) "X-Powered-By: PHP/%s +Content-type: text/html + +string(3) "555" +" +string(%d) "X-Powered-By: PHP/%s +Content-type: text/html + +string(3) "555" +string(10) "/test/path" +" +Done diff --git a/sapi/cgi/tests/003.phpt b/sapi/cgi/tests/003.phpt new file mode 100644 index 000000000..0da3ca860 --- /dev/null +++ b/sapi/cgi/tests/003.phpt @@ -0,0 +1,62 @@ +--TEST-- +strip comments and whitespace with -w +--SKIPIF-- +<?php +include "skipif.inc"; +?> +--FILE-- +<?php + +include "include.inc"; + +$php = get_cgi_path(); +reset_env_vars(); + +$filename = dirname(__FILE__).'/003.test.php'; +$code =' +<?php +/* some test script */ + +class test { /* {{{ */ + public $var = "test"; //test var +#perl style comment + private $pri; /* private attr */ + + function foo(/* void */) { + } +} +/* }}} */ + +?> +'; + +file_put_contents($filename, $code); + +var_dump(`$php -n -w "$filename"`); +var_dump(`$php -n -w "wrong"`); +var_dump(`echo "<?php /* comment */ class test {\n // comment \n function foo() {} } ?>" | $php -n -w`); + +@unlink($filename); + +echo "Done\n"; +?> +--EXPECTF-- +string(%d) "X-Powered-By: PHP/%s +Content-type: text/html + + +<?php + class test { public $var = "test"; private $pri; function foo() { } } ?> +" +string(%d) "Status: 404 +X-Powered-By: PHP/%s +Content-type: text/html + +No input file specified. +" +string(%d) "X-Powered-By: PHP/%s +Content-type: text/html + +<?php class test { function foo() {} } ?> +" +Done diff --git a/sapi/cgi/tests/004.phpt b/sapi/cgi/tests/004.phpt new file mode 100644 index 000000000..c841b68e0 --- /dev/null +++ b/sapi/cgi/tests/004.phpt @@ -0,0 +1,43 @@ +--TEST-- +execute a file with -f +--SKIPIF-- +<?php +include "skipif.inc"; +?> +--FILE-- +<?php + +include "include.inc"; + +$php = get_cgi_path(); +reset_env_vars(); + +$filename = dirname(__FILE__).'/004.test.php'; +$code =' +<?php + +class test { + private $pri; +} + +var_dump(test::$pri); +?> +'; + +file_put_contents($filename, $code); + +var_dump(`$php -n -f "$filename" 2>/dev/null`); +var_dump(`$php -n -f "wrong"`); + +@unlink($filename); + +echo "Done\n"; +?> +--EXPECTF-- +string(%d) " +<br /> +<b>Fatal error</b>: Cannot access private property test::$pri in <b>%s004.test.php</b> on line <b>8</b><br /> +" +string(25) "No input file specified. +" +Done diff --git a/sapi/cgi/tests/005.phpt b/sapi/cgi/tests/005.phpt new file mode 100644 index 000000000..6d82b0f31 --- /dev/null +++ b/sapi/cgi/tests/005.phpt @@ -0,0 +1,30 @@ +--TEST-- +using invalid combinations of cmdline options +--SKIPIF-- +<?php include "skipif.inc"; ?> +--FILE-- +<?php + +include "include.inc"; + +$php = get_cgi_path(); +reset_env_vars(); + +var_dump(`$php -n -c -f 'wrong'`); +var_dump(`$php -n -a -f 'wrong'`); +var_dump(`$php -n -f 'wrong' -a`); + +echo "Done\n"; +?> +--EXPECTF-- +string(55) "You cannot use both -n and -c switch. Use -h for help. +" +string(51) "No input file specified. +Interactive mode enabled + +" +string(51) "No input file specified. +Interactive mode enabled + +" +Done diff --git a/sapi/cgi/tests/006.phpt b/sapi/cgi/tests/006.phpt new file mode 100644 index 000000000..107ddc774 --- /dev/null +++ b/sapi/cgi/tests/006.phpt @@ -0,0 +1,60 @@ +--TEST-- +syntax check +--SKIPIF-- +<?php include "skipif.inc"; ?> +--FILE-- +<?php +include "include.inc"; + +$php = get_cgi_path(); +reset_env_vars(); + +$filename = dirname(__FILE__)."/006.test.php"; + +$code = ' +<?php + +$test = "var"; + +class test { + private $var; +} + +echo test::$var; + +?> +'; + +file_put_contents($filename, $code); + +var_dump(`"$php" -n -l "$filename"`); +var_dump(`"$php" -n -l some.unknown`); + +$code = ' +<?php + +class test + private $var; +} + +?> +'; + +file_put_contents($filename, $code); + +var_dump(`"$php" -n -l "$filename" 2>/dev/null`); + +@unlink($filename); + +echo "Done\n"; +?> +--EXPECTF-- +string(%d) "No syntax errors detected in %s006.test.php +" +string(%d) "No input file specified. +" +string(%d) "<br /> +<b>Parse error</b>: %s expecting %s{%s in <b>%s006.test.php</b> on line <b>5</b><br /> +Errors parsing %s006.test.php +" +Done diff --git a/sapi/cgi/tests/007.phpt b/sapi/cgi/tests/007.phpt new file mode 100644 index 000000000..c0f8df1bf --- /dev/null +++ b/sapi/cgi/tests/007.phpt @@ -0,0 +1,22 @@ +--TEST-- +invalid arguments and error messages +--SKIPIF-- +<?php include "skipif.inc"; ?> +--FILE-- +<?php +include "include.inc"; + +$php = get_cgi_path(); +reset_env_vars(); + +var_dump(`"$php" -n -f some.php -f some.php`); +var_dump(`"$php" -s -w -l`); + +echo "Done\n"; +?> +--EXPECTF-- +string(25) "No input file specified. +" +string(31) "No syntax errors detected in - +" +Done diff --git a/sapi/cgi/tests/008.phpt b/sapi/cgi/tests/008.phpt new file mode 100644 index 000000000..d541ca430 --- /dev/null +++ b/sapi/cgi/tests/008.phpt @@ -0,0 +1,54 @@ +--TEST-- +syntax highlighting +--SKIPIF-- +<?php include "skipif.inc"; ?> +--FILE-- +<?php + +include "include.inc"; + +$php = get_cgi_path(); +reset_env_vars(); + +$filename = dirname(__FILE__)."/008.test.php"; +$code = ' +<?php +$test = "var"; //var +/* test class */ +class test { + private $var = array(); + + public static function foo(Test $arg) { + echo "hello"; + var_dump($this); + } +} + +$o = new test; +?> +'; + +file_put_contents($filename, $code); + +var_dump(`"$php" -n -s "$filename"`); +var_dump(`"$php" -n -s "unknown"`); + +@unlink($filename); + +echo "Done\n"; +?> +--EXPECTF-- +string(%d) "X-Powered-By: PHP/%s +Content-type: text/html + +<code><span style="color: #000000"> +<br /><span style="color: #0000BB"><?php<br />$test </span><span style="color: #007700">= </span><span style="color: #DD0000">"var"</span><span style="color: #007700">; </span><span style="color: #FF8000">//var<br />/* test class */<br /></span><span style="color: #007700">class </span><span style="color: #0000BB">test </span><span style="color: #007700">{<br /> private </span><span style="color: #0000BB">$var </span><span style="color: #007700">= array();<br /><br /> public static function </span><span style="color: #0000BB">foo</span><span style="color: #007700">(</span><span style="color: #0000BB">Test $arg</span><span style="color: #007700">) {<br /> echo </span><span style="color: #DD0000">"hello"</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$this</span><span style="color: #007700">);<br /> }<br />}<br /><br /></span><span style="color: #0000BB">$o </span><span style="color: #007700">= new </span><span style="color: #0000BB">test</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?><br /></span> +</span> +</code>" +string(%d) "Status: 404 +X-Powered-By: PHP/%s +Content-type: text/html + +No input file specified. +" +Done diff --git a/sapi/cgi/tests/include.inc b/sapi/cgi/tests/include.inc new file mode 100644 index 000000000..2a8732149 --- /dev/null +++ b/sapi/cgi/tests/include.inc @@ -0,0 +1,57 @@ +<?php + +function get_cgi_path() /* {{{ */ +{ + $php = getenv("TEST_PHP_EXECUTABLE"); + + $cli = false; + $cgi = false; + + if (file_exists($php) && is_executable($php)) { + $version = `$php -v`; + if (strstr($version, "(cli)")) { + /* that's cli */ + $cli = true; + } else if (strpos($version, "(cgi")) { + /* that's cgi */ + return $php; + } + } + + if ($cli) { + /* trying to guess ... */ + $php_path = $php; + for ($i = 0; $i < 2; $i++) { + $slash_pos = strrpos($php_path, "/"); + if ($slash_pos) { + $php_path = substr($php_path, 0, $slash_pos); + } else { + return FALSE; + } + } + + if ($php_path && is_dir($php_path) && file_exists($php_path."/cgi/php") && is_executable($php_path."/cgi/php")) { + /* gotcha */ + return $php_path."/cgi/php"; + } + return false; + } + /* uhm? what's that then? */ + return false; +} +/* }}} */ + +function reset_env_vars() /* {{{ */ +{ + putenv("REDIRECT_STATUS"); + putenv("QUERY_STRING"); + putenv("PATH_TRANSLATED"); + putenv("SCRIPT_FILENAME"); + putenv("SERVER_SOFTWARE"); + putenv("SERVER_NAME"); + putenv("GATEWAY_INTERFACE"); + putenv("REQUEST_METHOD"); +} +/* }}} */ + +?> diff --git a/sapi/cgi/tests/skipif.inc b/sapi/cgi/tests/skipif.inc new file mode 100644 index 000000000..9da8b7934 --- /dev/null +++ b/sapi/cgi/tests/skipif.inc @@ -0,0 +1,17 @@ +<?php + +if (substr(php_sapi_name(), 0, 3) == "cgi") { + exit; +} + +if (substr(PHP_OS, 0, 3) == 'WIN') { + die ("skip not for Windows"); +} + +include dirname(__FILE__)."/include.inc"; + +if (!get_cgi_path()) { + die("skip CGI not found"); +} + +?> diff --git a/sapi/cli/getopt.c b/sapi/cli/getopt.c index 639eb9bb2..fd665d7d3 100644 --- a/sapi/cli/getopt.c +++ b/sapi/cli/getopt.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: getopt.c,v 1.8.2.1 2006/01/01 12:50:19 sniper Exp $ */ +/* $Id: getopt.c,v 1.8.2.1.2.5 2007/04/23 11:05:16 tony2001 Exp $ */ #include <stdio.h> #include <string.h> @@ -79,29 +79,35 @@ int php_getopt(int argc, char* const *argv, const opt_struct opts[], char **opta } if ((argv[*optind][0] == '-') && (argv[*optind][1] == '-')) { /* '--' indicates end of args if not followed by a known long option name */ + if (argv[*optind][2] == '\0') { + (*optind)++; + return(EOF); + } + while (1) { opts_idx++; if (opts[opts_idx].opt_char == '-') { (*optind)++; - return(EOF); + return(php_opt_error(argc, argv, *optind-1, optchr, OPTERRARG, show_err)); } else if (opts[opts_idx].opt_name && !strcmp(&argv[*optind][2], opts[opts_idx].opt_name)) { break; } } optchr = 0; - dash = 1; - arg_start = 2 + strlen(opts[opts_idx].opt_name); - } - if (!dash) { - dash = 1; - optchr = 1; - } - - /* Check if the guy tries to do a -: kind of flag */ - if (argv[*optind][optchr] == ':') { dash = 0; - (*optind)++; - return (php_opt_error(argc, argv, *optind-1, optchr, OPTERRCOLON, show_err)); + arg_start = 2 + strlen(opts[opts_idx].opt_name); + } else { + if (!dash) { + dash = 1; + optchr = 1; + } + /* Check if the guy tries to do a -: kind of flag */ + if (argv[*optind][optchr] == ':') { + dash = 0; + (*optind)++; + return (php_opt_error(argc, argv, *optind-1, optchr, OPTERRCOLON, show_err)); + } + arg_start = 1 + optchr; } if (opts_idx < 0) { while (1) { @@ -115,6 +121,7 @@ int php_getopt(int argc, char* const *argv, const opt_struct opts[], char **opta (*optind)++; } else { optchr++; + arg_start++; } return(php_opt_error(argc, argv, errind, errchr, OPTERRNF, show_err)); } else if (argv[*optind][optchr] == opts[opts_idx].opt_char) { @@ -138,7 +145,8 @@ int php_getopt(int argc, char* const *argv, const opt_struct opts[], char **opta } return opts[opts_idx].opt_char; } else { - if (arg_start == 2) { + /* multiple options specified as one (exclude long opts) */ + if (arg_start >= 2 && !((argv[*optind][0] == '-') && (argv[*optind][1] == '-'))) { if (!argv[*optind][optchr+1]) { dash = 0; diff --git a/sapi/cli/php.1.in b/sapi/cli/php.1.in index 4c86dec40..cb31c832c 100644 --- a/sapi/cli/php.1.in +++ b/sapi/cli/php.1.in @@ -1,4 +1,4 @@ -.TH PHP 1 "2006" "The PHP Group" "Scripting Language" +.TH PHP 1 "2007" "The PHP Group" "Scripting Language" .SH NAME .TP 15 php \- PHP Command Line Interface 'CLI' @@ -294,6 +294,16 @@ Shows information about class .IR name Shows information about extension .B name +.TP +.PD 0 +.B \-\-rextinfo +.IR name +.TP +.PD 1 +.B \-\-ri +.IR name +Shows configuration for extension +.B name .SH FILES .TP 15 .B php\-cli.ini @@ -377,7 +387,7 @@ found at: .SH AUTHORS The PHP Group: Thies C. Arntzen, Stig Bakken, Andi Gutmans, Rasmus Lerdorf, Sam Ruby, Sascha Schumann, Zeev Suraski, Jim Winstead, Andrei Zmievski. .P -Additional work for the CLI sapi was done by Edin Kadribasic and Marcus Boerger. +Additional work for the CLI sapi was done by Edin Kadribasic, Marcus Boerger and Johannes Schlueter. .P A List of active developers can be found here: .PD 0 @@ -390,7 +400,7 @@ contributors all around the world. .SH VERSION INFORMATION This manpage describes \fBphp\fP, version @PHP_VERSION@. .SH COPYRIGHT -Copyright \(co 1997\-2006 The PHP Group +Copyright \(co 1997\-2007 The PHP Group .LP This source file is subject to version 3.01 of the PHP license, that is bundled with this package in the file LICENSE, and is diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c index cb094a07b..e91dbfa2f 100644 --- a/sapi/cli/php_cli.c +++ b/sapi/cli/php_cli.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -20,7 +20,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_cli.c,v 1.129.2.13.2.10 2006/09/22 17:41:09 iliaa Exp $ */ +/* $Id: php_cli.c,v 1.129.2.13.2.18 2007/04/25 09:56:29 bjori Exp $ */ #include "php.h" #include "php_globals.h" @@ -105,16 +105,16 @@ #define PHP_MODE_REFLECTION_FUNCTION 8 #define PHP_MODE_REFLECTION_CLASS 9 #define PHP_MODE_REFLECTION_EXTENSION 10 +#define PHP_MODE_REFLECTION_EXT_INFO 11 #define HARDCODED_INI \ "html_errors=0\n" \ "register_argc_argv=1\n" \ "implicit_flush=1\n" \ "output_buffering=0\n" \ - "max_execution_time=0\n" \ + "max_execution_time=0\n" \ "max_input_time=-1\n" - static char *php_optarg = NULL; static int php_optind = 1; #if (HAVE_LIBREADLINE || HAVE_LIBEDIT) && !defined(COMPILE_DL_READLINE) @@ -153,6 +153,8 @@ static const opt_struct OPTIONS[] = { {11, 1, "rclass"}, {12, 1, "re"}, {12, 1, "rextension"}, + {13, 1, "ri"}, + {13, 1, "rextinfo"}, #endif {'-', 0, NULL} /* end of args */ }; @@ -450,6 +452,7 @@ static void php_cli_usage(char *argv0) " --rf <name> Show information about function <name>.\n" " --rc <name> Show information about class <name>.\n" " --re <name> Show information about extension <name>.\n" + " --ri <name> Show configuration for extension <name>.\n" "\n" #endif , prog, prog, prog, prog, prog, prog); @@ -474,9 +477,21 @@ static void cli_register_file_handles(TSRMLS_D) s_err = php_stream_open_wrapper_ex("php://stderr", "wb", 0, NULL, sc_err); if (s_in==NULL || s_out==NULL || s_err==NULL) { + FREE_ZVAL(zin); + FREE_ZVAL(zout); + FREE_ZVAL(zerr); + if (s_in) php_stream_close(s_in); + if (s_out) php_stream_close(s_out); + if (s_err) php_stream_close(s_err); return; } - + +#if PHP_DEBUG + /* do not close stdout and stderr */ + s_out->flags |= PHP_STREAM_FLAG_NO_CLOSE; + s_err->flags |= PHP_STREAM_FLAG_NO_CLOSE; +#endif + s_in_process = s_in; php_stream_to_zval(s_in, zin); @@ -617,8 +632,8 @@ int main(int argc, char *argv[]) tsrm_startup(1, 1, 0, NULL); #endif - cli_sapi_module.php_ini_path_override = NULL; cli_sapi_module.ini_defaults = sapi_cli_ini_defaults; + cli_sapi_module.php_ini_path_override = NULL; cli_sapi_module.phpinfo_as_text = 1; sapi_startup(&cli_sapi_module); @@ -636,13 +651,16 @@ int main(int argc, char *argv[]) while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0))!=-1) { switch (c) { - case 'c': - cli_sapi_module.php_ini_path_override = strdup(php_optarg); - break; - case 'n': - cli_sapi_module.php_ini_ignore = 1; - break; - case 'd': { + case 'c': + if (cli_sapi_module.php_ini_path_override) { + free(cli_sapi_module.php_ini_path_override); + } + cli_sapi_module.php_ini_path_override = strdup(php_optarg); + break; + case 'n': + cli_sapi_module.php_ini_ignore = 1; + break; + case 'd': { /* define ini entries on command line */ int len = strlen(php_optarg); char *val; @@ -689,7 +707,7 @@ int main(int argc, char *argv[]) #endif /* startup after we get the above ini override se we get things right */ - if (php_module_startup(&cli_sapi_module, NULL, 0)==FAILURE) { + if (cli_sapi_module.startup(&cli_sapi_module)==FAILURE) { /* there is no way to see if we must call zend_ini_deactivate() * since we cannot check if EG(ini_directives) has been initialised * because the executor's constructor does not set initialize it. @@ -754,7 +772,7 @@ int main(int argc, char *argv[]) } request_started = 1; - php_printf("PHP %s (%s) (built: %s %s) %s\nCopyright (c) 1997-2006 The PHP Group\n%s", + php_printf("PHP %s (%s) (built: %s %s) %s\nCopyright (c) 1997-2007 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, #if ZEND_DEBUG && defined(HAVE_GCOV) "(DEBUG GCOV)", @@ -941,6 +959,10 @@ int main(int argc, char *argv[]) behavior=PHP_MODE_REFLECTION_EXTENSION; reflection_what = php_optarg; break; + case 13: + behavior=PHP_MODE_REFLECTION_EXT_INFO; + reflection_what = php_optarg; + break; #endif default: break; @@ -1248,6 +1270,26 @@ int main(int argc, char *argv[]) break; } + case PHP_MODE_REFLECTION_EXT_INFO: + { + int len = strlen(reflection_what); + char *lcname = zend_str_tolower_dup(reflection_what, len); + zend_module_entry *module; + + if (zend_hash_find(&module_registry, lcname, len+1, (void**)&module) == FAILURE) { + if (!strcmp(reflection_what, "main")) { + display_ini_entries(NULL); + } else { + zend_printf("Extension '%s' not present.\n", reflection_what); + exit_status = 1; + } + } else { + php_info_print_module(module TSRMLS_CC); + } + + efree(lcname); + break; + } #endif /* reflection */ } } diff --git a/sapi/cli/php_cli_readline.c b/sapi/cli/php_cli_readline.c index 6cca22436..06903a7db 100644 --- a/sapi/cli/php_cli_readline.c +++ b/sapi/cli/php_cli_readline.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_cli_readline.c,v 1.3.2.5 2006/01/01 12:50:19 sniper Exp $ */ +/* $Id: php_cli_readline.c,v 1.3.2.5.2.2 2007/02/24 02:17:28 helly Exp $ */ #include "php.h" @@ -418,9 +418,10 @@ TODO: efree(class_name); } if (pce && retval) { - char *tmp = malloc(class_name_len + 2 + strlen(retval) + 1); + int len = class_name_len + 2 + strlen(retval) + 1; + char *tmp = malloc(len); - sprintf(tmp, "%s::%s", (*pce)->name, retval); + snprintf(tmp, len, "%s::%s", (*pce)->name, retval); free(retval); retval = tmp; } diff --git a/sapi/cli/php_cli_readline.h b/sapi/cli/php_cli_readline.h index 58b99398e..f27525faa 100644 --- a/sapi/cli/php_cli_readline.h +++ b/sapi/cli/php_cli_readline.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_cli_readline.h,v 1.2.2.1 2006/01/01 12:50:19 sniper Exp $ */ +/* $Id: php_cli_readline.h,v 1.2.2.1.2.1 2007/01/01 09:36:12 sebastian Exp $ */ #include "php.h" diff --git a/sapi/cli/php_getopt.h b/sapi/cli/php_getopt.h index 8d38e2803..24ac5c3f3 100644 --- a/sapi/cli/php_getopt.h +++ b/sapi/cli/php_getopt.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_getopt.h,v 1.7.2.1 2006/01/01 12:50:19 sniper Exp $ */ +/* $Id: php_getopt.h,v 1.7.2.1.2.1 2007/01/01 09:36:12 sebastian Exp $ */ #include "php.h" diff --git a/sapi/cli/tests/001.phpt b/sapi/cli/tests/001.phpt new file mode 100644 index 000000000..6fbd608a6 --- /dev/null +++ b/sapi/cli/tests/001.phpt @@ -0,0 +1,19 @@ +--TEST-- +version string +--SKIPIF-- +<?php include "skipif.inc"; ?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + +var_dump(`$php -n -v`); + +echo "Done\n"; +?> +--EXPECTF-- +string(%d) "PHP %s (cli) (built: %s)%s +Copyright (c) 1997-20%d The PHP Group +Zend Engine v%s, Copyright (c) 1998-20%d Zend Technologies +" +Done diff --git a/sapi/cli/tests/002-win32.phpt b/sapi/cli/tests/002-win32.phpt new file mode 100644 index 000000000..ca0e66ddc --- /dev/null +++ b/sapi/cli/tests/002-win32.phpt @@ -0,0 +1,22 @@ +--TEST-- +running code with -r +--SKIPIF-- +<?php +include "skipif.inc"; +if (substr(PHP_OS, 0, 3) != 'WIN') { + die ("skip only for Windows"); +} +?> +--FILE-- +<?php + +$php = $_ENV['TEST_PHP_EXECUTABLE']; + +var_dump(`$php -n -r "var_dump('hello');"`); + +echo "Done\n"; +?> +--EXPECTF-- +string(18) "string(5) "hello" +" +Done diff --git a/sapi/cli/tests/002.phpt b/sapi/cli/tests/002.phpt new file mode 100644 index 000000000..be2b6331b --- /dev/null +++ b/sapi/cli/tests/002.phpt @@ -0,0 +1,22 @@ +--TEST-- +running code with -r +--SKIPIF-- +<?php +include "skipif.inc"; +if (substr(PHP_OS, 0, 3) == 'WIN') { + die ("skip not for Windows"); +} +?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + +var_dump(`$php -n -r 'var_dump("hello");'`); + +echo "Done\n"; +?> +--EXPECTF-- +string(18) "string(5) "hello" +" +Done diff --git a/sapi/cli/tests/003-2.phpt b/sapi/cli/tests/003-2.phpt new file mode 100755 index 000000000..2ed9b07db --- /dev/null +++ b/sapi/cli/tests/003-2.phpt @@ -0,0 +1,25 @@ +--TEST-- +defining INI options with -d (as 2nd arg) +--SKIPIF-- +<?php +include "skipif.inc"; +if (substr(PHP_OS, 0, 3) == 'WIN') { + die ("skip not for Windows"); +} +?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + +var_dump(`"$php" -nd max_execution_time=111 -r 'var_dump(ini_get("max_execution_time"));'`); +var_dump(`"$php" -nd max_execution_time=500 -r 'var_dump(ini_get("max_execution_time"));'`); + +?> +===DONE=== +--EXPECTF-- +string(16) "string(3) "111" +" +string(16) "string(3) "500" +" +===DONE=== diff --git a/sapi/cli/tests/003.phpt b/sapi/cli/tests/003.phpt new file mode 100644 index 000000000..d62360e1f --- /dev/null +++ b/sapi/cli/tests/003.phpt @@ -0,0 +1,32 @@ +--TEST-- +defining INI options with -d +--SKIPIF-- +<?php +include "skipif.inc"; +if (substr(PHP_OS, 0, 3) == 'WIN') { + die ("skip not for Windows"); +} +?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + +var_dump(`$php -n -d max_execution_time=111 -r 'var_dump(ini_get("max_execution_time"));'`); +var_dump(`$php -n -d max_execution_time=500 -r 'var_dump(ini_get("max_execution_time"));'`); +var_dump(`$php -n -d max_execution_time=500 -d max_execution_time=555 -r 'var_dump(ini_get("max_execution_time"));'`); +var_dump(`$php -n -d upload_tmp_dir=/test/path -d max_execution_time=555 -r 'var_dump(ini_get("max_execution_time")); var_dump(ini_get("upload_tmp_dir"));'`); + +echo "Done\n"; +?> +--EXPECTF-- +string(16) "string(3) "111" +" +string(16) "string(3) "500" +" +string(16) "string(3) "555" +" +string(40) "string(3) "555" +string(10) "/test/path" +" +Done diff --git a/sapi/cli/tests/004.phpt b/sapi/cli/tests/004.phpt new file mode 100644 index 000000000..24c8d31c9 --- /dev/null +++ b/sapi/cli/tests/004.phpt @@ -0,0 +1,34 @@ +--TEST-- +show information about function +--SKIPIF-- +<?php +include "skipif.inc"; +if (!extension_loaded("reflection")) { + die("skip"); +} +?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + +var_dump(`$php -n --rf unknown`); +var_dump(`$php -n --rf echo`); +var_dump(`$php -n --rf phpinfo`); + +echo "Done\n"; +?> +--EXPECTF-- +string(45) "Exception: Function unknown() does not exist +" +string(42) "Exception: Function echo() does not exist +" +string(110) "Function [ <internal> function phpinfo ] { + + - Parameters [1] { + Parameter #0 [ <optional> $what ] + } +} + +" +Done diff --git a/sapi/cli/tests/005.phpt b/sapi/cli/tests/005.phpt new file mode 100644 index 000000000..0b38bba76 --- /dev/null +++ b/sapi/cli/tests/005.phpt @@ -0,0 +1,99 @@ +--TEST-- +show information about class +--SKIPIF-- +<?php +include "skipif.inc"; +if (!extension_loaded("reflection")) { + die("skip"); +} +?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + +var_dump(`$php -n --rc unknown`); +var_dump(`$php -n --rc stdclass`); +var_dump(`$php -n --rc exception`); + +echo "Done\n"; +?> +--EXPECTF-- +string(40) "Exception: Class unknown does not exist +" +string(178) "Class [ <internal> class stdClass ] { + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Methods [0] { + } +} + +" +string(1141) "Class [ <internal> class Exception ] { + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [6] { + Property [ <default> protected $message ] + Property [ <default> private $string ] + Property [ <default> protected $code ] + Property [ <default> protected $file ] + Property [ <default> protected $line ] + Property [ <default> private $trace ] + } + + - Methods [9] { + Method [ <internal> final private method __clone ] { + } + + Method [ <internal, ctor> public method __construct ] { + + - Parameters [2] { + Parameter #0 [ <optional> $message ] + Parameter #1 [ <optional> $code ] + } + } + + Method [ <internal> final public method getMessage ] { + } + + Method [ <internal> final public method getCode ] { + } + + Method [ <internal> final public method getFile ] { + } + + Method [ <internal> final public method getLine ] { + } + + Method [ <internal> final public method getTrace ] { + } + + Method [ <internal> final public method getTraceAsString ] { + } + + Method [ <internal> public method __toString ] { + } + } +} + +" +Done diff --git a/sapi/cli/tests/006.phpt b/sapi/cli/tests/006.phpt new file mode 100644 index 000000000..8ce82b3b7 --- /dev/null +++ b/sapi/cli/tests/006.phpt @@ -0,0 +1,328 @@ +--TEST-- +show information about extension +--SKIPIF-- +<?php +include "skipif.inc"; +if (!extension_loaded("reflection")) { + die("skip"); +} +?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + +var_dump(`$php -n --re unknown`); +var_dump(`$php -n --re ""`); +var_dump(`$php -n --re date`); + +echo "Done\n"; +?> +--EXPECTF-- +string(44) "Exception: Extension unknown does not exist +" +string(37) "Exception: Extension does not exist +" +string(%d) "Extension [ <persistent> extension #%d date version %s ] { + + - Dependencies { + Dependency [ session (Optional) ] + } + + - INI { + Entry [ date.timezone <ALL> ] + Current = '' + } + Entry [ date.default_latitude <ALL> ] + Current = '%s' + } + Entry [ date.default_longitude <ALL> ] + Current = '%s' + } + Entry [ date.sunset_zenith <ALL> ] + Current = '%s' + } + Entry [ date.sunrise_zenith <ALL> ] + Current = '%s' + } + } + + - Constants [14] { + Constant [ string DATE_ATOM ] { Y-m-d\TH:i:sP } + Constant [ string DATE_COOKIE ] { l, d-M-y H:i:s T } + Constant [ string DATE_ISO8601 ] { Y-m-d\TH:i:sO } + Constant [ string DATE_RFC822 ] { D, d M y H:i:s O } + Constant [ string DATE_RFC850 ] { l, d-M-y H:i:s T } + Constant [ string DATE_RFC1036 ] { D, d M y H:i:s O } + Constant [ string DATE_RFC1123 ] { D, d M Y H:i:s O } + Constant [ string DATE_RFC2822 ] { D, d M Y H:i:s O } + Constant [ string DATE_RFC3339 ] { Y-m-d\TH:i:sP } + Constant [ string DATE_RSS ] { D, d M Y H:i:s O } + Constant [ string DATE_W3C ] { Y-m-d\TH:i:sP } + Constant [ integer SUNFUNCS_RET_TIMESTAMP ] { 0 } + Constant [ integer SUNFUNCS_RET_STRING ] { 1 } + Constant [ integer SUNFUNCS_RET_DOUBLE ] { 2 } + } + + - Functions { + Function [ <internal> function strtotime ] { + + - Parameters [2] { + Parameter #0 [ <required> $time ] + Parameter #1 [ <optional> $now ] + } + } + Function [ <internal> function date ] { + + - Parameters [2] { + Parameter #0 [ <required> $format ] + Parameter #1 [ <optional> $timestamp ] + } + } + Function [ <internal> function idate ] { + + - Parameters [2] { + Parameter #0 [ <required> $format ] + Parameter #1 [ <optional> $timestamp ] + } + } + Function [ <internal> function gmdate ] { + + - Parameters [2] { + Parameter #0 [ <required> $format ] + Parameter #1 [ <optional> $timestamp ] + } + } + Function [ <internal> function mktime ] { + + - Parameters [6] { + Parameter #0 [ <optional> $hour ] + Parameter #1 [ <optional> $min ] + Parameter #2 [ <optional> $sec ] + Parameter #3 [ <optional> $mon ] + Parameter #4 [ <optional> $day ] + Parameter #5 [ <optional> $year ] + } + } + Function [ <internal> function gmmktime ] { + + - Parameters [6] { + Parameter #0 [ <optional> $hour ] + Parameter #1 [ <optional> $min ] + Parameter #2 [ <optional> $sec ] + Parameter #3 [ <optional> $mon ] + Parameter #4 [ <optional> $day ] + Parameter #5 [ <optional> $year ] + } + } + Function [ <internal> function checkdate ] { + + - Parameters [3] { + Parameter #0 [ <required> $month ] + Parameter #1 [ <required> $day ] + Parameter #2 [ <required> $year ] + } + } + Function [ <internal> function strftime ] { + + - Parameters [2] { + Parameter #0 [ <required> $format ] + Parameter #1 [ <optional> $timestamp ] + } + } + Function [ <internal> function gmstrftime ] { + + - Parameters [2] { + Parameter #0 [ <required> $format ] + Parameter #1 [ <optional> $timestamp ] + } + } + Function [ <internal> function time ] { + + - Parameters [0] { + } + } + Function [ <internal> function localtime ] { + + - Parameters [2] { + Parameter #0 [ <optional> $timestamp ] + Parameter #1 [ <optional> $associative_array ] + } + } + Function [ <internal> function getdate ] { + + - Parameters [1] { + Parameter #0 [ <optional> $timestamp ] + } + } + Function [ <internal> function date_create ] { + } + Function [ <internal> function date_parse ] { + } + Function [ <internal> function date_format ] { + } + Function [ <internal> function date_modify ] { + } + Function [ <internal> function date_timezone_get ] { + } + Function [ <internal> function date_timezone_set ] { + } + Function [ <internal> function date_offset_get ] { + } + Function [ <internal> function date_time_set ] { + } + Function [ <internal> function date_date_set ] { + } + Function [ <internal> function date_isodate_set ] { + } + Function [ <internal> function timezone_open ] { + } + Function [ <internal> function timezone_name_get ] { + } + Function [ <internal> function timezone_name_from_abbr ] { + } + Function [ <internal> function timezone_offset_get ] { + } + Function [ <internal> function timezone_transitions_get ] { + } + Function [ <internal> function timezone_identifiers_list ] { + } + Function [ <internal> function timezone_abbreviations_list ] { + } + Function [ <internal> function date_default_timezone_set ] { + + - Parameters [1] { + Parameter #0 [ <required> $timezone_identifier ] + } + } + Function [ <internal> function date_default_timezone_get ] { + + - Parameters [0] { + } + } + Function [ <internal> function date_sunrise ] { + + - Parameters [6] { + Parameter #0 [ <required> $time ] + Parameter #1 [ <optional> $format ] + Parameter #2 [ <optional> $latitude ] + Parameter #3 [ <optional> $longitude ] + Parameter #4 [ <optional> $zenith ] + Parameter #5 [ <optional> $gmt_offset ] + } + } + Function [ <internal> function date_sunset ] { + + - Parameters [6] { + Parameter #0 [ <required> $time ] + Parameter #1 [ <optional> $format ] + Parameter #2 [ <optional> $latitude ] + Parameter #3 [ <optional> $longitude ] + Parameter #4 [ <optional> $zenith ] + Parameter #5 [ <optional> $gmt_offset ] + } + } + Function [ <internal> function date_sun_info ] { + + - Parameters [3] { + Parameter #0 [ <required> $time ] + Parameter #1 [ <required> $latitude ] + Parameter #2 [ <required> $longitude ] + } + } + } + + - Classes [2] { + Class [ <internal:date> class DateTime ] { + + - Constants [11] { + Constant [ string ATOM ] { Y-m-d\TH:i:sP } + Constant [ string COOKIE ] { l, d-M-y H:i:s T } + Constant [ string ISO8601 ] { Y-m-d\TH:i:sO } + Constant [ string RFC822 ] { D, d M y H:i:s O } + Constant [ string RFC850 ] { l, d-M-y H:i:s T } + Constant [ string RFC1036 ] { D, d M y H:i:s O } + Constant [ string RFC1123 ] { D, d M Y H:i:s O } + Constant [ string RFC2822 ] { D, d M Y H:i:s O } + Constant [ string RFC3339 ] { Y-m-d\TH:i:sP } + Constant [ string RSS ] { D, d M Y H:i:s O } + Constant [ string W3C ] { Y-m-d\TH:i:sP } + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Methods [9] { + Method [ <internal, ctor> public method __construct ] { + } + + Method [ <internal> public method format ] { + } + + Method [ <internal> public method modify ] { + } + + Method [ <internal> public method getTimezone ] { + } + + Method [ <internal> public method setTimezone ] { + } + + Method [ <internal> public method getOffset ] { + } + + Method [ <internal> public method setTime ] { + } + + Method [ <internal> public method setDate ] { + } + + Method [ <internal> public method setISODate ] { + } + } + } + + Class [ <internal:date> class DateTimeZone ] { + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [2] { + Method [ <internal> static public method listAbbreviations ] { + } + + Method [ <internal> static public method listIdentifiers ] { + } + } + + - Properties [0] { + } + + - Methods [4] { + Method [ <internal, ctor> public method __construct ] { + } + + Method [ <internal> public method getName ] { + } + + Method [ <internal> public method getOffset ] { + } + + Method [ <internal> public method getTransitions ] { + } + } + } + } +} + +" +Done diff --git a/sapi/cli/tests/007.phpt b/sapi/cli/tests/007.phpt new file mode 100644 index 000000000..12fddee01 --- /dev/null +++ b/sapi/cli/tests/007.phpt @@ -0,0 +1,52 @@ +--TEST-- +strip comments and whitespace with -w +--SKIPIF-- +<?php +include "skipif.inc"; +if (substr(PHP_OS, 0, 3) == 'WIN') { + die ("skip not for Windows"); +} +?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + +$filename = dirname(__FILE__).'/007.test.php'; +$code =' +<?php +/* some test script */ + +class test { /* {{{ */ + public $var = "test"; //test var +#perl style comment + private $pri; /* private attr */ + + function foo(/* void */) { + } +} +/* }}} */ + +?> +'; + +file_put_contents($filename, $code); + +var_dump(`$php -n -w "$filename"`); +var_dump(`$php -n -w "wrong"`); +var_dump(`echo "<?php /* comment */ class test {\n // comment \n function foo() {} } ?>" | $php -n -w`); + +@unlink($filename); + +echo "Done\n"; +?> +--EXPECTF-- +string(81) " +<?php + class test { public $var = "test"; private $pri; function foo() { } } ?> +" +Could not open input file: wrong +NULL +string(43) "<?php class test { function foo() {} } ?> +" +Done diff --git a/sapi/cli/tests/008.phpt b/sapi/cli/tests/008.phpt new file mode 100644 index 000000000..a83304309 --- /dev/null +++ b/sapi/cli/tests/008.phpt @@ -0,0 +1,43 @@ +--TEST-- +execute a file with -f +--SKIPIF-- +<?php +include "skipif.inc"; +if (substr(PHP_OS, 0, 3) == 'WIN') { + die ("skip not for Windows"); +} +?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + +$filename = dirname(__FILE__).'/008.test.php'; +$code =' +<?php + +class test { + private $pri; +} + +var_dump(test::$pri); +?> +'; + +file_put_contents($filename, $code); + +var_dump(`$php -n -f "$filename"`); +var_dump(`$php -n -f "wrong"`); + +@unlink($filename); + +echo "Done\n"; +?> +--EXPECTF-- +string(%d) " + +Fatal error: Cannot access private property test::$pri in %s on line %d +" +Could not open input file: wrong +NULL +Done diff --git a/sapi/cli/tests/009.phpt b/sapi/cli/tests/009.phpt new file mode 100644 index 000000000..c0bb319f7 --- /dev/null +++ b/sapi/cli/tests/009.phpt @@ -0,0 +1,23 @@ +--TEST-- +using invalid combinations of cmdline options +--SKIPIF-- +<?php include "skipif.inc"; ?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + +var_dump(`$php -n -c -r "echo hello;"`); +var_dump(`$php -n -a -r "echo hello;"`); +var_dump(`$php -n -r "echo hello;" -a`); + +echo "Done\n"; +?> +--EXPECTF-- +You cannot use both -n and -c switch. Use -h for help. +NULL +Either execute direct code, process stdin or use a file. +NULL +Either execute direct code, process stdin or use a file. +NULL +Done diff --git a/sapi/cli/tests/010-2.phpt b/sapi/cli/tests/010-2.phpt new file mode 100644 index 000000000..bd33d2cc9 --- /dev/null +++ b/sapi/cli/tests/010-2.phpt @@ -0,0 +1,35 @@ +--TEST-- +executing a code with -R +--SKIPIF-- +<?php +include "skipif.inc"; +if (substr(PHP_OS, 0, 3) == 'WIN') { + die ("skip not for Windows"); +} +?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + +$filename_txt = dirname(__FILE__)."/010.test.txt"; + +$txt = ' +test +hello +'; + +file_put_contents($filename_txt, $txt); + +var_dump(`cat "$filename_txt" | "$php" -n -R "var_dump(1);"`); + +@unlink($filename_txt); + +echo "Done\n"; +?> +--EXPECTF-- +string(21) "int(1) +int(1) +int(1) +" +Done diff --git a/sapi/cli/tests/010.phpt b/sapi/cli/tests/010.phpt new file mode 100644 index 000000000..e465e3797 --- /dev/null +++ b/sapi/cli/tests/010.phpt @@ -0,0 +1,47 @@ +--TEST-- +executing a file with -F +--SKIPIF-- +<?php +include "skipif.inc"; +if (substr(PHP_OS, 0, 3) == 'WIN') { + die ("skip not for Windows"); +} +?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + +$filename = dirname(__FILE__)."/010.test.php"; +$filename_txt = dirname(__FILE__)."/010.test.txt"; + +$code = ' +<?php +var_dump(fread(STDIN, 10)); +?> +'; + +file_put_contents($filename, $code); + +$txt = ' +test +hello +'; + +file_put_contents($filename_txt, $txt); + +var_dump(`cat "$filename_txt" | "$php" -n -F "$filename"`); + +@unlink($filename); +@unlink($filename_txt); + +echo "Done\n"; +?> +--EXPECTF-- +string(39) " +string(10) "test +hello" + +string(0) "" +" +Done diff --git a/sapi/cli/tests/011.phpt b/sapi/cli/tests/011.phpt new file mode 100644 index 000000000..ef49666d3 --- /dev/null +++ b/sapi/cli/tests/011.phpt @@ -0,0 +1,58 @@ +--TEST-- +syntax check +--SKIPIF-- +<?php include "skipif.inc"; ?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + +$filename = dirname(__FILE__)."/011.test.php"; + +$code = ' +<?php + +$test = "var"; + +class test { + private $var; +} + +echo test::$var; + +?> +'; + +file_put_contents($filename, $code); + +var_dump(`"$php" -n -l $filename`); +var_dump(`"$php" -n -l some.unknown`); + +$code = ' +<?php + +class test + private $var; +} + +?> +'; + +file_put_contents($filename, $code); + +var_dump(`"$php" -n -l $filename`); + +@unlink($filename); + +echo "Done\n"; +?> +--EXPECTF-- +string(%d) "No syntax errors detected in %s011.test.php +" +Could not open input file: some.unknown +NULL +string(%d) " +Parse error: %s expecting %s{%s in %s on line %d +Errors parsing %s011.test.php +" +Done diff --git a/sapi/cli/tests/012.phpt b/sapi/cli/tests/012.phpt new file mode 100644 index 000000000..137e0bd78 --- /dev/null +++ b/sapi/cli/tests/012.phpt @@ -0,0 +1,38 @@ +--TEST-- +invalid arguments and error messages +--SKIPIF-- +<?php include "skipif.inc"; ?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + +var_dump(`"$php" -n -F some.php -F some.php`); +var_dump(`"$php" -n -F some.php -R some.php`); +var_dump(`"$php" -n -R some.php -F some.php`); +var_dump(`"$php" -n -R some.php -R some.php`); +var_dump(`"$php" -n -f some.php -f some.php`); +var_dump(`"$php" -n -B '' -B ''`); +var_dump(`"$php" -n -E '' -E ''`); +var_dump(`"$php" -n -r '' -r ''`); + +echo "Done\n"; +?> +--EXPECTF-- +You can use -R or -F only once. +NULL +You can use -R or -F only once. +NULL +You can use -R or -F only once. +NULL +You can use -R or -F only once. +NULL +You can use -f only once. +NULL +You can use -B only once. +NULL +You can use -E only once. +NULL +You can use -r only once. +NULL +Done diff --git a/sapi/cli/tests/013.phpt b/sapi/cli/tests/013.phpt new file mode 100644 index 000000000..99bfe5e7b --- /dev/null +++ b/sapi/cli/tests/013.phpt @@ -0,0 +1,34 @@ +--TEST-- +running PHP code before and after processing input lines with -B and -E +--SKIPIF-- +<?php +include "skipif.inc"; +if (substr(PHP_OS, 0, 3) == 'WIN') { + die ("skip not for Windows"); +} +?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + +$filename_txt = dirname(__FILE__)."/013.test.txt"; +file_put_contents($filename_txt, "test\nfile\ncontents\n"); + +var_dump(`cat "$filename_txt" | "$php" -n -B 'var_dump("start");'`); +var_dump(`cat "$filename_txt" | "$php" -n -E 'var_dump("end");'`); +var_dump(`cat "$filename_txt" | "$php" -n -B 'var_dump("start");' -E 'var_dump("end");'`); + +@unlink($filename_txt); + +echo "Done\n"; +?> +--EXPECTF-- +string(18) "string(5) "start" +" +string(16) "string(3) "end" +" +string(34) "string(5) "start" +string(3) "end" +" +Done diff --git a/sapi/cli/tests/014.phpt b/sapi/cli/tests/014.phpt new file mode 100644 index 000000000..b20478a03 --- /dev/null +++ b/sapi/cli/tests/014.phpt @@ -0,0 +1,44 @@ +--TEST-- +syntax highlighting +--SKIPIF-- +<?php include "skipif.inc"; ?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + +$filename = dirname(__FILE__)."/014.test.php"; +$code = ' +<?php +$test = "var"; //var +/* test class */ +class test { + private $var = array(); + + public static function foo(Test $arg) { + echo "hello"; + var_dump($this); + } +} + +$o = new test; +?> +'; + +file_put_contents($filename, $code); + +var_dump(`"$php" -n -s $filename`); +var_dump(`"$php" -n -s unknown`); + +@unlink($filename); + +echo "Done\n"; +?> +--EXPECTF-- +string(1478) "<code><span style="color: #000000"> +<br /><span style="color: #0000BB"><?php<br />$test </span><span style="color: #007700">= </span><span style="color: #DD0000">"var"</span><span style="color: #007700">; </span><span style="color: #FF8000">//var<br />/* test class */<br /></span><span style="color: #007700">class </span><span style="color: #0000BB">test </span><span style="color: #007700">{<br /> private </span><span style="color: #0000BB">$var </span><span style="color: #007700">= array();<br /><br /> public static function </span><span style="color: #0000BB">foo</span><span style="color: #007700">(</span><span style="color: #0000BB">Test $arg</span><span style="color: #007700">) {<br /> echo </span><span style="color: #DD0000">"hello"</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$this</span><span style="color: #007700">);<br /> }<br />}<br /><br /></span><span style="color: #0000BB">$o </span><span style="color: #007700">= new </span><span style="color: #0000BB">test</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?><br /></span> +</span> +</code>" +Could not open input file: unknown +NULL +Done diff --git a/sapi/cli/tests/015.phpt b/sapi/cli/tests/015.phpt new file mode 100644 index 000000000..be501d471 --- /dev/null +++ b/sapi/cli/tests/015.phpt @@ -0,0 +1,35 @@ +--TEST-- +CLI long options +--SKIPIF-- +<?php +include "skipif.inc"; +if (substr(PHP_OS, 0, 3) == 'WIN') { + die ("skip not for Windows"); +} +?> +--FILE-- +<?php + +$php = getenv('TEST_PHP_EXECUTABLE'); + + +echo `"$php" --version | grep built:`; +echo `echo "<?php print_r(\\\$argv);" | "$php" -- foo bar baz`, "\n"; +echo `"$php" --version foo bar baz | grep built:`; +echo `"$php" --notexisting foo bar baz | grep Usage:`; + +echo "Done\n"; +?> +--EXPECTF-- +PHP %d.%d.%d%s(cli) (built: %s)%s +Array +( + [0] => - + [1] => foo + [2] => bar + [3] => baz +) + +PHP %d.%d.%d%s(cli) (built: %s)%s +Usage: php [options] [-f] <file> [--] [args...] +Done diff --git a/sapi/cli/tests/skipif.inc b/sapi/cli/tests/skipif.inc new file mode 100644 index 000000000..79e6c9100 --- /dev/null +++ b/sapi/cli/tests/skipif.inc @@ -0,0 +1,7 @@ +<?php + +if (php_sapi_name() != "cli") { + die("skip CLI only"); +} + +?> diff --git a/sapi/continuity/capi.c b/sapi/continuity/capi.c index 0cf81e0c9..c14b76a5b 100644 --- a/sapi/continuity/capi.c +++ b/sapi/continuity/capi.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -110,7 +110,7 @@ PHP_MSHUTDOWN_FUNCTION(continuity) PHP_MINFO_FUNCTION(continuity) { php_info_print_table_start(); - php_info_print_table_row(2, "Continuity Module Revision", "$Revision: 1.11.2.2 $"); + php_info_print_table_row(2, "Continuity Module Revision", "$Revision: 1.11.2.2.2.1 $"); php_info_print_table_row(2, "Server Version", conFget_build()); #ifdef CONTINUITY_CDPEXT php_info_print_table_row(2,"CDP Extensions", "enabled"); diff --git a/sapi/embed/php_embed.c b/sapi/embed/php_embed.c index e2ce93cec..4d8326789 100644 --- a/sapi/embed/php_embed.c +++ b/sapi/embed/php_embed.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -15,7 +15,7 @@ | Author: Edin Kadribasic <edink@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: php_embed.c,v 1.11.2.1 2006/01/01 12:50:19 sniper Exp $ */ +/* $Id: php_embed.c,v 1.11.2.1.2.1 2007/01/01 09:36:12 sebastian Exp $ */ #include "php_embed.h" diff --git a/sapi/embed/php_embed.h b/sapi/embed/php_embed.h index bf1bcb936..f18d61fab 100644 --- a/sapi/embed/php_embed.h +++ b/sapi/embed/php_embed.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -15,7 +15,7 @@ | Author: Edin Kadribasic <edink@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: php_embed.h,v 1.6.2.2 2006/01/01 12:50:19 sniper Exp $ */ +/* $Id: php_embed.h,v 1.6.2.2.2.1 2007/01/01 09:36:12 sebastian Exp $ */ #ifndef _PHP_EMBED_H_ #define _PHP_EMBED_H_ diff --git a/sapi/isapi/php5isapi.c b/sapi/isapi/php5isapi.c index da3615359..2e357d3cb 100644 --- a/sapi/isapi/php5isapi.c +++ b/sapi/isapi/php5isapi.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ | Ben Mansell <ben@zeus.com> (Zeus Support) | +----------------------------------------------------------------------+ */ -/* $Id: php5isapi.c,v 1.8.2.2 2006/02/15 11:15:32 tony2001 Exp $ */ +/* $Id: php5isapi.c,v 1.8.2.2.2.3 2007/02/23 22:08:31 stas Exp $ */ #include "php.h" #include <httpext.h> @@ -389,24 +389,24 @@ static void sapi_isapi_register_zeus_ssl_variables(LPEXTENSION_CONTROL_BLOCK lpE */ strcpy( static_cons_buf, "/C=" ); if( lpECB->GetServerVariable( lpECB->ConnID, "SSL_CLIENT_C", static_variable_buf, &variable_len ) && static_variable_buf[0] ) { - strcat( static_cons_buf, static_variable_buf ); + strlcat( static_cons_buf, static_variable_buf, ISAPI_SERVER_VAR_BUF_SIZE); } - strcat( static_cons_buf, "/ST=" ); + strlcat( static_cons_buf, "/ST=", ISAPI_SERVER_VAR_BUF_SIZE); variable_len = ISAPI_SERVER_VAR_BUF_SIZE; if( lpECB->GetServerVariable( lpECB->ConnID, "SSL_CLIENT_ST", static_variable_buf, &variable_len ) && static_variable_buf[0] ) { - strcat( static_cons_buf, static_variable_buf ); + strlcat( static_cons_buf, static_variable_buf, ISAPI_SERVER_VAR_BUF_SIZE ); } php_register_variable( "SSL_CLIENT_DN", static_cons_buf, track_vars_array TSRMLS_CC ); strcpy( static_cons_buf, "/C=" ); variable_len = ISAPI_SERVER_VAR_BUF_SIZE; if( lpECB->GetServerVariable( lpECB->ConnID, "SSL_CLIENT_I_C", static_variable_buf, &variable_len ) && static_variable_buf[0] ) { - strcat( static_cons_buf, static_variable_buf ); + strlcat( static_cons_buf, static_variable_buf, ISAPI_SERVER_VAR_BUF_SIZE ); } - strcat( static_cons_buf, "/ST=" ); + strlcat( static_cons_buf, "/ST=", ISAPI_SERVER_VAR_BUF_SIZE); variable_len = ISAPI_SERVER_VAR_BUF_SIZE; if( lpECB->GetServerVariable( lpECB->ConnID, "SSL_CLIENT_I_ST", static_variable_buf, &variable_len ) && static_variable_buf[0] ) { - strcat( static_cons_buf, static_variable_buf ); + strlcat( static_cons_buf, static_variable_buf, ISAPI_SERVER_VAR_BUF_SIZE ); } php_register_variable( "SSL_CLIENT_I_DN", static_cons_buf, track_vars_array TSRMLS_CC ); } diff --git a/sapi/milter/php_milter.c b/sapi/milter/php_milter.c index 17bb63e38..620e39008 100644 --- a/sapi/milter/php_milter.c +++ b/sapi/milter/php_milter.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -63,6 +63,8 @@ #include "libmilter/mfapi.h" +#include "php_getopt.h" + #define OPTSTRING "ac:d:Def:hnp:vVz:?" #define MG(v) TSRMG(milter_globals_id, zend_milter_globals *, v) @@ -109,6 +111,7 @@ static int mlfi_init() int ret = 0; zend_file_handle file_handle; zval function_name, retval; + int status; TSRMLS_FETCH(); /* request startup */ @@ -123,8 +126,13 @@ static int mlfi_init() /* disable headers */ SG(headers_sent) = 1; SG(request_info).no_headers = 1; - - file_handle.type = ZEND_HANDLE_FILENAME; + + if (!(file_handle.handle.fp = VCWD_FOPEN(filename, "rb"))) { + php_printf("Could not open input file: %s\n", filename); + return SMFIS_TEMPFAIL; + } + + file_handle.type = ZEND_HANDLE_FP; file_handle.filename = filename; file_handle.free_filename = 0; file_handle.opened_path = NULL; @@ -139,12 +147,12 @@ static int mlfi_init() /* set the milter context for possible use in API functions */ MG(state) = MLFI_INIT; - call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL TSRMLS_CC); + status = call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL TSRMLS_CC); MG(state) = MLFI_NONE; MG(initialized) = 1; - if (Z_TYPE(retval) == IS_LONG) { + if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { ret = Z_LVAL(retval); } @@ -164,6 +172,7 @@ static sfsistat mlfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr) { zend_file_handle file_handle; zval function_name, retval, *param[1]; + int status; TSRMLS_FETCH(); /* request startup */ @@ -178,8 +187,13 @@ static sfsistat mlfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr) /* disable headers */ SG(headers_sent) = 1; SG(request_info).no_headers = 1; - - file_handle.type = ZEND_HANDLE_FILENAME; + + if (!(file_handle.handle.fp = VCWD_FOPEN(filename, "rb"))) { + php_printf("Could not open input file: %s\n", filename); + return SMFIS_TEMPFAIL; + } + + file_handle.type = ZEND_HANDLE_FP; file_handle.filename = filename; file_handle.free_filename = 0; file_handle.opened_path = NULL; @@ -199,11 +213,11 @@ static sfsistat mlfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr) MG(ctx) = ctx; MG(state) = MLFI_CONNECT; - call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param TSRMLS_CC); + status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param TSRMLS_CC); MG(state) = MLFI_NONE; - - if (Z_TYPE(retval) == IS_LONG) { + zval_ptr_dtor(param); + if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { return Z_LVAL(retval); } @@ -217,6 +231,7 @@ static sfsistat mlfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr) static sfsistat mlfi_helo(SMFICTX *ctx, char *helohost) { zval function_name, retval, *param[1]; + int status; TSRMLS_FETCH(); /* call userland */ @@ -232,13 +247,12 @@ static sfsistat mlfi_helo(SMFICTX *ctx, char *helohost) MG(ctx) = ctx; MG(state) = MLFI_HELO; - call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param TSRMLS_CC); + status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param TSRMLS_CC); MG(state) = MLFI_NONE; + zval_ptr_dtor(param); - FREE_ZVAL(param[0]); - - if (Z_TYPE(retval) == IS_LONG) { + if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { return Z_LVAL(retval); } @@ -252,6 +266,7 @@ static sfsistat mlfi_helo(SMFICTX *ctx, char *helohost) static sfsistat mlfi_envfrom(SMFICTX *ctx, char **argv) { zval function_name, retval, *param[1]; + int status; TSRMLS_FETCH(); /* call userland */ @@ -272,13 +287,12 @@ static sfsistat mlfi_envfrom(SMFICTX *ctx, char **argv) MG(ctx) = ctx; MG(state) = MLFI_ENVFROM; - call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param TSRMLS_CC); + status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param TSRMLS_CC); MG(state) = MLFI_NONE; + zval_ptr_dtor(param); - FREE_ZVAL(param[0]); - - if (Z_TYPE(retval) == IS_LONG) { + if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { return Z_LVAL(retval); } @@ -292,6 +306,7 @@ static sfsistat mlfi_envfrom(SMFICTX *ctx, char **argv) static sfsistat mlfi_envrcpt(SMFICTX *ctx, char **argv) { zval function_name, retval, *param[1]; + int status; TSRMLS_FETCH(); /* call userland */ @@ -312,13 +327,13 @@ static sfsistat mlfi_envrcpt(SMFICTX *ctx, char **argv) MG(ctx) = ctx; MG(state) = MLFI_ENVRCPT; - call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param TSRMLS_CC); + status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param TSRMLS_CC); MG(state) = MLFI_NONE; - FREE_ZVAL(param[0]); + zval_ptr_dtor(param); - if (Z_TYPE(retval) == IS_LONG) { + if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { return Z_LVAL(retval); } @@ -332,6 +347,7 @@ static sfsistat mlfi_envrcpt(SMFICTX *ctx, char **argv) static sfsistat mlfi_header(SMFICTX *ctx, char *headerf, char *headerv) { zval function_name, retval, *param[2]; + int status; TSRMLS_FETCH(); /* call userland */ @@ -350,14 +366,14 @@ static sfsistat mlfi_header(SMFICTX *ctx, char *headerf, char *headerv) MG(ctx) = ctx; MG(state) = MLFI_HEADER; - call_user_function(CG(function_table), NULL, &function_name, &retval, 2, param TSRMLS_CC); + status = call_user_function(CG(function_table), NULL, &function_name, &retval, 2, param TSRMLS_CC); MG(state) = MLFI_NONE; - FREE_ZVAL(param[0]); - FREE_ZVAL(param[1]); + zval_ptr_dtor(¶m[0]); + zval_ptr_dtor(¶m[1]); - if (Z_TYPE(retval) == IS_LONG) { + if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { return Z_LVAL(retval); } @@ -371,6 +387,7 @@ static sfsistat mlfi_header(SMFICTX *ctx, char *headerf, char *headerv) static sfsistat mlfi_eoh(SMFICTX *ctx) { zval function_name, retval; + int status; TSRMLS_FETCH(); /* call userland */ @@ -381,11 +398,11 @@ static sfsistat mlfi_eoh(SMFICTX *ctx) MG(ctx) = ctx; MG(state) = MLFI_EOH; - call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL TSRMLS_CC); + status = call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL TSRMLS_CC); MG(state) = MLFI_NONE; - if (Z_TYPE(retval) == IS_LONG) { + if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { return Z_LVAL(retval); } @@ -399,6 +416,7 @@ static sfsistat mlfi_eoh(SMFICTX *ctx) static sfsistat mlfi_body(SMFICTX *ctx, u_char *bodyp, size_t len) { zval function_name, retval, *param[1]; + int status; TSRMLS_FETCH(); /* call userland */ @@ -408,19 +426,19 @@ static sfsistat mlfi_body(SMFICTX *ctx, u_char *bodyp, size_t len) INIT_PZVAL(param[0]); ZVAL_STRING(&function_name, "milter_body", 0); - ZVAL_STRINGL(param[0], bodyp, len, 1); + ZVAL_STRINGL(param[0], (char*)bodyp, len, 1); /*alex*/ /* set the milter context for possible use in API functions */ MG(ctx) = ctx; MG(state) = MLFI_BODY; - call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param TSRMLS_CC); + status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param TSRMLS_CC); MG(state) = MLFI_NONE; - FREE_ZVAL(param[0]); + zval_ptr_dtor(param); - if (Z_TYPE(retval) == IS_LONG) { + if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { return Z_LVAL(retval); } @@ -434,6 +452,7 @@ static sfsistat mlfi_body(SMFICTX *ctx, u_char *bodyp, size_t len) static sfsistat mlfi_eom(SMFICTX *ctx) { zval function_name, retval; + int status; TSRMLS_FETCH(); /* call userland */ @@ -444,11 +463,11 @@ static sfsistat mlfi_eom(SMFICTX *ctx) MG(ctx) = ctx; MG(state) = MLFI_EOM; - call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL TSRMLS_CC); + status = call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL TSRMLS_CC); MG(state) = MLFI_NONE; - if (Z_TYPE(retval) == IS_LONG) { + if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { return Z_LVAL(retval); } @@ -462,6 +481,7 @@ static sfsistat mlfi_eom(SMFICTX *ctx) static sfsistat mlfi_abort(SMFICTX *ctx) { zval function_name, retval; + int status; TSRMLS_FETCH(); /* call userland */ @@ -472,11 +492,11 @@ static sfsistat mlfi_abort(SMFICTX *ctx) MG(ctx) = ctx; MG(state) = MLFI_ABORT; - call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL TSRMLS_CC); + status = call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL TSRMLS_CC); MG(state) = MLFI_NONE; - if (Z_TYPE(retval) == IS_LONG) { + if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { return Z_LVAL(retval); } @@ -491,6 +511,7 @@ static sfsistat mlfi_close(SMFICTX *ctx) { int ret = SMFIS_CONTINUE; zval function_name, retval; + int status; TSRMLS_FETCH(); /* call userland */ @@ -501,11 +522,11 @@ static sfsistat mlfi_close(SMFICTX *ctx) MG(ctx) = ctx; MG(state) = MLFI_CLOSE; - call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL TSRMLS_CC); + status = call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL TSRMLS_CC); MG(state) = MLFI_NONE; - if (Z_TYPE(retval) == IS_LONG) { + if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { ret = Z_LVAL(retval); } @@ -538,7 +559,7 @@ struct smfiDesc smfilter = { /* {{{ PHP Milter API */ -/* {{{ proto string smfi_setflags(long flags) +/* {{{ proto void smfi_setflags(long flags) Sets the flags describing the actions the filter may take. */ PHP_FUNCTION(smfi_setflags) { @@ -548,13 +569,13 @@ PHP_FUNCTION(smfi_setflags) if (MG(state) != MLFI_INIT) { php_error(E_WARNING, NOT_INIT, get_active_function_name(TSRMLS_C)); } else if (zend_parse_parameters(1 TSRMLS_CC, "l", &flags) == SUCCESS) { - flags = flags & SMFIF_ADDHDRS|SMFIF_CHGHDRS|SMFIF_CHGBODY|SMFIF_ADDRCPT|SMFIF_DELRCPT; + flags = flags & (SMFIF_ADDHDRS|SMFIF_CHGHDRS|SMFIF_CHGBODY|SMFIF_ADDRCPT|SMFIF_DELRCPT); smfilter.xxfi_flags = flags; } } /* }}} */ -/* {{{ proto string smfi_settimeout(long timeout) +/* {{{ proto void smfi_settimeout(long timeout) Sets the number of seconds libmilter will wait for an MTA connection before timing out a socket. */ PHP_FUNCTION(smfi_settimeout) { @@ -581,15 +602,15 @@ PHP_FUNCTION(smfi_getsymval) php_error(E_WARNING, IS_NONE, get_active_function_name(TSRMLS_C)); } else if (zend_parse_parameters(1 TSRMLS_CC, "s", &symname, &len) == SUCCESS) { if ((ret = smfi_getsymval(MG(ctx), symname)) != NULL) { - RETVAL_STRING(ret, 1); + RETURN_STRING(ret, 1); } } - RETVAL_NULL(); + RETURN_NULL(); } /* }}} */ -/* {{{ proto string smfi_setreply(string rcode, string xcode, string message) +/* {{{ proto bool smfi_setreply(string rcode, string xcode, string message) Directly set the SMTP error reply code for this connection. This code will be used on subsequent error replies resulting from actions taken by this filter. */ PHP_FUNCTION(smfi_setreply) @@ -602,15 +623,15 @@ PHP_FUNCTION(smfi_setreply) php_error(E_WARNING, IS_NONE, get_active_function_name(TSRMLS_C)); } else if (zend_parse_parameters(3 TSRMLS_CC, "sss", &rcode, &len, &xcode, &len, &message, &len) == SUCCESS) { if (smfi_setreply(MG(ctx), rcode, xcode, message) == MI_SUCCESS) { - RETVAL_TRUE; + RETURN_TRUE; } } - RETVAL_FALSE; + RETURN_FALSE; } /* }}} */ -/* {{{ proto string smfi_addheader(string headerf, string headerv) +/* {{{ proto bool smfi_addheader(string headerf, string headerv) Adds a header to the current message. */ PHP_FUNCTION(smfi_addheader) { @@ -622,15 +643,15 @@ PHP_FUNCTION(smfi_addheader) php_error(E_WARNING, NOT_EOM, get_active_function_name(TSRMLS_C)); } else if (zend_parse_parameters(2 TSRMLS_CC, "ss", &f, &len, &v, &len) == SUCCESS) { if (smfi_addheader(MG(ctx), f, v) == MI_SUCCESS) { - RETVAL_TRUE; + RETURN_TRUE; } } - RETVAL_FALSE; + RETURN_FALSE; } /* }}} */ -/* {{{ proto string smfi_chgheader(string headerf, string headerv) +/* {{{ proto bool smfi_chgheader(string headerf, string headerv) Changes a header's value for the current message. */ PHP_FUNCTION(smfi_chgheader) { @@ -643,15 +664,15 @@ PHP_FUNCTION(smfi_chgheader) php_error(E_WARNING, NOT_EOM, get_active_function_name(TSRMLS_C)); } else if (zend_parse_parameters(3 TSRMLS_CC, "sls", &f, &len, &idx, &v, &len) == SUCCESS) { if (smfi_chgheader(MG(ctx), f, idx, v) == MI_SUCCESS) { - RETVAL_TRUE; + RETURN_TRUE; } } - RETVAL_FALSE; + RETURN_FALSE; } /* }}} */ -/* {{{ proto string smfi_addrcpt(string rcpt) +/* {{{ proto bool smfi_addrcpt(string rcpt) Add a recipient to the message envelope. */ PHP_FUNCTION(smfi_addrcpt) { @@ -663,15 +684,15 @@ PHP_FUNCTION(smfi_addrcpt) php_error(E_WARNING, NOT_EOM, get_active_function_name(TSRMLS_C)); } else if (zend_parse_parameters(1 TSRMLS_CC, "s", &rcpt, &len) == SUCCESS) { if (smfi_addrcpt(MG(ctx), rcpt) == MI_SUCCESS) { - RETVAL_TRUE; + RETURN_TRUE; } } - RETVAL_FALSE; + RETURN_FALSE; } /* }}} */ -/* {{{ proto string smfi_delrcpt(string rcpt) +/* {{{ proto bool smfi_delrcpt(string rcpt) Removes the named recipient from the current message's envelope. */ PHP_FUNCTION(smfi_delrcpt) { @@ -683,15 +704,15 @@ PHP_FUNCTION(smfi_delrcpt) php_error(E_WARNING, NOT_EOM, get_active_function_name(TSRMLS_C)); } else if (zend_parse_parameters(1 TSRMLS_CC, "s", &rcpt, &len) == SUCCESS) { if (smfi_delrcpt(MG(ctx), rcpt) == MI_SUCCESS) { - RETVAL_TRUE; + RETURN_TRUE; } } - RETVAL_FALSE; + RETURN_FALSE; } /* }}} */ -/* {{{ proto string smfi_replacebody(string body) +/* {{{ proto bool smfi_replacebody(string body) Replaces the body of the current message. If called more than once, subsequent calls result in data being appended to the new body. */ PHP_FUNCTION(smfi_replacebody) @@ -703,12 +724,12 @@ PHP_FUNCTION(smfi_replacebody) if (MG(state) != MLFI_EOM) { php_error(E_WARNING, NOT_EOM, get_active_function_name(TSRMLS_C)); } else if (zend_parse_parameters(1 TSRMLS_CC, "s", &body, &len) == SUCCESS) { - if (smfi_replacebody(MG(ctx), body, len) == MI_SUCCESS) { - RETVAL_TRUE; + if (smfi_replacebody(MG(ctx), (u_char*)body, len) == MI_SUCCESS) { + RETURN_TRUE; } } - RETVAL_FALSE; + RETURN_FALSE; } /* }}} */ @@ -732,6 +753,7 @@ PHP_MINIT_FUNCTION(milter) MG(state) = MLFI_NONE; MG(initialized) = 0; + return SUCCESS; } /* }}} */ @@ -893,7 +915,7 @@ static void php_milter_usage(char *argv0) } /* }}} */ -static void define_command_line_ini_entry(char *arg) +static void define_command_line_ini_entry(char *arg) /* {{{ */ { char *name, *value; @@ -907,6 +929,7 @@ static void define_command_line_ini_entry(char *arg) } zend_alter_ini_entry(name, strlen(name)+1, value, strlen(value), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE); } +/* }}} */ /* {{{ main */ @@ -920,9 +943,7 @@ int main(int argc, char *argv[]) /* temporary locals */ int orig_optind=ap_php_optind; char *orig_optarg=ap_php_optarg; - char *arg_free=NULL, **arg_excp=&arg_free; int interactive=0; - char *exec_direct=NULL; char *param_error=NULL; /* end of temporary locals */ @@ -1044,7 +1065,7 @@ int main(int argc, char *argv[]) } SG(headers_sent) = 1; SG(request_info).no_headers = 1; - php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) 1997-2006 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version()); + php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) 1997-2007 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version()); php_end_ob_buffers(1 TSRMLS_CC); exit(1); break; @@ -1092,22 +1113,25 @@ int main(int argc, char *argv[]) } } - { + if (sock) { struct stat junk; if (stat(sock,&junk) == 0) unlink(sock); } openlog("php-milter", LOG_PID, LOG_MAIL); - if (exit_status = mlfi_init()) { + if ((exit_status = mlfi_init())) { syslog(1, "mlfi_init failed."); - exit(exit_status); + closelog(); + goto err; } smfi_setconn(sock); if (smfi_register(smfilter) == MI_FAILURE) { syslog(1, "smfi_register failed."); fprintf(stderr, "smfi_register failed\n"); + closelog(); + goto err; } else { exit_status = smfi_main(); } @@ -1122,6 +1146,7 @@ int main(int argc, char *argv[]) exit_status = EG(exit_status); } zend_end_try(); +err: php_module_shutdown(TSRMLS_C); sapi_shutdown(); tsrm_shutdown(); diff --git a/sapi/nsapi/nsapi.c b/sapi/nsapi/nsapi.c index 5991b5d4e..c6536c5da 100644 --- a/sapi/nsapi/nsapi.c +++ b/sapi/nsapi/nsapi.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: nsapi.c,v 1.69.2.3 2006/01/01 12:50:19 sniper Exp $ */ +/* $Id: nsapi.c,v 1.69.2.3.2.6 2007/04/27 00:29:26 thetaphi Exp $ */ /* * PHP includes @@ -73,8 +73,6 @@ #define NSLS_CC , NSLS_C #define NSG(v) (request_context->v) -#define NS_BUF_SIZE 2048 - /* * ZTS needs to be defined for NSAPI to work */ @@ -310,7 +308,7 @@ PHP_MSHUTDOWN_FUNCTION(nsapi) PHP_MINFO_FUNCTION(nsapi) { php_info_print_table_start(); - php_info_print_table_row(2, "NSAPI Module Revision", "$Revision: 1.69.2.3 $"); + php_info_print_table_row(2, "NSAPI Module Revision", "$Revision: 1.69.2.3.2.6 $"); php_info_print_table_row(2, "Server Software", system_version()); php_info_print_table_row(2, "Sub-requests with nsapi_virtual()", (nsapi_servact_service)?((zend_ini_long("zlib.output_compression", sizeof("zlib.output_compression"), 0))?"not supported with zlib.output_compression":"enabled"):"not supported on this platform" ); @@ -589,7 +587,7 @@ static void sapi_nsapi_register_server_variables(zval *track_vars_array TSRMLS_D register size_t i; int pos; char *value,*p; - char buf[NS_BUF_SIZE + 1]; + char buf[32]; struct pb_entry *entry; for (i = 0; i < nsapi_reqpb_size; i++) { @@ -604,20 +602,22 @@ static void sapi_nsapi_register_server_variables(zval *track_vars_array TSRMLS_D while (entry) { if (!PG(safe_mode) || strncasecmp(entry->param->name, "authorization", 13)) { if (strcasecmp(entry->param->name, "content-length")==0 || strcasecmp(entry->param->name, "content-type")==0) { - strlcpy(buf, entry->param->name, NS_BUF_SIZE); + value=estrdup(entry->param->name); pos = 0; } else { - snprintf(buf, NS_BUF_SIZE, "HTTP_%s", entry->param->name); + spprintf(&value, 0, "HTTP_%s", entry->param->name); pos = 5; } - buf[NS_BUF_SIZE]='\0'; - for(p = buf + pos; *p; p++) { - *p = toupper(*p); - if (*p < 'A' || *p > 'Z') { - *p = '_'; + if (value) { + for(p = value + pos; *p; p++) { + *p = toupper(*p); + if (*p < 'A' || *p > 'Z') { + *p = '_'; + } } + php_register_variable(value, entry->param->value, track_vars_array TSRMLS_CC); + efree(value); } - php_register_variable(buf, entry->param->value, track_vars_array TSRMLS_CC); } entry=entry->next; } @@ -642,7 +642,7 @@ static void sapi_nsapi_register_server_variables(zval *track_vars_array TSRMLS_D nsapi_free(value); } - sprintf(buf, "%d", conf_getglobals()->Vport); + slprintf(buf, sizeof(buf), "%d", conf_getglobals()->Vport); php_register_variable("SERVER_PORT", buf, track_vars_array TSRMLS_CC); php_register_variable("SERVER_NAME", conf_getglobals()->Vserver_hostname, track_vars_array TSRMLS_CC); @@ -672,30 +672,34 @@ static void sapi_nsapi_register_server_variables(zval *track_vars_array TSRMLS_D /* Create full Request-URI & Script-Name */ if (SG(request_info).request_uri) { - strlcpy(buf, SG(request_info).request_uri, NS_BUF_SIZE); if (SG(request_info).query_string) { - p = strchr(buf, 0); - snprintf(p, NS_BUF_SIZE-(p-buf), "?%s", SG(request_info).query_string); - buf[NS_BUF_SIZE]='\0'; + spprintf(&value, 0, "%s?%s", SG(request_info).request_uri, SG(request_info).query_string); + if (value) { + php_register_variable("REQUEST_URI", value, track_vars_array TSRMLS_CC); + efree(value); + } + } else { + php_register_variable("REQUEST_URI", SG(request_info).request_uri, track_vars_array TSRMLS_CC); } - php_register_variable("REQUEST_URI", buf, track_vars_array TSRMLS_CC); - strlcpy(buf, SG(request_info).request_uri, NS_BUF_SIZE); - if (rc->path_info) { - pos = strlen(SG(request_info).request_uri) - strlen(rc->path_info); - if (pos>=0 && pos<=NS_BUF_SIZE && rc->path_info) { - buf[pos] = '\0'; - } else { - buf[0]='\0'; + if (value = nsapi_strdup(SG(request_info).request_uri)) { + if (rc->path_info) { + pos = strlen(SG(request_info).request_uri) - strlen(rc->path_info); + if (pos>=0) { + value[pos] = '\0'; + } else { + value[0]='\0'; + } } + php_register_variable("SCRIPT_NAME", value, track_vars_array TSRMLS_CC); + nsapi_free(value); } - php_register_variable("SCRIPT_NAME", buf, track_vars_array TSRMLS_CC); } php_register_variable("SCRIPT_FILENAME", SG(request_info).path_translated, track_vars_array TSRMLS_CC); /* special variables in error mode */ if (rc->http_error) { - sprintf(buf, "%d", rc->http_error); + slprintf(buf, sizeof(buf), "%d", rc->http_error); php_register_variable("ERROR_TYPE", buf, track_vars_array TSRMLS_CC); } } @@ -705,7 +709,11 @@ static void nsapi_log_message(char *message) TSRMLS_FETCH(); nsapi_request_context *rc = (nsapi_request_context *)SG(server_context); - log_error(LOG_INFORM, pblock_findval("fn", rc->pb), rc->sn, rc->rq, "%s", message); + if (rc) { + log_error(LOG_INFORM, pblock_findval("fn", rc->pb), rc->sn, rc->rq, "%s", message); + } else { + log_error(LOG_INFORM, "php5", NULL, NULL, "%s", message); + } } static time_t sapi_nsapi_get_request_time(TSRMLS_D) diff --git a/sapi/phttpd/php_phttpd.h b/sapi/phttpd/php_phttpd.h index 9add826f6..235309f65 100644 --- a/sapi/phttpd/php_phttpd.h +++ b/sapi/phttpd/php_phttpd.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | diff --git a/sapi/phttpd/phttpd.c b/sapi/phttpd/phttpd.c index 61ecbcbfe..8e8241da5 100644 --- a/sapi/phttpd/phttpd.c +++ b/sapi/phttpd/phttpd.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | diff --git a/sapi/pi3web/pi3web_sapi.c b/sapi/pi3web/pi3web_sapi.c index 6ae1eecfd..9459d8289 100644 --- a/sapi/pi3web/pi3web_sapi.c +++ b/sapi/pi3web/pi3web_sapi.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: pi3web_sapi.c,v 1.60.2.1 2006/01/01 12:50:19 sniper Exp $ */ +/* $Id: pi3web_sapi.c,v 1.60.2.1.2.1 2007/01/01 09:36:13 sebastian Exp $ */ #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS @@ -57,7 +57,7 @@ static void php_info_pi3web(ZEND_MODULE_INFO_FUNC_ARGS) PUTS("<table border=0 cellpadding=3 cellspacing=1 width=600 align=center>\n"); PUTS("<tr><th colspan=2 bgcolor=\"" PHP_HEADER_COLOR "\">Pi3Web Server Information</th></tr>\n"); php_info_print_table_header(2, "Information Field", "Value"); - php_info_print_table_row(2, "Pi3Web SAPI module version", "$Id: pi3web_sapi.c,v 1.60.2.1 2006/01/01 12:50:19 sniper Exp $"); + php_info_print_table_row(2, "Pi3Web SAPI module version", "$Id: pi3web_sapi.c,v 1.60.2.1.2.1 2007/01/01 09:36:13 sebastian Exp $"); php_info_print_table_row(2, "Server Name Stamp", HTTPCore_getServerStamp()); snprintf(variable_buf, 511, "%d", HTTPCore_debugEnabled()); php_info_print_table_row(2, "Debug Enabled", variable_buf); diff --git a/sapi/roxen/roxen.c b/sapi/roxen/roxen.c index aa6315cc3..34b547999 100644 --- a/sapi/roxen/roxen.c +++ b/sapi/roxen/roxen.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: roxen.c,v 1.61.2.2 2006/01/01 12:50:19 sniper Exp $ */ +/* $Id: roxen.c,v 1.61.2.2.2.1 2007/01/01 09:36:13 sebastian Exp $ */ #include "php.h" #ifdef HAVE_ROXEN @@ -438,7 +438,7 @@ static void php_info_roxen(ZEND_MODULE_INFO_FUNC_ARGS) { /* char buf[512]; */ php_info_print_table_start(); - php_info_print_table_row(2, "SAPI module version", "$Id: roxen.c,v 1.61.2.2 2006/01/01 12:50:19 sniper Exp $"); + php_info_print_table_row(2, "SAPI module version", "$Id: roxen.c,v 1.61.2.2.2.1 2007/01/01 09:36:13 sebastian Exp $"); /* php_info_print_table_row(2, "Build date", Ns_InfoBuildDate()); php_info_print_table_row(2, "Config file path", Ns_InfoConfigFile()); php_info_print_table_row(2, "Error Log path", Ns_InfoErrorLog()); diff --git a/sapi/thttpd/php_thttpd.h b/sapi/thttpd/php_thttpd.h index cc0255d29..56567d639 100644 --- a/sapi/thttpd/php_thttpd.h +++ b/sapi/thttpd/php_thttpd.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | diff --git a/sapi/thttpd/thttpd.c b/sapi/thttpd/thttpd.c index fba14570f..121f35239 100644 --- a/sapi/thttpd/thttpd.c +++ b/sapi/thttpd/thttpd.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: thttpd.c,v 1.95.2.1 2006/01/01 12:50:19 sniper Exp $ */ +/* $Id: thttpd.c,v 1.95.2.1.2.1 2007/01/01 09:36:13 sebastian Exp $ */ #include "php.h" #include "SAPI.h" diff --git a/sapi/tux/php_tux.c b/sapi/tux/php_tux.c index 579bf16ea..3a3a452ee 100644 --- a/sapi/tux/php_tux.c +++ b/sapi/tux/php_tux.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -116,7 +116,7 @@ static int sapi_tux_send_headers(sapi_headers_struct *sapi_headers) status_line = malloc(30); /* safe sprintf use */ - len = sprintf(status_line, "HTTP/1.1 %d NA\r\n", SG(sapi_headers).http_response_code); + len = slprintf(status_line, 30, "HTTP/1.1 %d NA\r\n", SG(sapi_headers).http_response_code); vec[0].iov_base = status_line; vec[0].iov_len = len; @@ -195,7 +195,7 @@ static void sapi_tux_register_variables(zval *track_vars_array TSRMLS_DC) sapi_header_line ctr = {0}; ctr.line = buf; - ctr.line_len = sprintf(buf, "Server: %s", TUXAPI_version); + ctr.line_len = slprintf(buf, sizeof(buf), "Server: %s", TUXAPI_version); sapi_header_op(SAPI_HEADER_REPLACE, &ctr TSRMLS_CC); php_register_variable("PHP_SELF", SG(request_info).request_uri, track_vars_array TSRMLS_CC); @@ -215,7 +215,7 @@ static void sapi_tux_register_variables(zval *track_vars_array TSRMLS_DC) ADD_STRING("REMOTE_HOST"); } - sprintf(buf, "%d", CGI_SERVER_PORT(TG(req))); + snprintf(buf, sizeof(buf), "%d", CGI_SERVER_PORT(TG(req))); ADD_STRING("SERVER_PORT"); #if 0 @@ -241,7 +241,7 @@ static void sapi_tux_register_variables(zval *track_vars_array TSRMLS_DC) #if 0 if (TG(hc)->contentlength != -1) { - sprintf(buf, "%ld", (long) TG(hc)->contentlength); + snprintf(buf, sizeof(buf), "%ld", (long) TG(hc)->contentlength); ADD_STRING("CONTENT_LENGTH"); } #endif diff --git a/sapi/webjames/php_webjames.h b/sapi/webjames/php_webjames.h index 9b9c037c1..99a55efb4 100644 --- a/sapi/webjames/php_webjames.h +++ b/sapi/webjames/php_webjames.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | diff --git a/sapi/webjames/webjames.c b/sapi/webjames/webjames.c index 3068d8fcc..e7eea9e0b 100644 --- a/sapi/webjames/webjames.c +++ b/sapi/webjames/webjames.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -27,7 +27,7 @@ #include <unixlib/local.h> -#define WEBJAMES_SAPI_VERSION "1.0.1" +#define WEBJAMES_SAPI_VERSION "1.0.2" typedef struct { struct connection *conn; /*structure holding all the details of the current request*/ @@ -42,24 +42,44 @@ static php_webjames_globals webjames_globals; static int sapi_webjames_ub_write(const char *str, uint str_length TSRMLS_DC) /*unbuffered write - send data straight out to socket*/ { - int bytes; - - bytes = webjames_writebuffer(WG(conn),str,str_length); - if (bytes<0) { - PG(connection_status) = PHP_CONNECTION_ABORTED; - if (!PG(ignore_user_abort)) { - zend_bailout(); + int totalbytes = 0; + + do { + int bytes; + bytes = webjames_writebuffer(WG(conn),str,str_length); + if (bytes<0) { + PG(connection_status) = PHP_CONNECTION_ABORTED; + if (!PG(ignore_user_abort)) { + zend_bailout(); + } + return bytes; } - } - return bytes; + str += bytes; + str_length -= bytes; + totalbytes += bytes; + } while (str_length); + return totalbytes; } static void sapi_webjames_send_header(sapi_header_struct *sapi_header, void *server_context TSRMLS_DC) /*send an HTTP header*/ { + char *header = sapi_header->header; + int len = sapi_header->header_len; if (WG(conn)->flags.outputheaders) { - if (sapi_header) - webjames_writebuffer(WG(conn), sapi_header->header, sapi_header->header_len); + while (sapi_header && len > 0) { + int bytes; + bytes = webjames_writebuffer(WG(conn), header, len); + if (bytes<0) { + PG(connection_status) = PHP_CONNECTION_ABORTED; + if (!PG(ignore_user_abort)) { + zend_bailout(); + } + return; + } + header += bytes; + len -= bytes; + } webjames_writestring(WG(conn), "\r\n"); } } |
