From 582f42b8d47fb85edc846a6c739b85a1653e0852 Mon Sep 17 00:00:00 2001 From: George Wang Date: Wed, 3 Sep 2014 11:24:45 -0400 Subject: Update LSAPI to 6.7, added support for 'filter_input'. Fixed a crash in CLI mode. --- sapi/litespeed/lsapi_main.c | 68 +++++++++++++++++++++++++++++++++++++++++---- sapi/litespeed/lsapilib.c | 6 +++- 2 files changed, 67 insertions(+), 7 deletions(-) diff --git a/sapi/litespeed/lsapi_main.c b/sapi/litespeed/lsapi_main.c index 3413a423ac..cb7c66b44a 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) @@ -268,7 +324,7 @@ 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); + litespeed_php_import_environment_variables(track_vars_array TSRMLS_CC); } else { php_import_environment_variables(track_vars_array TSRMLS_CC); @@ -370,7 +426,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] ) -- cgit v1.2.1 From d2e1a04b1011e15321b9748f76620786418b7893 Mon Sep 17 00:00:00 2001 From: George Wang Date: Mon, 8 Sep 2014 23:58:05 -0400 Subject: Fine tuned the order of adding request variables. --- sapi/litespeed/lsapi_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sapi/litespeed/lsapi_main.c b/sapi/litespeed/lsapi_main.c index cb7c66b44a..789ebf2460 100644 --- a/sapi/litespeed/lsapi_main.c +++ b/sapi/litespeed/lsapi_main.c @@ -311,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 @@ -324,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 - litespeed_php_import_environment_variables(track_vars_array TSRMLS_CC); } else { php_import_environment_variables(track_vars_array TSRMLS_CC); -- cgit v1.2.1 From bdac08bcdd61181cdda43edad414fe9e205401ca Mon Sep 17 00:00:00 2001 From: George Wang Date: Mon, 8 Sep 2014 23:58:05 -0400 Subject: Fine tuned the order of adding request variables. --- sapi/litespeed/lsapi_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sapi/litespeed/lsapi_main.c b/sapi/litespeed/lsapi_main.c index cb7c66b44a..789ebf2460 100644 --- a/sapi/litespeed/lsapi_main.c +++ b/sapi/litespeed/lsapi_main.c @@ -311,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 @@ -324,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 - litespeed_php_import_environment_variables(track_vars_array TSRMLS_CC); } else { php_import_environment_variables(track_vars_array TSRMLS_CC); -- cgit v1.2.1 From 99f0760bfba86f45af9ea011a0f017080922710a Mon Sep 17 00:00:00 2001 From: Tjerk Meesters Date: Tue, 9 Sep 2014 17:58:45 +0800 Subject: Fixed #67985 - Incorrect last used array index copied to new array after unset In master zend_array_dup() is used to do this properly; this is a workaround. --- NEWS | 4 ++++ Zend/tests/bug67985.phpt | 16 ++++++++++++++++ Zend/zend_variables.c | 1 + 3 files changed, 21 insertions(+) create mode 100644 Zend/tests/bug67985.phpt diff --git a/NEWS b/NEWS index 6c9b2baa67..792665969e 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,10 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? 2014, PHP 5.4.34 +- Core: + . Fixed bug #67985 (Incorrect last used array index copied to new array after + unset). (Tjerk) + ?? ??? 2014, PHP 5.4.33 - Core: diff --git a/Zend/tests/bug67985.phpt b/Zend/tests/bug67985.phpt new file mode 100644 index 0000000000..6f032643f4 --- /dev/null +++ b/Zend/tests/bug67985.phpt @@ -0,0 +1,16 @@ +--TEST-- +Bug #67985 - Last used array index not copied to new array at assignment +--FILE-- + +--EXPECT-- +bool(true) diff --git a/Zend/zend_variables.c b/Zend/zend_variables.c index b875445120..9674de5246 100644 --- a/Zend/zend_variables.c +++ b/Zend/zend_variables.c @@ -136,6 +136,7 @@ ZEND_API void _zval_copy_ctor_func(zval *zvalue ZEND_FILE_LINE_DC) ALLOC_HASHTABLE_REL(tmp_ht); zend_hash_init(tmp_ht, zend_hash_num_elements(original_ht), NULL, ZVAL_PTR_DTOR, 0); zend_hash_copy(tmp_ht, original_ht, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); + tmp_ht->nNextFreeElement = original_ht->nNextFreeElement; zvalue->value.ht = tmp_ht; } break; -- cgit v1.2.1 From b9ac5e23fb1b347b5eab250832999e291d65807a Mon Sep 17 00:00:00 2001 From: Tjerk Meesters Date: Tue, 9 Sep 2014 18:02:45 +0800 Subject: Updated NEWS for #67985 --- NEWS | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS b/NEWS index f0a4379e2a..ba6eaaaf5c 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,10 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? 2014, PHP 5.5.18 +- Core: + . Fixed bug #67985 (Incorrect last used array index copied to new array after + unset). (Tjerk) + - Session: . Fixed bug #67972 (SessionHandler Invalid memory read create_sid()). (Adam) -- cgit v1.2.1