diff options
Diffstat (limited to 'sapi')
35 files changed, 280 insertions, 191 deletions
diff --git a/sapi/apache/mod_php5.c b/sapi/apache/mod_php5.c index a78b8dc913..04ff6e5d30 100644 --- a/sapi/apache/mod_php5.c +++ b/sapi/apache/mod_php5.c @@ -567,7 +567,7 @@ static void init_request_info(TSRMLS_D) static int php_apache_alter_ini_entries(php_per_dir_entry *per_dir_entry TSRMLS_DC) { zend_string *key = STR_INIT(per_dir_entry->key, per_dir_entry->key_length, 0); - zend_alter_ini_entry(key, per_dir_entry->value, per_dir_entry->value_length, per_dir_entry->type, per_dir_entry->htaccess?PHP_INI_STAGE_HTACCESS:PHP_INI_STAGE_ACTIVATE); + zend_alter_ini_entry_chars(key, per_dir_entry->value, per_dir_entry->value_length, per_dir_entry->type, per_dir_entry->htaccess?PHP_INI_STAGE_HTACCESS:PHP_INI_STAGE_ACTIVATE); STR_RELEASE(key); return 0; } diff --git a/sapi/apache2handler/apache_config.c b/sapi/apache2handler/apache_config.c index 5302afcf18..09d42b5440 100644 --- a/sapi/apache2handler/apache_config.c +++ b/sapi/apache2handler/apache_config.c @@ -192,7 +192,7 @@ void apply_config(void *dummy) ZEND_HASH_FOREACH_STR_KEY_PTR(&d->config, str, data) { phpapdebug((stderr, "APPLYING (%s)(%s)\n", str, data->value)); - if (zend_alter_ini_entry(str, data->value, data->value_len, data->status, data->htaccess?PHP_INI_STAGE_HTACCESS:PHP_INI_STAGE_ACTIVATE) == FAILURE) { + if (zend_alter_ini_entry_chars(str, data->value, data->value_len, data->status, data->htaccess?PHP_INI_STAGE_HTACCESS:PHP_INI_STAGE_ACTIVATE) == FAILURE) { phpapdebug((stderr, "..FAILED\n")); } } ZEND_HASH_FOREACH_END(); diff --git a/sapi/apache2handler/config.m4 b/sapi/apache2handler/config.m4 index 02f8a0b3ad..a0080a654a 100644 --- a/sapi/apache2handler/config.m4 +++ b/sapi/apache2handler/config.m4 @@ -100,7 +100,7 @@ if test "$PHP_APXS2" != "no"; then MH_BUNDLE_FLAGS="-bundle -bundle_loader $APXS_HTTPD $MH_BUNDLE_FLAGS" PHP_SUBST(MH_BUNDLE_FLAGS) PHP_SELECT_SAPI(apache2handler, bundle, mod_php5.c sapi_apache2.c apache_config.c php_functions.c, $APACHE_CFLAGS) - SAPI_SHARED=libs/libphp5.so + SAPI_SHARED=libs/libphp7.so INSTALL_IT="$INSTALL_IT $SAPI_SHARED" ;; *beos*) diff --git a/sapi/apache2handler/php_apache.h b/sapi/apache2handler/php_apache.h index 34846048b0..f1033c9539 100644 --- a/sapi/apache2handler/php_apache.h +++ b/sapi/apache2handler/php_apache.h @@ -25,6 +25,9 @@ #include "http_config.h" #include "http_core.h" +#include "php.h" +#include "main/php_streams.h" + /* Declare this so we can get to it from outside the sapi_apache2.c file */ extern module AP_MODULE_DECLARE_DATA php5_module; @@ -40,7 +43,7 @@ typedef struct php_struct { #if defined(NETWARE) && defined(CLIB_STAT_PATCH) struct stat_libc finfo; #else - struct stat finfo; + zend_stat_t finfo; #endif /* Whether or not we've processed PHP in the output filters yet. */ int request_processed; diff --git a/sapi/apache2handler/php_functions.c b/sapi/apache2handler/php_functions.c index 4bc8fe8872..084f411c2f 100644 --- a/sapi/apache2handler/php_functions.c +++ b/sapi/apache2handler/php_functions.c @@ -72,7 +72,7 @@ static request_rec *php_apache_lookup_uri(char *filename TSRMLS_DC) PHP_FUNCTION(virtual) { char *filename; - int filename_len; + size_t filename_len; request_rec *rr; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) { @@ -119,7 +119,7 @@ PHP_FUNCTION(apache_lookup_uri) { request_rec *rr; char *filename; - int filename_len; + size_t filename_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) { return; @@ -222,7 +222,7 @@ PHP_FUNCTION(apache_note) { php_struct *ctx; char *note_name, *note_val = NULL; - int note_name_len, note_val_len; + size_t note_name_len, note_val_len; char *old_note_val=NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", ¬e_name, ¬e_name_len, ¬e_val, ¬e_val_len) == FAILURE) { @@ -254,7 +254,7 @@ PHP_FUNCTION(apache_setenv) { php_struct *ctx; char *variable=NULL, *string_val=NULL; - int variable_len, string_val_len; + size_t variable_len, string_val_len; zend_bool walk_to_top = 0; int arg_count = ZEND_NUM_ARGS(); request_rec *r; diff --git a/sapi/apache2handler/sapi_apache2.c b/sapi/apache2handler/sapi_apache2.c index ebcc3e9bc9..d39a25a74e 100644 --- a/sapi/apache2handler/sapi_apache2.c +++ b/sapi/apache2handler/sapi_apache2.c @@ -72,8 +72,8 @@ /* A way to specify the location of the php.ini dir in an apache directive */ char *apache2_php_ini_path_override = NULL; -static int -php_apache_sapi_ub_write(const char *str, uint str_length TSRMLS_DC) +static size_t +php_apache_sapi_ub_write(const char *str, size_t str_length TSRMLS_DC) { request_rec *r; php_struct *ctx; @@ -180,8 +180,8 @@ php_apache_sapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) return SAPI_HEADER_SENT_SUCCESSFULLY; } -static int -php_apache_sapi_read_post(char *buf, uint count_bytes TSRMLS_DC) +static apr_size_t +php_apache_sapi_read_post(char *buf, size_t count_bytes TSRMLS_DC) { apr_size_t len, tlen=0; php_struct *ctx = SG(server_context); @@ -212,7 +212,7 @@ php_apache_sapi_read_post(char *buf, uint count_bytes TSRMLS_DC) return tlen; } -static struct stat* +static zend_stat_t* php_apache_sapi_get_stat(TSRMLS_D) { php_struct *ctx = SG(server_context); @@ -270,18 +270,18 @@ 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; + size_t new_val_len; APR_ARRAY_FOREACH_OPEN(arr, key, val) if (!val) { val = ""; } - if (sapi_module.input_filter(PARSE_SERVER, key, &val, strlen(val), (unsigned int *)&new_val_len TSRMLS_CC)) { + if (sapi_module.input_filter(PARSE_SERVER, key, &val, strlen(val), (size_t *)&new_val_len TSRMLS_CC)) { php_register_variable_safe(key, val, new_val_len, track_vars_array TSRMLS_CC); } APR_ARRAY_FOREACH_CLOSE() - if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &ctx->r->uri, strlen(ctx->r->uri), (unsigned int *)&new_val_len TSRMLS_CC)) { + if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &ctx->r->uri, strlen(ctx->r->uri), (size_t *)&new_val_len TSRMLS_CC)) { php_register_variable_safe("PHP_SELF", ctx->r->uri, new_val_len, track_vars_array TSRMLS_CC); } } diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index ff3889dd6c..be02aac17a 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -159,6 +159,8 @@ static const opt_struct OPTIONS[] = { }; typedef struct _php_cgi_globals_struct { + HashTable user_config_cache; + char *redirect_status_env; zend_bool rfc2616_headers; zend_bool nph; zend_bool check_shebang_line; @@ -166,11 +168,9 @@ typedef struct _php_cgi_globals_struct { zend_bool force_redirect; zend_bool discard_path; zend_bool fcgi_logging; - char *redirect_status_env; #ifdef PHP_WIN32 zend_bool impersonate; #endif - HashTable user_config_cache; } php_cgi_globals_struct; /* {{{ user_config_cache @@ -274,7 +274,7 @@ static void print_extensions(TSRMLS_D) static inline size_t sapi_cgi_single_write(const char *str, uint str_length TSRMLS_DC) { #ifdef PHP_WRITE_STDOUT - long ret; + int ret; ret = write(STDOUT_FILENO, str, str_length); if (ret <= 0) return 0; @@ -287,10 +287,10 @@ static inline size_t sapi_cgi_single_write(const char *str, uint str_length TSRM #endif } -static int sapi_cgi_ub_write(const char *str, uint str_length TSRMLS_DC) +static size_t sapi_cgi_ub_write(const char *str, size_t str_length TSRMLS_DC) { const char *ptr = str; - uint remaining = str_length; + size_t remaining = str_length; size_t ret; while (remaining > 0) { @@ -306,14 +306,14 @@ static int sapi_cgi_ub_write(const char *str, uint str_length TSRMLS_DC) return str_length; } -static int sapi_fcgi_ub_write(const char *str, uint str_length TSRMLS_DC) +static size_t sapi_fcgi_ub_write(const char *str, size_t str_length TSRMLS_DC) { const char *ptr = str; - uint remaining = str_length; + size_t remaining = str_length; fcgi_request *request = (fcgi_request*) SG(server_context); while (remaining > 0) { - long ret = fcgi_write(request, FCGI_STDOUT, ptr, remaining); + zend_long ret = fcgi_write(request, FCGI_STDOUT, ptr, remaining); if (ret <= 0) { php_handle_aborted_connection(); @@ -505,9 +505,9 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) # define STDIN_FILENO 0 #endif -static int sapi_cgi_read_post(char *buffer, uint count_bytes TSRMLS_DC) +static size_t sapi_cgi_read_post(char *buffer, size_t count_bytes TSRMLS_DC) { - uint read_bytes = 0; + size_t read_bytes = 0; int tmp_read_bytes; count_bytes = MIN(count_bytes, SG(request_info).content_length - SG(read_post_bytes)); @@ -521,9 +521,9 @@ static int sapi_cgi_read_post(char *buffer, uint count_bytes TSRMLS_DC) return read_bytes; } -static int sapi_fcgi_read_post(char *buffer, uint count_bytes TSRMLS_DC) +static size_t sapi_fcgi_read_post(char *buffer, size_t count_bytes TSRMLS_DC) { - uint read_bytes = 0; + size_t read_bytes = 0; int tmp_read_bytes; fcgi_request *request = (fcgi_request*) SG(server_context); size_t remaining = SG(request_info).content_length - SG(read_post_bytes); @@ -622,7 +622,7 @@ static void cgi_php_load_env_var(char *var, unsigned int var_len, char *val, uns { zval *array_ptr = (zval*)arg; int filter_arg = (Z_ARR_P(array_ptr) == Z_ARR(PG(http_globals)[TRACK_VARS_ENV]))?PARSE_ENV:PARSE_SERVER; - unsigned int new_val_len; + size_t 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); @@ -658,7 +658,7 @@ static 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 php_self_len; + size_t php_self_len; char *php_self; /* In CGI mode, we consider the environment to be a part of the server @@ -1184,7 +1184,7 @@ static void init_request_info(fcgi_request *request TSRMLS_DC) #endif if (CGIG(fix_pathinfo)) { - struct stat st; + zend_stat_t st; char *real_path = NULL; char *env_redirect_url = CGI_GETENV("REDIRECT_URL"); char *env_document_root = CGI_GETENV("DOCUMENT_ROOT"); @@ -1238,7 +1238,7 @@ static void init_request_info(fcgi_request *request TSRMLS_DC) while ((ptr = strrchr(pt, '/')) || (ptr = strrchr(pt, '\\'))) { *ptr = 0; - if (stat(pt, &st) == 0 && S_ISREG(st.st_mode)) { + if (zend_stat(pt, &st) == 0 && S_ISREG(st.st_mode)) { /* * okay, we found the base script! * work out how many chars we had to strip off; @@ -1587,7 +1587,7 @@ PHP_FUNCTION(apache_request_headers) /* {{{ */ char buf[128]; char **env, *p, *q, *var, *val, *t = buf; size_t alloc_size = sizeof(buf); - unsigned long var_len; + zend_ulong var_len; for (env = environ; env != NULL && *env != NULL; env++) { val = strchr(*env, '='); @@ -1751,6 +1751,7 @@ int main(int argc, char *argv[]) char *bindpath = NULL; int fcgi_fd = 0; fcgi_request *request = NULL; + int warmup_repeats = 0; int repeats = 1; int benchmark = 0; #if HAVE_GETTIMEOFDAY @@ -2094,7 +2095,15 @@ consult the installation file that came with this distribution, or visit \n\ switch (c) { case 'T': benchmark = 1; - repeats = atoi(php_optarg); + { + char *comma = strchr(php_optarg, ','); + if (comma) { + warmup_repeats = atoi(php_optarg); + repeats = atoi(comma + 1); + } else { + repeats = atoi(php_optarg); + } + } #ifdef HAVE_GETTIMEOFDAY gettimeofday(&start, NULL); #else @@ -2130,7 +2139,6 @@ consult the installation file that came with this distribution, or visit \n\ while (!fastcgi || fcgi_accept_request(request) >= 0) { SG(server_context) = fastcgi ? (void *) request : (void *) 1; init_request_info(request TSRMLS_CC); - CG(interactive) = 0; if (!cgi && !fastcgi) { while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) { @@ -2138,7 +2146,6 @@ consult the installation file that came with this distribution, or visit \n\ case 'a': /* interactive mode */ printf("Interactive mode enabled\n\n"); - CG(interactive) = 1; break; case 'C': /* don't chdir to the script directory */ @@ -2398,8 +2405,8 @@ consult the installation file that came with this distribution, or visit \n\ /* handle situations where line is terminated by \r\n */ if (c == '\r') { if (fgetc(file_handle.handle.fp) != '\n') { - long pos = ftell(file_handle.handle.fp); - fseek(file_handle.handle.fp, pos - 1, SEEK_SET); + zend_long pos = zend_ftell(file_handle.handle.fp); + zend_fseek(file_handle.handle.fp, pos - 1, SEEK_SET); } } CG(start_lineno) = 2; @@ -2416,7 +2423,7 @@ consult the installation file that came with this distribution, or visit \n\ /* handle situations where line is terminated by \r\n */ if (c == '\r') { if (php_stream_getc((php_stream*)file_handle.handle.stream.handle) != '\n') { - long pos = php_stream_tell((php_stream*)file_handle.handle.stream.handle); + zend_off_t pos = php_stream_tell((php_stream*)file_handle.handle.stream.handle); php_stream_seek((php_stream*)file_handle.handle.stream.handle, pos - 1, SEEK_SET); } } @@ -2514,12 +2521,24 @@ fastcgi_request_done: if (!fastcgi) { if (benchmark) { - repeats--; - if (repeats > 0) { - script_file = NULL; - php_optind = orig_optind; - php_optarg = orig_optarg; + if (warmup_repeats) { + warmup_repeats--; + if (!warmup_repeats) { +#ifdef HAVE_GETTIMEOFDAY + gettimeofday(&start, NULL); +#else + time(&start); +#endif + } continue; + } else { + repeats--; + if (repeats > 0) { + script_file = NULL; + php_optind = orig_optind; + php_optarg = orig_optarg; + continue; + } } } break; diff --git a/sapi/cgi/config.w32 b/sapi/cgi/config.w32 index 8d1d431da4..55a2fba48f 100644 --- a/sapi/cgi/config.w32 +++ b/sapi/cgi/config.w32 @@ -4,7 +4,7 @@ ARG_ENABLE('cgi', 'Build CGI version of PHP', 'yes'); if (PHP_CGI == "yes") { - ADD_FLAG("LDFLAGS_CGI", "/stack:8388608"); + ADD_FLAG("LDFLAGS_CGI", "/stack:67108864"); SAPI('cgi', 'cgi_main.c fastcgi.c', 'php-cgi.exe'); ADD_FLAG('LIBS_CGI', 'ws2_32.lib kernel32.lib advapi32.lib'); } diff --git a/sapi/cgi/fastcgi.c b/sapi/cgi/fastcgi.c index afbb7d2a37..c499fa2106 100644 --- a/sapi/cgi/fastcgi.c +++ b/sapi/cgi/fastcgi.c @@ -19,6 +19,7 @@ /* $Id$ */ #include "php.h" +#include "php_network.h" #include "fastcgi.h" #include <string.h> @@ -72,8 +73,6 @@ # 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 @@ -642,7 +641,7 @@ int fcgi_listen(const char *path, int backlog) if (namedPipe == INVALID_HANDLE_VALUE) { return -1; } - listen_socket = _open_osfhandle((long)namedPipe, 0); + listen_socket = _open_osfhandle((intptr_t)namedPipe, 0); if (!is_initialized) { fcgi_init(); } @@ -723,7 +722,7 @@ int fcgi_listen(const char *path, int backlog) #ifdef _WIN32 if (tcp) { - listen_socket = _open_osfhandle((long)listen_socket, 0); + listen_socket = _open_osfhandle((intptr_t)listen_socket, 0); } #else fcgi_setup_signals(); @@ -1112,7 +1111,7 @@ static inline void fcgi_close(fcgi_request *req, int force, int destroy) shutdown(req->fd, 1); /* read the last FCGI_STDIN header (it may be omitted) */ - recv(req->fd, (char *)&buf, sizeof(buf), 0); + recv(req->fd, (char *)(&buf), sizeof(buf), 0); } closesocket(req->fd); } @@ -1122,7 +1121,7 @@ static inline void fcgi_close(fcgi_request *req, int force, int destroy) shutdown(req->fd, 1); /* read the last FCGI_STDIN header (it may be omitted) */ - recv(req->fd, &buf, sizeof(buf), 0); + recv(req->fd, (char *)(&buf), sizeof(buf), 0); } close(req->fd); #endif @@ -1511,7 +1510,7 @@ void fcgi_impersonate(void) void fcgi_set_mgmt_var(const char * name, size_t name_len, const char * value, size_t value_len) { zval zvalue; - ZVAL_NEW_STR(&zvalue, STR_INIT(value, value_len, 1)); + ZVAL_NEW_STR(&zvalue, zend_string_init(value, value_len, 1)); zend_hash_str_add(&fcgi_mgmt_vars, name, name_len, &zvalue); } diff --git a/sapi/cli/cli.h b/sapi/cli/cli.h index dc85893a0b..b04f6c91f0 100644 --- a/sapi/cli/cli.h +++ b/sapi/cli/cli.h @@ -30,11 +30,11 @@ #endif -extern PHP_CLI_API size_t sapi_cli_single_write(const char *str, uint str_length TSRMLS_DC); +extern PHP_CLI_API size_t sapi_cli_single_write(const char *str, size_t str_length TSRMLS_DC); typedef struct { - size_t (*cli_shell_write)(const char *str, uint str_length TSRMLS_DC); - int (*cli_shell_ub_write)(const char *str, uint str_length TSRMLS_DC); + size_t (*cli_shell_write)(const char *str, size_t str_length TSRMLS_DC); + size_t (*cli_shell_ub_write)(const char *str, size_t str_length TSRMLS_DC); int (*cli_shell_run)(TSRMLS_D); } cli_shell_callbacks_t; diff --git a/sapi/cli/config.w32 b/sapi/cli/config.w32 index adcbb2b496..438c9e6d62 100644 --- a/sapi/cli/config.w32 +++ b/sapi/cli/config.w32 @@ -11,11 +11,11 @@ if (PHP_CLI == "yes") { if (PHP_CRT_DEBUG == "yes") { ADD_FLAG("CFLAGS_CLI", "/D PHP_WIN32_DEBUG_HEAP"); } - ADD_FLAG("LDFLAGS_CLI", "/stack:8388608"); + ADD_FLAG("LDFLAGS_CLI", "/stack:67108864"); } if (PHP_CLI_WIN32 == "yes") { SAPI('cli_win32', 'cli_win32.c php_cli_process_title.c ps_title.c', 'php-win.exe'); - ADD_FLAG("LDFLAGS_CLI_WIN32", "/stack:8388608"); + ADD_FLAG("LDFLAGS_CLI_WIN32", "/stack:67108864"); } diff --git a/sapi/cli/php.1.in b/sapi/cli/php.1.in index 4d536df53c..c062f3d20e 100644 --- a/sapi/cli/php.1.in +++ b/sapi/cli/php.1.in @@ -1,24 +1,24 @@ -.TH PHP 1 "2014" "The PHP Group" "Scripting Language" +.TH @program_prefix@php 1 "2014" "The PHP Group" "Scripting Language" .SH NAME -php \- PHP Command Line Interface 'CLI' +@program_prefix@php \- PHP Command Line Interface 'CLI' .P -php-cgi \- PHP Common Gateway Interface 'CGI' command +@program_prefix@php-cgi \- PHP Common Gateway Interface 'CGI' command .SH SYNOPSIS -.B php +.B @program_prefix@php [options] [ .B \-f\fP ] .IR file [[\-\-] .IR args.\|.\|. ] .LP -.B php +.B @program_prefix@php [options] .B \-r .IR code [[\-\-] .IR args.\|.\|. ] .LP -.B php +.B @program_prefix@php [options] [\-B .IR begin_code ] .B \-R @@ -28,7 +28,7 @@ php-cgi \- PHP Common Gateway Interface 'CGI' command [[\-\-] .IR args.\|.\|. ] .LP -.B php +.B @program_prefix@php [options] [\-B .IR begin_code ] .B \-F @@ -38,13 +38,13 @@ php-cgi \- PHP Common Gateway Interface 'CGI' command [[\-\-] .IR args.\|.\|. ] .LP -.B php +.B @program_prefix@php [options] \-\- [ .IR args.\|.\|. ] .LP -\fBphp \fP[options] \fB\-a\fP +\fB@program_prefix@php \fP[options] \fB\-a\fP .LP -.B php +.B @program_prefix@php [options] \-S .IR addr:port [\-t @@ -374,35 +374,35 @@ The standard configuration file will only be used when cannot be found. .SH EXAMPLES .TP 5 -\fIphp \-r 'echo "Hello World\\n";'\fP +\fI@program_prefix@php \-r 'echo "Hello World\\n";'\fP This command simply writes the text "Hello World" to standard out. .TP -\fIphp \-r 'print_r(gd_info());'\fP +\fI@program_prefix@php \-r 'print_r(gd_info());'\fP This shows the configuration of your gd extension. You can use this to easily check which image formats you can use. If you have any dynamic modules you may want to use the same ini file that php uses when executed from your webserver. There are more extensions which have such a function. For dba use: .RS -\fIphp \-r 'print_r(dba_handlers(1));'\fP +\fI@program_prefix@php \-r 'print_r(dba_handlers(1));'\fP .RE .TP -\fIphp \-R 'echo strip_tags($argn)."\\n";'\fP +\fI@program_prefix@php \-R 'echo strip_tags($argn)."\\n";'\fP This PHP command strips off the HTML tags line by line and outputs the result. To see how it works you can first look at the following PHP command \'\fIphp \-d html_errors=1 \-i\fP\' which uses PHP to output HTML formatted configuration information. If you then combine those two \'\fIphp \.\.\.|php \.\.\.\fP\' you'll see what happens. .TP -\fIphp \-E 'echo "Lines: $argi\\n";'\fP +\fI@program_prefix@php \-E 'echo "Lines: $argi\\n";'\fP Using this PHP command you can count the lines being input. .TP -\fIphp \-R '@$l+=count(file($argn));' \-E 'echo "Lines:$l\\n";'\fP +\fI@program_prefix@php \-R '@$l+=count(file($argn));' \-E 'echo "Lines:$l\\n";'\fP In this example PHP expects each input line being a file. It counts all lines of the files specified by each input line and shows the summarized result. You may combine this with tools like find and change the php scriptlet. .TP -\fIphp \-R 'echo "$argn\\n"; fgets(STDIN);'\fP +\fI@program_prefix@php \-R 'echo "$argn\\n"; fgets(STDIN);'\fP Since you have access to STDIN from within \-B \-R \-F and \-E you can skip certain input lines with your code. But note that in such cases $argi only counts the lines being processed by php itself. Having read this you will diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c index ec76f37715..f3eec80283 100644 --- a/sapi/cli/php_cli.c +++ b/sapi/cli/php_cli.c @@ -252,10 +252,10 @@ static inline int sapi_cli_select(int fd TSRMLS_DC) return ret != -1; } -PHP_CLI_API size_t sapi_cli_single_write(const char *str, uint str_length TSRMLS_DC) /* {{{ */ +PHP_CLI_API size_t sapi_cli_single_write(const char *str, size_t str_length TSRMLS_DC) /* {{{ */ { #ifdef PHP_WRITE_STDOUT - long ret; + zend_long ret; #else size_t ret; #endif @@ -285,10 +285,10 @@ PHP_CLI_API size_t sapi_cli_single_write(const char *str, uint str_length TSRMLS } /* }}} */ -static int sapi_cli_ub_write(const char *str, uint str_length TSRMLS_DC) /* {{{ */ +static size_t sapi_cli_ub_write(const char *str, size_t str_length TSRMLS_DC) /* {{{ */ { const char *ptr = str; - uint remaining = str_length; + size_t remaining = str_length; size_t ret; if (!str_length) { @@ -296,7 +296,7 @@ static int sapi_cli_ub_write(const char *str, uint str_length TSRMLS_DC) /* {{{ } if (cli_shell_callbacks.cli_shell_ub_write) { - int ub_wrote; + size_t ub_wrote; ub_wrote = cli_shell_callbacks.cli_shell_ub_write(str, str_length TSRMLS_CC); if (ub_wrote > -1) { return ub_wrote; @@ -338,7 +338,7 @@ static char *script_filename = ""; static void sapi_cli_register_variables(zval *track_vars_array TSRMLS_DC) /* {{{ */ { - unsigned int len; + size_t len; char *docroot = ""; /* In CGI mode, we consider the environment to be a part of the server @@ -425,7 +425,7 @@ static int php_cli_startup(sapi_module_struct *sapi_module) /* {{{ */ /* overwriteable ini defaults must be set in sapi_cli_ini_defaults() */ #define INI_DEFAULT(name,value)\ - ZVAL_NEW_STR(&tmp, STR_INIT(value, sizeof(value)-1, 1));\ + ZVAL_NEW_STR(&tmp, zend_string_init(value, sizeof(value)-1, 1));\ zend_hash_str_update(configuration_hash, name, sizeof(name)-1, &tmp);\ static void sapi_cli_ini_defaults(HashTable *configuration_hash) @@ -581,19 +581,19 @@ static void cli_register_file_handles(TSRMLS_D) /* {{{ */ ZVAL_COPY_VALUE(&ic.value, &zin); ic.flags = CONST_CS; - ic.name = STR_INIT("STDIN", sizeof("STDIN")-1, 1); + ic.name = zend_string_init("STDIN", sizeof("STDIN")-1, 1); ic.module_number = 0; zend_register_constant(&ic TSRMLS_CC); ZVAL_COPY_VALUE(&oc.value, &zout); oc.flags = CONST_CS; - oc.name = STR_INIT("STDOUT", sizeof("STDOUT")-1, 1); + oc.name = zend_string_init("STDOUT", sizeof("STDOUT")-1, 1); oc.module_number = 0; zend_register_constant(&oc TSRMLS_CC); ZVAL_COPY_VALUE(&ec.value, &zerr); ec.flags = CONST_CS; - ec.name = STR_INIT("STDERR", sizeof("STDERR")-1, 1); + ec.name = zend_string_init("STDERR", sizeof("STDERR")-1, 1); ec.module_number = 0; zend_register_constant(&ec TSRMLS_CC); } @@ -627,8 +627,8 @@ static int cli_seek_file_begin(zend_file_handle *file_handle, char *script_file, /* handle situations where line is terminated by \r\n */ if (c == '\r') { if (fgetc(file_handle->handle.fp) != '\n') { - long pos = ftell(file_handle->handle.fp); - fseek(file_handle->handle.fp, pos - 1, SEEK_SET); + zend_long pos = zend_ftell(file_handle->handle.fp); + zend_fseek(file_handle->handle.fp, pos - 1, SEEK_SET); } } *lineno = 2; @@ -902,8 +902,6 @@ static int do_cli(int argc, char **argv TSRMLS_DC) /* {{{ */ fflush(stdout); } - CG(interactive) = interactive; - /* only set script_file if not set already and not in direct mode and not at end of parameter list */ if (argc > php_optind && !script_file @@ -963,9 +961,9 @@ static int do_cli(int argc, char **argv TSRMLS_DC) /* {{{ */ } } - key = STR_INIT("_SERVER", sizeof("_SERVER")-1, 0); + key = zend_string_init("_SERVER", sizeof("_SERVER")-1, 0); zend_is_auto_global(key TSRMLS_CC); - STR_RELEASE(key); + zend_string_release(key); PG(during_request_startup) = 0; switch (behavior) { diff --git a/sapi/cli/php_cli_process_title.c b/sapi/cli/php_cli_process_title.c index 298300f065..24f26f383c 100644 --- a/sapi/cli/php_cli_process_title.c +++ b/sapi/cli/php_cli_process_title.c @@ -31,7 +31,7 @@ PHP_FUNCTION(cli_set_process_title) { char *title = NULL; - int title_len; + size_t title_len; int rc; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &title, &title_len) == FAILURE) { diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c index 09cfd02ec9..88a1010db1 100644 --- a/sapi/cli/php_cli_server.c +++ b/sapi/cli/php_cli_server.c @@ -139,7 +139,7 @@ typedef struct php_cli_server_request { size_t content_len; const char *ext; size_t ext_len; - struct stat sb; + zend_stat_t sb; } php_cli_server_request; typedef struct php_cli_server_chunk { @@ -436,7 +436,7 @@ PHP_FUNCTION(apache_request_headers) /* {{{ */ static void add_response_header(sapi_header_struct *h, zval *return_value TSRMLS_DC) /* {{{ */ { char *s, *p; - int len; + ptrdiff_t len; ALLOCA_FLAG(use_heap) if (h->header_len > 0) { @@ -539,7 +539,7 @@ static int sapi_cli_server_startup(sapi_module_struct *sapi_module) /* {{{ */ return SUCCESS; } /* }}} */ -static int sapi_cli_server_ub_write(const char *str, uint str_length TSRMLS_DC) /* {{{ */ +static size_t sapi_cli_server_ub_write(const char *str, size_t str_length TSRMLS_DC) /* {{{ */ { php_cli_server_client *client = SG(server_context); if (!client) { @@ -619,7 +619,7 @@ static char *sapi_cli_server_read_cookies(TSRMLS_D) /* {{{ */ return val; } /* }}} */ -static int sapi_cli_server_read_post(char *buf, uint count_bytes TSRMLS_DC) /* {{{ */ +static size_t sapi_cli_server_read_post(char *buf, size_t count_bytes TSRMLS_DC) /* {{{ */ { php_cli_server_client *client = SG(server_context); if (client->request.content) { @@ -635,7 +635,7 @@ static int sapi_cli_server_read_post(char *buf, uint count_bytes TSRMLS_DC) /* { static void sapi_cli_server_register_variable(zval *track_vars_array, const char *key, const char *val TSRMLS_DC) /* {{{ */ { char *new_val = (char *)val; - uint new_val_len; + size_t new_val_len; if (sapi_module.input_filter(PARSE_SERVER, (char*)key, &new_val, strlen(val), &new_val_len TSRMLS_CC)) { php_register_variable_safe((char *)key, new_val, new_val_len, track_vars_array TSRMLS_CC); } @@ -789,7 +789,7 @@ static int php_cli_server_poller_ctor(php_cli_server_poller *poller) /* {{{ */ return SUCCESS; } /* }}} */ -static void php_cli_server_poller_add(php_cli_server_poller *poller, int mode, int fd) /* {{{ */ +static void php_cli_server_poller_add(php_cli_server_poller *poller, int mode, php_socket_t fd) /* {{{ */ { if (mode & POLLIN) { PHP_SAFE_FD_SET(fd, &poller->rfds); @@ -802,7 +802,7 @@ static void php_cli_server_poller_add(php_cli_server_poller *poller, int mode, i } } /* }}} */ -static void php_cli_server_poller_remove(php_cli_server_poller *poller, int mode, int fd) /* {{{ */ +static void php_cli_server_poller_remove(php_cli_server_poller *poller, int mode, php_socket_t fd) /* {{{ */ { if (mode & POLLIN) { PHP_SAFE_FD_CLR(fd, &poller->rfds); @@ -830,7 +830,7 @@ static int php_cli_server_poller_poll(php_cli_server_poller *poller, struct time return php_select(poller->max_fd + 1, &poller->active.rfds, &poller->active.wfds, NULL, tv); } /* }}} */ -static int php_cli_server_poller_iter_on_active(php_cli_server_poller *poller, void *opaque, int(*callback)(void *, int fd, int events)) /* {{{ */ +static int php_cli_server_poller_iter_on_active(php_cli_server_poller *poller, void *opaque, int(*callback)(void *, php_socket_t fd, int events)) /* {{{ */ { int retval = SUCCESS; #ifdef PHP_WIN32 @@ -1209,7 +1209,7 @@ static void php_cli_server_logf(const char *format TSRMLS_DC, ...) /* {{{ */ static int php_network_listen_socket(const char *host, int *port, int socktype, int *af, socklen_t *socklen, zend_string **errstr TSRMLS_DC) /* {{{ */ { - int retval = SOCK_ERR; + php_socket_t retval = SOCK_ERR; int err = 0; struct sockaddr *sa = NULL, **p, **sal; @@ -1377,7 +1377,7 @@ static void php_cli_server_request_dtor(php_cli_server_request *req) /* {{{ */ static void php_cli_server_request_translate_vpath(php_cli_server_request *request, const char *document_root, size_t document_root_len) /* {{{ */ { - struct stat sb; + zend_stat_t sb; static const char *index_files[] = { "index.php", "index.html", NULL }; char *buf = safe_pemalloc(1, request->vpath_len, 1 + document_root_len + 1 + sizeof("index.html"), 1); char *p = buf, *prev_path = NULL, *q, *vpath; @@ -1414,7 +1414,7 @@ static void php_cli_server_request_translate_vpath(php_cli_server_request *reque *p = '\0'; q = p; while (q > buf) { - if (!stat(buf, &sb)) { + if (!zend_stat(buf, &sb)) { if (sb.st_mode & S_IFDIR) { const char **file = index_files; if (q[-1] != DEFAULT_SLASH) { @@ -1423,7 +1423,7 @@ static void php_cli_server_request_translate_vpath(php_cli_server_request *reque while (*file) { size_t l = strlen(*file); memmove(q, *file, l + 1); - if (!stat(buf, &sb) && (sb.st_mode & S_IFREG)) { + if (!zend_stat(buf, &sb) && (sb.st_mode & S_IFREG)) { q += l; break; } @@ -1613,12 +1613,12 @@ static int php_cli_server_client_read_request_on_header_value(php_http_parser *p } { /* strip off the colon */ - zend_string *orig_header_name = STR_INIT(client->current_header_name, client->current_header_name_len, 1); + zend_string *orig_header_name = zend_string_init(client->current_header_name, client->current_header_name_len, 1); char *lc_header_name = zend_str_tolower_dup(client->current_header_name, client->current_header_name_len); zend_hash_str_add_ptr(&client->request.headers, lc_header_name, client->current_header_name_len, value); zend_hash_add_ptr(&client->request.headers_original_case, orig_header_name, value); efree(lc_header_name); - STR_RELEASE(orig_header_name); + zend_string_release(orig_header_name); } if (client->current_header_name_allocated) { @@ -1785,7 +1785,7 @@ static void destroy_request_info(sapi_request_info *request_info) /* {{{ */ { } /* }}} */ -static int php_cli_server_client_ctor(php_cli_server_client *client, php_cli_server *server, int client_sock, struct sockaddr *addr, socklen_t addr_len TSRMLS_DC) /* {{{ */ +static int php_cli_server_client_ctor(php_cli_server_client *client, php_cli_server *server, php_socket_t client_sock, struct sockaddr *addr, socklen_t addr_len TSRMLS_DC) /* {{{ */ { client->server = server; client->sock = client_sock; @@ -1797,7 +1797,7 @@ static int php_cli_server_client_ctor(php_cli_server_client *client, php_cli_ser php_network_populate_name_from_sockaddr(addr, addr_len, &addr_str, NULL, 0 TSRMLS_CC); client->addr_str = pestrndup(addr_str->val, addr_str->len, 1); client->addr_str_len = addr_str->len; - STR_RELEASE(addr_str); + zend_string_release(addr_str); } php_http_parser_init(&client->parser, PHP_HTTP_REQUEST); client->request_read = 0; @@ -1919,14 +1919,14 @@ static int php_cli_server_send_error_page(php_cli_server *server, php_cli_server if (errstr) { pefree(errstr, 1); } - STR_FREE(escaped_request_uri); + zend_string_free(escaped_request_uri); return SUCCESS; fail: if (errstr) { pefree(errstr, 1); } - STR_FREE(escaped_request_uri); + zend_string_free(escaped_request_uri); return FAILURE; } /* }}} */ @@ -2233,7 +2233,7 @@ static int php_cli_server_ctor(php_cli_server *server, const char *addr, const c if (server_sock == SOCK_ERR) { php_cli_server_logf("Failed to listen on %s:%d (reason: %s)" TSRMLS_CC, host, port, errstr ? errstr->val : "?"); if (errstr) { - STR_RELEASE(errstr); + zend_string_release(errstr); } retval = FAILURE; goto out; @@ -2361,7 +2361,7 @@ typedef struct php_cli_server_do_event_for_each_fd_callback_params { int(*whandler)(php_cli_server*, php_cli_server_client* TSRMLS_DC); } php_cli_server_do_event_for_each_fd_callback_params; -static int php_cli_server_do_event_for_each_fd_callback(void *_params, int fd, int event) /* {{{ */ +static int php_cli_server_do_event_for_each_fd_callback(void *_params, php_socket_t fd, int event) /* {{{ */ { php_cli_server_do_event_for_each_fd_callback_params *params = _params; #ifdef ZTS @@ -2487,9 +2487,9 @@ int do_cli_server(int argc, char **argv TSRMLS_DC) /* {{{ */ } if (document_root) { - struct stat sb; + zend_stat_t sb; - if (stat(document_root, &sb)) { + if (zend_stat(document_root, &sb)) { fprintf(stderr, "Directory %s does not exist.\n", document_root); return 1; } diff --git a/sapi/cli/ps_title.c b/sapi/cli/ps_title.c index 53cd5fc9a0..0be94e3eb0 100644 --- a/sapi/cli/ps_title.c +++ b/sapi/cli/ps_title.c @@ -311,7 +311,7 @@ const char* ps_title_errno(int rc) #ifdef PS_USE_WIN32 case PS_TITLE_WINDOWS_ERROR: - sprintf(windows_error_details, "Windows error code: %d", GetLastError()); + sprintf(windows_error_details, "Windows error code: %u", GetLastError()); return windows_error_details; #endif } diff --git a/sapi/embed/php_embed.c b/sapi/embed/php_embed.c index b4fc5aaf10..230b3a649d 100644 --- a/sapi/embed/php_embed.c +++ b/sapi/embed/php_embed.c @@ -44,10 +44,10 @@ static int php_embed_deactivate(TSRMLS_D) return SUCCESS; } -static inline size_t php_embed_single_write(const char *str, uint str_length) +static inline size_t php_embed_single_write(const char *str, size_t str_length) { #ifdef PHP_WRITE_STDOUT - long ret; + zend_long ret; ret = write(STDOUT_FILENO, str, str_length); if (ret <= 0) return 0; @@ -61,10 +61,10 @@ static inline size_t php_embed_single_write(const char *str, uint str_length) } -static int php_embed_ub_write(const char *str, uint str_length TSRMLS_DC) +static size_t php_embed_ub_write(const char *str, size_t str_length TSRMLS_DC) { const char *ptr = str; - uint remaining = str_length; + size_t remaining = str_length; size_t ret; while (remaining > 0) { diff --git a/sapi/fpm/fpm/fastcgi.c b/sapi/fpm/fpm/fastcgi.c index 8fbdd36a24..39621b839c 100644 --- a/sapi/fpm/fpm/fastcgi.c +++ b/sapi/fpm/fpm/fastcgi.c @@ -1064,13 +1064,13 @@ char* fcgi_putenv(fcgi_request *req, char* var, int var_len, char* val) void fcgi_set_mgmt_var(const char * name, size_t name_len, const char * value, size_t value_len) { zval zvalue; - ZVAL_STR(&zvalue, STR_INIT(value, value_len, 1)); + ZVAL_STR(&zvalue, zend_string_init(value, value_len, 1)); zend_hash_str_add(&fcgi_mgmt_vars, name, name_len, &zvalue); } void fcgi_free_mgmt_var_cb(zval *zv) { - STR_FREE(Z_STR_P(zv)); + zend_string_free(Z_STR_P(zv)); } char *fcgi_get_last_client_ip() /* {{{ */ diff --git a/sapi/fpm/fpm/fpm_conf.c b/sapi/fpm/fpm/fpm_conf.c index 34e0480101..18ddccb300 100644 --- a/sapi/fpm/fpm/fpm_conf.c +++ b/sapi/fpm/fpm/fpm_conf.c @@ -1476,7 +1476,8 @@ static void fpm_conf_ini_parser(zval *arg1, zval *arg2, zval *arg3, int callback int fpm_conf_load_ini_file(char *filename TSRMLS_DC) /* {{{ */ { int error = 0; - char buf[1024+1]; + char *buf = NULL, *newbuf = NULL; + int bufsize = 0; int fd, n; int nb_read = 1; char c = '*'; @@ -1503,19 +1504,36 @@ int fpm_conf_load_ini_file(char *filename TSRMLS_DC) /* {{{ */ ini_lineno = 0; while (nb_read > 0) { int tmp; - memset(buf, 0, sizeof(char) * (1024 + 1)); - for (n = 0; n < 1024 && (nb_read = read(fd, &c, sizeof(char))) == sizeof(char) && c != '\n'; n++) { + ini_lineno++; + ini_filename = filename; + for (n = 0; (nb_read = read(fd, &c, sizeof(char))) == sizeof(char) && c != '\n'; n++) { + if (n == bufsize) { + bufsize += 1024; + newbuf = (char*) realloc(buf, sizeof(char) * (bufsize + 2)); + if (newbuf == NULL) { + ini_recursion--; + close(fd); + free(buf); + return -1; + } + buf = newbuf; + } + buf[n] = c; } + if (n == 0) { + continue; + } + /* always append newline and null terminate */ buf[n++] = '\n'; - ini_lineno++; - ini_filename = filename; + buf[n] = '\0'; tmp = zend_parse_ini_string(buf, 1, ZEND_INI_SCANNER_NORMAL, (zend_ini_parser_cb_t)fpm_conf_ini_parser, &error TSRMLS_CC); ini_filename = filename; if (error || tmp == FAILURE) { if (ini_include) free(ini_include); ini_recursion--; close(fd); + free(buf); return -1; } if (ini_include) { @@ -1527,16 +1545,17 @@ int fpm_conf_load_ini_file(char *filename TSRMLS_DC) /* {{{ */ free(tmp); ini_recursion--; close(fd); + free(buf); return -1; } free(tmp); } } + free(buf); ini_recursion--; close(fd); return ret; - } /* }}} */ diff --git a/sapi/fpm/fpm/fpm_main.c b/sapi/fpm/fpm/fpm_main.c index 5e9fa89cc8..d130befdb5 100644 --- a/sapi/fpm/fpm/fpm_main.c +++ b/sapi/fpm/fpm/fpm_main.c @@ -298,7 +298,7 @@ static inline size_t sapi_cgibin_single_write(const char *str, uint str_length T #endif } -static int sapi_cgibin_ub_write(const char *str, uint str_length TSRMLS_DC) +static size_t sapi_cgibin_ub_write(const char *str, size_t str_length TSRMLS_DC) { const char *ptr = str; uint remaining = str_length; @@ -497,7 +497,7 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) # define STDIN_FILENO 0 #endif -static int sapi_cgi_read_post(char *buffer, uint count_bytes TSRMLS_DC) +static size_t sapi_cgi_read_post(char *buffer, size_t count_bytes TSRMLS_DC) { uint read_bytes = 0; int tmp_read_bytes; @@ -598,7 +598,7 @@ void cgi_php_import_environment_variables(zval *array_ptr TSRMLS_DC) ? PARSE_ENV : PARSE_SERVER; ZEND_HASH_FOREACH_STR_KEY_PTR(request->env, var, val) { - unsigned int new_val_len; + size_t new_val_len; if (var && sapi_module.input_filter(filter_arg, var->val, &val, strlen(val), &new_val_len TSRMLS_CC)) { php_register_variable_safe(var->val, val, new_val_len, array_ptr TSRMLS_CC); @@ -608,7 +608,7 @@ 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 php_self_len; + size_t php_self_len; char *php_self; /* In CGI mode, we consider the environment to be a part of the server @@ -1226,6 +1226,17 @@ static void init_request_info(TSRMLS_D) SG(request_info).request_uri = orig_script_name; } path_info[0] = old; + } else if (apache_was_here && env_script_name) { + /* Using mod_proxy_fcgi and ProxyPass, apache cannot set PATH_INFO + * As we can extract PATH_INFO from PATH_TRANSLATED + * it is probably also in SCRIPT_NAME and need to be removed + */ + int snlen = strlen(env_script_name); + if (snlen>slen && !strcmp(env_script_name+snlen-slen, path_info)) { + _sapi_cgibin_putenv("ORIG_SCRIPT_NAME", orig_script_name TSRMLS_CC); + env_script_name[snlen-slen] = 0; + SG(request_info).request_uri = _sapi_cgibin_putenv("SCRIPT_NAME", env_script_name TSRMLS_CC); + } } env_path_info = _sapi_cgibin_putenv("PATH_INFO", path_info TSRMLS_CC); } @@ -1866,7 +1877,6 @@ consult the installation file that came with this distribution, or visit \n\ request_body_fd = -1; SG(server_context) = (void *) &request; init_request_info(TSRMLS_C); - CG(interactive) = 0; char *primary_script = NULL; fpm_request_info(); diff --git a/sapi/fpm/fpm/fpm_php.c b/sapi/fpm/fpm/fpm_php.c index 7112cb923b..e0de217c00 100644 --- a/sapi/fpm/fpm/fpm_php.c +++ b/sapi/fpm/fpm/fpm_php.c @@ -26,22 +26,21 @@ static char **limit_extensions = NULL; static int fpm_php_zend_ini_alter_master(char *name, int name_length, char *new_value, int new_value_length, int mode, int stage TSRMLS_DC) /* {{{ */ { zend_ini_entry *ini_entry; - char *duplicate; + zend_string *duplicate; if ((ini_entry = zend_hash_str_find_ptr(EG(ini_directives), name, name_length))) { return FAILURE; } - duplicate = strdup(new_value); + duplicate = zend_string_init(new_value, new_value_length, 1); if (!ini_entry->on_modify - || ini_entry->on_modify(ini_entry, duplicate, new_value_length, + || ini_entry->on_modify(ini_entry, duplicate, ini_entry->mh_arg1, ini_entry->mh_arg2, ini_entry->mh_arg3, stage TSRMLS_CC) == SUCCESS) { ini_entry->value = duplicate; - ini_entry->value_length = new_value_length; ini_entry->modifiable = mode; } else { - free(duplicate); + zend_string_release(duplicate); } return SUCCESS; @@ -92,7 +91,7 @@ int fpm_php_apply_defines_ex(struct key_value_s *kv, int mode) /* {{{ */ return Z_TYPE(zv) == IS_TRUE; } - if (fpm_php_zend_ini_alter_master(name, name_len+1, value, value_len, mode, PHP_INI_STAGE_ACTIVATE TSRMLS_CC) == FAILURE) { + if (fpm_php_zend_ini_alter_master(name, name_len, value, value_len, mode, PHP_INI_STAGE_ACTIVATE TSRMLS_CC) == FAILURE) { return -1; } diff --git a/sapi/fpm/fpm/fpm_status.c b/sapi/fpm/fpm/fpm_status.c index e447648462..fa3fc763a5 100644 --- a/sapi/fpm/fpm/fpm_status.c +++ b/sapi/fpm/fpm/fpm_status.c @@ -127,7 +127,7 @@ int fpm_status_handle_request(TSRMLS_D) /* {{{ */ } /* full status ? */ - _GET_str = STR_INIT("_GET", sizeof("_GET")-1, 0); + _GET_str = zend_string_init("_GET", sizeof("_GET")-1, 0); full = (fpm_php_get_string_from_table(_GET_str, "full" TSRMLS_CC) != NULL); short_syntax = short_post = NULL; full_separator = full_pre = full_syntax = full_post = NULL; @@ -378,7 +378,7 @@ int fpm_status_handle_request(TSRMLS_D) /* {{{ */ PUTS(buffer); efree(buffer); - STR_RELEASE(_GET_str); + zend_string_release(_GET_str); if (short_post) { PUTS(short_post); @@ -463,7 +463,7 @@ int fpm_status_handle_request(TSRMLS_D) /* {{{ */ efree(buffer); if (tmp_query_string) { - STR_FREE(tmp_query_string); + zend_string_free(tmp_query_string); } } diff --git a/sapi/litespeed/lsapi_main.c b/sapi/litespeed/lsapi_main.c index 3a4ed748e3..3da98b16bc 100644 --- a/sapi/litespeed/lsapi_main.c +++ b/sapi/litespeed/lsapi_main.c @@ -195,15 +195,22 @@ static char *sapi_lsapi_getenv( char * name, size_t name_len TSRMLS_DC ) /* }}} */ -/* + + static int add_variable( const char * pKey, int keyLen, const char * pValue, int valLen, void * arg ) { - php_register_variable_safe((char *)pKey, (char *)pValue, valLen, (zval *)arg TSRMLS_CC); - return 1; + int filter_arg = (arg == PG(http_globals)[TRACK_VARS_ENV])?PARSE_ENV:PARSE_SERVER; + char * new_val = (char *) pValue; + unsigned int new_val_len; + + if (sapi_module.input_filter(filter_arg, (char *)pKey, &new_val, valLen, &new_val_len TSRMLS_CC)) { + php_register_variable_safe((char *)pKey, new_val, new_val_len, (zval *)arg ); + } + return 1; } -*/ +/* static int add_variable( const char * pKey, int keyLen, const char * pValue, int valLen, void * arg ) { @@ -222,6 +229,55 @@ static int add_variable( const char * pKey, int keyLen, const char * pValue, int #endif return 1; } +*/ + +static void litespeed_php_import_environment_variables(zval *array_ptr TSRMLS_DC) +{ + char buf[128]; + char **env, *p, *t = buf; + size_t alloc_size = sizeof(buf); + unsigned long nlen; /* ptrdiff_t is not portable */ + + if (PG(http_globals)[TRACK_VARS_ENV] && + array_ptr != PG(http_globals)[TRACK_VARS_ENV] && + Z_TYPE_P(PG(http_globals)[TRACK_VARS_ENV]) == IS_ARRAY && + zend_hash_num_elements(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_ENV])) > 0 + ) { + zval_dtor(array_ptr); + *array_ptr = *PG(http_globals)[TRACK_VARS_ENV]; + INIT_PZVAL(array_ptr); + zval_copy_ctor(array_ptr); + return; + } else if (PG(http_globals)[TRACK_VARS_SERVER] && + array_ptr != PG(http_globals)[TRACK_VARS_SERVER] && + Z_TYPE_P(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY && + zend_hash_num_elements(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER])) > 0 + ) { + zval_dtor(array_ptr); + *array_ptr = *PG(http_globals)[TRACK_VARS_SERVER]; + INIT_PZVAL(array_ptr); + zval_copy_ctor(array_ptr); + return; + } + + for (env = environ; env != NULL && *env != NULL; env++) { + p = strchr(*env, '='); + if (!p) { /* malformed entry? */ + continue; + } + nlen = p - *env; + if (nlen >= alloc_size) { + alloc_size = nlen + 64; + t = (t == buf ? emalloc(alloc_size): erealloc(t, alloc_size)); + } + memcpy(t, *env, nlen); + t[nlen] = '\0'; + add_variable(t, nlen, p + 1, strlen( p + 1 ), array_ptr TSRMLS_CC); + } + if (t != buf && t != NULL) { + efree(t); + } +} #if ((PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 4) || PHP_MAJOR_VERSION < 5) @@ -255,6 +311,8 @@ static void sapi_lsapi_register_variables(zval *track_vars_array TSRMLS_DC) if ( (SG(request_info).request_uri ) ) php_self = (SG(request_info).request_uri ); + litespeed_php_import_environment_variables(track_vars_array TSRMLS_CC); + #if ((PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 4) || PHP_MAJOR_VERSION < 5) if (!PG(magic_quotes_gpc)) { #endif @@ -268,7 +326,6 @@ static void sapi_lsapi_register_variables(zval *track_vars_array TSRMLS_DC) add_variable_magic_quote("PHP_SELF", 8, php_self, strlen( php_self ), track_vars_array ); } #endif - php_import_environment_variables(track_vars_array TSRMLS_CC); } else { php_import_environment_variables(track_vars_array TSRMLS_CC); @@ -370,7 +427,7 @@ static void sapi_lsapi_log_message(char *message TSRMLS_DC) static sapi_module_struct lsapi_sapi_module = { "litespeed", - "LiteSpeed V6.6", + "LiteSpeed V6.7", php_lsapi_startup, /* startup */ php_module_shutdown_wrapper, /* shutdown */ diff --git a/sapi/litespeed/lsapilib.c b/sapi/litespeed/lsapilib.c index 786a3bd20b..aac823fc1c 100644 --- a/sapi/litespeed/lsapilib.c +++ b/sapi/litespeed/lsapilib.c @@ -1912,9 +1912,13 @@ int LSAPI_ForeachOrgHeader_r( LSAPI_Request * pReq, int ret; int count = 0; struct _headerInfo headers[512]; + if ( !pReq || !fn ) return -1; - + + if ( !pReq->m_pHeaderIndex ) + return 0; + for( i = 0; i < H_TRANSFER_ENCODING; ++i ) { if ( pReq->m_pHeaderIndex->m_headerOff[i] ) diff --git a/sapi/milter/php_milter.c b/sapi/milter/php_milter.c index 443fee9dfd..57f8190ec4 100644 --- a/sapi/milter/php_milter.c +++ b/sapi/milter/php_milter.c @@ -1134,8 +1134,6 @@ int main(int argc, char *argv[]) exit(1); } - CG(interactive) = interactive; - /* only set script_file if not set already and not in direct mode and not at end of parameter list */ if (argc > ap_php_optind && !filename) { filename=argv[ap_php_optind]; diff --git a/sapi/phpdbg/.travis.yml b/sapi/phpdbg/.travis.yml index d5b492e7cf..2e777fbe13 100644 --- a/sapi/phpdbg/.travis.yml +++ b/sapi/phpdbg/.travis.yml @@ -4,7 +4,6 @@ env: - PHP="PHP-5.4" - PHP="PHP-5.5" - PHP="PHP-5.6" -- PHP="master" before_script: ./travis/ci.sh diff --git a/sapi/phpdbg/README.md b/sapi/phpdbg/README.md index e7e5c731a8..a2a84deb7b 100644 --- a/sapi/phpdbg/README.md +++ b/sapi/phpdbg/README.md @@ -1,7 +1,7 @@ The interactive PHP debugger ============================ -Implemented as a SAPI module, phpdbg can excert complete control over the environment without impacting the functionality or performance of your code. +Implemented as a SAPI module, phpdbg can exert complete control over the environment without impacting the functionality or performance of your code. phpdbg aims to be a lightweight, powerful, easy to use debugging platform for PHP 5.4+ diff --git a/sapi/phpdbg/phpdbg.c b/sapi/phpdbg/phpdbg.c index 1fbd18a423..c10af61e1a 100644 --- a/sapi/phpdbg/phpdbg.c +++ b/sapi/phpdbg/phpdbg.c @@ -308,7 +308,7 @@ static PHP_FUNCTION(phpdbg_color) { long element = 0L; char *color = NULL; - int color_len = 0; + size_t color_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &element, &color, &color_len) == FAILURE) { return; @@ -329,7 +329,7 @@ static PHP_FUNCTION(phpdbg_color) static PHP_FUNCTION(phpdbg_prompt) { char *prompt = NULL; - int prompt_len = 0; + size_t prompt_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &prompt, &prompt_len) == FAILURE) { return; @@ -1296,14 +1296,14 @@ phpdbg_main: /* do not install sigint handlers for remote consoles */ /* sending SIGINT then provides a decent way of shutting down the server */ -#if defined(ZEND_SIGNALS) && !defined(_WIN32) - if (listen[0] < 0) { - zend_try { zend_signal(SIGINT, phpdbg_sigint_handler TSRMLS_CC); } zend_end_try(); - } -#elif !defined(_WIN32) +#ifndef _WIN32 if (listen[0] < 0) { #endif +#if defined(ZEND_SIGNALS) && !defined(_WIN32) + zend_try { zend_signal(SIGINT, phpdbg_sigint_handler TSRMLS_CC); } zend_end_try(); +#else signal(SIGINT, phpdbg_sigint_handler); +#endif #ifndef _WIN32 } #endif diff --git a/sapi/phpdbg/phpdbg.h b/sapi/phpdbg/phpdbg.h index eb4faf1f94..7d720f157b 100644 --- a/sapi/phpdbg/phpdbg.h +++ b/sapi/phpdbg/phpdbg.h @@ -180,7 +180,7 @@ ZEND_BEGIN_MODULE_GLOBALS(phpdbg) HashTable registered; /* registered */ HashTable seek; /* seek oplines */ phpdbg_frame_t frame; /* frame */ - zend_uint last_line; /* last executed line */ + uint32_t last_line; /* last executed line */ phpdbg_lexer_data lexer; /* lexer data */ phpdbg_param_t *parser_stack; /* param stack during lexer / parser phase */ diff --git a/sapi/phpdbg/phpdbg_bp.c b/sapi/phpdbg/phpdbg_bp.c index a18316a228..09bdc1931f 100644 --- a/sapi/phpdbg/phpdbg_bp.c +++ b/sapi/phpdbg/phpdbg_bp.c @@ -700,7 +700,7 @@ PHPDBG_API void phpdbg_set_breakpoint_opline_ex(phpdbg_opline_ptr_t opline TSRML static inline void phpdbg_create_conditional_break(phpdbg_breakcond_t *brake, const phpdbg_param_t *param, const char *expr, size_t expr_len, zend_ulong hash TSRMLS_DC) /* {{{ */ { phpdbg_breakcond_t new_break; - zend_uint cops = CG(compiler_options); + uint32_t cops = CG(compiler_options); zval pv; PHPDBG_BREAK_INIT(new_break, PHPDBG_BREAK_COND); @@ -970,7 +970,6 @@ static inline phpdbg_breakbase_t *phpdbg_find_conditional_breakpoint(zend_execut zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], (void*)&bp, &position) == SUCCESS; zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], &position)) { zval *retval = NULL; - int orig_interactive = CG(interactive); zval **orig_retval = EG(return_value_ptr_ptr); zend_op_array *orig_ops = EG(active_op_array); zend_op **orig_opline = EG(opline_ptr); @@ -995,8 +994,6 @@ static inline phpdbg_breakbase_t *phpdbg_find_conditional_breakpoint(zend_execut zend_rebuild_symbol_table(TSRMLS_C); } - CG(interactive) = 0; - zend_try { PHPDBG_G(flags) |= PHPDBG_IN_COND_BP; zend_execute(EG(active_op_array) TSRMLS_CC); @@ -1008,8 +1005,6 @@ static inline phpdbg_breakbase_t *phpdbg_find_conditional_breakpoint(zend_execut breakpoint = SUCCESS; } } zend_catch { - CG(interactive) = orig_interactive; - EG(no_extensions)=1; EG(return_value_ptr_ptr) = orig_retval; EG(active_op_array) = orig_ops; @@ -1017,8 +1012,6 @@ static inline phpdbg_breakbase_t *phpdbg_find_conditional_breakpoint(zend_execut PHPDBG_G(flags) &= ~PHPDBG_IN_COND_BP; } zend_end_try(); - CG(interactive) = orig_interactive; - EG(no_extensions)=1; EG(return_value_ptr_ptr) = orig_retval; EG(active_op_array) = orig_ops; @@ -1092,7 +1085,7 @@ PHPDBG_API void phpdbg_delete_breakpoint(zend_ulong num TSRMLS_DC) /* {{{ */ if ((brake = phpdbg_find_breakbase_ex(num, &table, &position TSRMLS_CC))) { char *key; - zend_uint klen; + uint32_t klen; zend_ulong idx; int type = brake->type; char *name = NULL; @@ -1370,7 +1363,7 @@ PHPDBG_API void phpdbg_print_breakpoints(zend_ulong type TSRMLS_DC) /* {{{ */ HashPosition position[2]; HashTable *class_table; char *class_name = NULL; - zend_uint class_len = 0; + uint32_t class_len = 0; zend_ulong class_idx = 0L; phpdbg_writeln(SEPARATE); @@ -1449,7 +1442,7 @@ PHPDBG_API void phpdbg_print_breakpoints(zend_ulong type TSRMLS_DC) /* {{{ */ HashPosition position[3]; HashTable *class_table, *method_table; char *class_name = NULL, *method_name = NULL; - zend_uint class_len = 0, method_len = 0; + uint32_t class_len = 0, method_len = 0; zend_ulong class_idx = 0L, method_idx = 0L; phpdbg_writeln(SEPARATE); @@ -1488,7 +1481,7 @@ PHPDBG_API void phpdbg_print_breakpoints(zend_ulong type TSRMLS_DC) /* {{{ */ HashPosition position[2]; HashTable *function_table; char *function_name = NULL; - zend_uint function_len = 0; + uint32_t function_len = 0; zend_ulong function_idx = 0L; phpdbg_writeln(SEPARATE); @@ -1518,7 +1511,7 @@ PHPDBG_API void phpdbg_print_breakpoints(zend_ulong type TSRMLS_DC) /* {{{ */ HashPosition position[2]; HashTable *file_table; char *file_name = NULL; - zend_uint file_len = 0; + uint32_t file_len = 0; zend_ulong file_idx = 0L; phpdbg_writeln(SEPARATE); diff --git a/sapi/phpdbg/phpdbg_cmd.c b/sapi/phpdbg/phpdbg_cmd.c index a45513bee6..72dc484098 100644 --- a/sapi/phpdbg/phpdbg_cmd.c +++ b/sapi/phpdbg/phpdbg_cmd.c @@ -699,7 +699,7 @@ PHPDBG_API const phpdbg_command_t* phpdbg_stack_resolve(const phpdbg_command_t * default: { char *list = NULL; - zend_uint it = 0; + uint32_t it = 0; size_t pos = 0; while (it < matches) { diff --git a/sapi/phpdbg/phpdbg_frame.c b/sapi/phpdbg/phpdbg_frame.c index a235fe8cb0..5a6a37d5f9 100644 --- a/sapi/phpdbg/phpdbg_frame.c +++ b/sapi/phpdbg/phpdbg_frame.c @@ -114,7 +114,7 @@ static void phpdbg_dump_prototype(zval **tmp TSRMLS_DC) /* {{{ */ (void **)&class); } else { zend_get_object_classname(*class, (const char **)&Z_STRVAL_PP(class), - (zend_uint *)&Z_STRLEN_PP(class) TSRMLS_CC); + (uint32_t *)&Z_STRLEN_PP(class) TSRMLS_CC); } if (is_class == SUCCESS) { diff --git a/sapi/phpdbg/phpdbg_opcode.c b/sapi/phpdbg/phpdbg_opcode.c index 6b13625fc1..31cf75b11d 100644 --- a/sapi/phpdbg/phpdbg_opcode.c +++ b/sapi/phpdbg/phpdbg_opcode.c @@ -26,7 +26,7 @@ ZEND_EXTERN_MODULE_GLOBALS(phpdbg); -static inline zend_uint phpdbg_decode_literal(zend_op_array *ops, zend_literal *literal TSRMLS_DC) /* {{{ */ +static inline uint32_t phpdbg_decode_literal(zend_op_array *ops, zend_literal *literal TSRMLS_DC) /* {{{ */ { int iter = 0; @@ -40,7 +40,7 @@ static inline zend_uint phpdbg_decode_literal(zend_op_array *ops, zend_literal * return 0; } /* }}} */ -static inline char *phpdbg_decode_op(zend_op_array *ops, znode_op *op, zend_uint type, HashTable *vars TSRMLS_DC) /* {{{ */ +static inline char *phpdbg_decode_op(zend_op_array *ops, znode_op *op, uint32_t type, HashTable *vars TSRMLS_DC) /* {{{ */ { char *decode = NULL; @@ -104,9 +104,6 @@ char *phpdbg_decode_opline(zend_op_array *ops, zend_op *op, HashTable *vars TSRM #ifdef ZEND_JMP_SET case ZEND_JMP_SET: #endif -#ifdef ZEND_JMP_SET_VAR - case ZEND_JMP_SET_VAR: -#endif decode[1] = phpdbg_decode_op(ops, &op->op1, op->op1_type, vars TSRMLS_CC); asprintf( &decode[2], "J%ld", op->op2.jmp_addr - ops->opcodes); @@ -333,12 +330,6 @@ const char *phpdbg_decode_opcode(zend_uchar opcode) /* {{{ */ #ifdef ZEND_SEPARATE CASE(ZEND_SEPARATE); #endif -#ifdef ZEND_QM_ASSIGN_VAR - CASE(ZEND_QM_ASSIGN_VAR); -#endif -#ifdef ZEND_JMP_SET_VAR - CASE(ZEND_JMP_SET_VAR); -#endif #ifdef ZEND_DISCARD_EXCEPTION CASE(ZEND_DISCARD_EXCEPTION); #endif diff --git a/sapi/phpdbg/phpdbg_print.c b/sapi/phpdbg/phpdbg_print.c index 76321a5042..376373e4a1 100644 --- a/sapi/phpdbg/phpdbg_print.c +++ b/sapi/phpdbg/phpdbg_print.c @@ -59,7 +59,7 @@ static inline void phpdbg_print_function_helper(zend_function *method TSRMLS_DC) if (op_array) { zend_op *opline = &(op_array->opcodes[0]); - zend_uint opcode = 0, + uint32_t opcode = 0, end = op_array->last-1; if (method->common.scope) { diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index d91ef3f3f5..7f78b58e53 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -430,7 +430,7 @@ PHPDBG_COMMAND(until) /* {{{ */ PHPDBG_G(flags) |= PHPDBG_IN_UNTIL; { - zend_uint next = 0, + uint32_t next = 0, self = (EG(current_execute_data)->opline - EG(active_op_array)->opcodes); zend_op *opline = &EG(active_op_array)->opcodes[self]; @@ -458,7 +458,7 @@ PHPDBG_COMMAND(finish) /* {{{ */ PHPDBG_G(flags) |= PHPDBG_IN_FINISH; { - zend_uint next = 0, + uint32_t next = 0, self = (EG(current_execute_data)->opline - EG(active_op_array)->opcodes); for (next = self; next < EG(active_op_array)->last; next++) { @@ -491,7 +491,7 @@ PHPDBG_COMMAND(leave) /* {{{ */ PHPDBG_G(flags) |= PHPDBG_IN_LEAVE; { - zend_uint next = 0, + uint32_t next = 0, self = (EG(current_execute_data)->opline - EG(active_op_array)->opcodes); for (next = self; next < EG(active_op_array)->last; next++) { @@ -534,7 +534,7 @@ static inline void phpdbg_handle_exception(TSRMLS_D) /* }}} */ /* get filename and linenumber before unsetting exception */ const char *filename = zend_get_executed_filename(TSRMLS_C); - zend_uint lineno = zend_get_executed_lineno(TSRMLS_C); + uint32_t lineno = zend_get_executed_lineno(TSRMLS_C); /* copy exception */ exception = *EG(exception); @@ -1134,7 +1134,7 @@ static inline zend_execute_data *phpdbg_create_execute_data(zend_op_array *op_ar } } - EX(opline) = UNEXPECTED((op_array->fn_flags & ZEND_ACC_INTERACTIVE) != 0) && EG(start_op) ? EG(start_op) : op_array->opcodes; + EX(opline) = op_array->opcodes; EG(opline_ptr) = &EX(opline); EX(function_state).function = (zend_function *) op_array; |
