From 8584cc010aaf5dfa9e314d3e8f2eb14aee78225b Mon Sep 17 00:00:00 2001 From: George Wang Date: Wed, 25 Feb 2015 10:48:19 -0500 Subject: [PATCH 1/4] Fixed a bug that header value is not terminated by '\0' when accessed through getenv(). --- sapi/litespeed/lsapilib.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/sapi/litespeed/lsapilib.c b/sapi/litespeed/lsapilib.c index 3d1513ac502..baf0db37972 100644 --- a/sapi/litespeed/lsapilib.c +++ b/sapi/litespeed/lsapilib.c @@ -1390,10 +1390,12 @@ char * LSAPI_GetHeader_r( LSAPI_Request * pReq, int headerIndex ) off = pReq->m_pHeaderIndex->m_headerOff[ headerIndex ]; if ( !off ) return NULL; - if ( *(pReq->m_pHttpHeader + off + - pReq->m_pHeaderIndex->m_headerLen[ headerIndex ]) ) - *( pReq->m_pHttpHeader + off + - pReq->m_pHeaderIndex->m_headerLen[ headerIndex ]) = 0; + if ( *(pReq->m_pHttpHeader + off + + pReq->m_pHeaderIndex->m_headerLen[ headerIndex ]) ) + { + *( pReq->m_pHttpHeader + off + + pReq->m_pHeaderIndex->m_headerLen[ headerIndex ]) = 0; + } return pReq->m_pHttpHeader + off; } @@ -1830,12 +1832,21 @@ ssize_t LSAPI_Write_Stderr_r( LSAPI_Request * pReq, const char * pBuf, size_t le static char * GetHeaderVar( LSAPI_Request * pReq, const char * name ) { int i; + char * pValue; for( i = 0; i < H_TRANSFER_ENCODING; ++i ) { if ( pReq->m_pHeaderIndex->m_headerOff[i] ) { if ( strcmp( name, CGI_HEADERS[i] ) == 0 ) - return pReq->m_pHttpHeader + pReq->m_pHeaderIndex->m_headerOff[i]; + { + pValue = pReq->m_pHttpHeader + + pReq->m_pHeaderIndex->m_headerOff[i]; + if ( *(pValue + pReq->m_pHeaderIndex->m_headerLen[i]) != '\0') + { + *(pValue + pReq->m_pHeaderIndex->m_headerLen[i]) = '\0'; + } + return pValue; + } } } if ( pReq->m_pHeader->m_cntUnknownHeaders > 0 ) @@ -1862,7 +1873,15 @@ static char * GetHeaderVar( LSAPI_Request * pReq, const char * name ) ++p; ++pKey; } if (( pKey == pKeyEnd )&& (!*p )) - return pReq->m_pHttpHeader + pCur->valueOff; + { + pValue = pReq->m_pHttpHeader + pCur->valueOff; + + if ( *(pValue + pCur->valueLen) != '\0') + { + *(pValue + pCur->valueLen) = '\0'; + } + return pValue; + } ++pCur; } } From d5248f67b58ac3107fec82c5b937fc3f4c89784a Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 2 Mar 2015 12:27:36 +0300 Subject: [PATCH 2/4] Check variable type before its usage as IS_ARRAY. --- ext/soap/soap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ext/soap/soap.c b/ext/soap/soap.c index eaa57d90328..8790605f8e2 100644 --- a/ext/soap/soap.c +++ b/ext/soap/soap.c @@ -2884,7 +2884,8 @@ PHP_METHOD(SoapClient, __call) } /* Add default headers */ - if (zend_hash_find(Z_OBJPROP_P(this_ptr), "__default_headers", sizeof("__default_headers"), (void **) &tmp)==SUCCESS) { + if (zend_hash_find(Z_OBJPROP_P(this_ptr), "__default_headers", sizeof("__default_headers"), (void **) &tmp)==SUCCESS && + Z_TYPE_PP(tmp) == IS_ARRAY) { HashTable *default_headers = Z_ARRVAL_P(*tmp); if (soap_headers) { if (!free_soap_headers) { From 34f09b62408759e9d8754ccdd790c6586507a4d2 Mon Sep 17 00:00:00 2001 From: Reeze Xia Date: Tue, 3 Mar 2015 11:25:30 +0800 Subject: [PATCH 3/4] Fixed bug #67741 (auto_prepend_file messes up __LINE__) This also fixes bug #54081 --- main/main.c | 15 ++++++++++++++- sapi/cli/tests/bug67741.phpt | 17 +++++++++++++++++ sapi/cli/tests/bug67741_stub.inc | 3 +++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 sapi/cli/tests/bug67741.phpt create mode 100644 sapi/cli/tests/bug67741_stub.inc diff --git a/main/main.c b/main/main.c index 8f5bac17b91..9f7c15354af 100644 --- a/main/main.c +++ b/main/main.c @@ -2507,8 +2507,21 @@ PHPAPI int php_execute_script(zend_file_handle *primary_file TSRMLS_DC) #endif zend_set_timeout(INI_INT("max_execution_time"), 0); } - retval = (zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, NULL, 3, prepend_file_p, primary_file, append_file_p) == SUCCESS); + { + /* + If cli primary file has shabang line and there is a prepend file, + the `start_lineno` will be used by prepend file but not primary file, + save it and restore after prepend file been executed. + */ + int orig_start_lineno = CG(start_lineno); + + CG(start_lineno) = 0; + retval = (zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, NULL, 1, prepend_file_p) == SUCCESS); + CG(start_lineno) = orig_start_lineno; + + retval = retval && (zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, NULL, 2, primary_file, append_file_p) == SUCCESS); + } } zend_end_try(); #if HAVE_BROKEN_GETCWD diff --git a/sapi/cli/tests/bug67741.phpt b/sapi/cli/tests/bug67741.phpt new file mode 100644 index 00000000000..df0981443f2 --- /dev/null +++ b/sapi/cli/tests/bug67741.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug #67741 (auto_prepend_file messes up __LINE__) +--INI-- +include_path={PWD} +auto_prepend_file=bug67741_stub.inc +--SKIPIF-- + +--FILE-- +#!/bin/env php + +--EXPECT-- +prepend lineno: 2 +primary lineno: 3 \ No newline at end of file diff --git a/sapi/cli/tests/bug67741_stub.inc b/sapi/cli/tests/bug67741_stub.inc new file mode 100644 index 00000000000..4d7470ea293 --- /dev/null +++ b/sapi/cli/tests/bug67741_stub.inc @@ -0,0 +1,3 @@ + From bb466d57ae7a630526cc17f6259669f2be693aca Mon Sep 17 00:00:00 2001 From: Reeze Xia Date: Tue, 3 Mar 2015 14:22:03 +0800 Subject: [PATCH 4/4] Update NEWS --- NEWS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS b/NEWS index da1fa62ce94..5eec926c32c 100644 --- a/NEWS +++ b/NEWS @@ -55,6 +55,9 @@ PHP NEWS - CGI: . Fixed bug #69015 (php-cgi's getopt does not see $argv). (Laruence) +- CLI: + . Fixed bug #67741 (auto_prepend_file messes up __LINE__). (Reeze Xia) + - FPM: . Fixed bug #68822 (request time is reset too early). (honghu069 at 163 dot com)