From 9b65a10256e244a6d80027c943b163dd1643abe2 Mon Sep 17 00:00:00 2001 From: Zheng SHAO Date: Sat, 17 Dec 2016 13:37:58 +0900 Subject: bug fixed #61471 in apache2handler --- sapi/apache2handler/sapi_apache2.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'sapi/apache2handler/sapi_apache2.c') diff --git a/sapi/apache2handler/sapi_apache2.c b/sapi/apache2handler/sapi_apache2.c index 456b9719fa..718e01f7ad 100644 --- a/sapi/apache2handler/sapi_apache2.c +++ b/sapi/apache2handler/sapi_apache2.c @@ -184,6 +184,7 @@ php_apache_sapi_read_post(char *buf, size_t count_bytes) php_struct *ctx = SG(server_context); request_rec *r; apr_bucket_brigade *brigade; + apr_status_t ret; r = ctx->r; brigade = ctx->brigade; @@ -195,7 +196,7 @@ php_apache_sapi_read_post(char *buf, size_t count_bytes) * need to make sure that if data is available we fill the buffer completely. */ - while (ap_get_brigade(r->input_filters, brigade, AP_MODE_READBYTES, APR_BLOCK_READ, len) == APR_SUCCESS) { + while ((ret=ap_get_brigade(r->input_filters, brigade, AP_MODE_READBYTES, APR_BLOCK_READ, len)) == APR_SUCCESS) { apr_brigade_flatten(brigade, buf, &len); apr_brigade_cleanup(brigade); tlen += len; @@ -206,6 +207,14 @@ php_apache_sapi_read_post(char *buf, size_t count_bytes) len = count_bytes - tlen; } + if (ret != APR_SUCCESS) { + if (APR_STATUS_IS_TIMEUP(ret)) { + SG(sapi_headers).http_response_code = ap_map_http_request_error(ret, HTTP_REQUEST_TIME_OUT); + } else { + SG(sapi_headers).http_response_code = ap_map_http_request_error(ret, HTTP_BAD_REQUEST); + } + } + return tlen; } @@ -656,6 +665,13 @@ zend_first_try { brigade = ctx->brigade; } + if (SG(request_info).content_length > SG(read_post_bytes)) { + ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "attemp to read POST data error: %d", SG(sapi_headers).http_response_code); + apr_brigade_cleanup(brigade); + PHPAP_INI_OFF; + return SG(sapi_headers).http_response_code; + } + if (AP2(last_modified)) { ap_update_mtime(r, r->finfo.mtime); ap_set_last_modified(r); -- cgit v1.2.1 From fb98907d2de619e2b2a5e4edb531ae5e33f6ab37 Mon Sep 17 00:00:00 2001 From: Zheng SHAO Date: Sat, 17 Dec 2016 20:26:09 +0900 Subject: typo fixed --- sapi/apache2handler/sapi_apache2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sapi/apache2handler/sapi_apache2.c') diff --git a/sapi/apache2handler/sapi_apache2.c b/sapi/apache2handler/sapi_apache2.c index 718e01f7ad..1a4f36fa9e 100644 --- a/sapi/apache2handler/sapi_apache2.c +++ b/sapi/apache2handler/sapi_apache2.c @@ -666,7 +666,7 @@ zend_first_try { } if (SG(request_info).content_length > SG(read_post_bytes)) { - ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "attemp to read POST data error: %d", SG(sapi_headers).http_response_code); + ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "Error while attempting to read POST data: %d", SG(sapi_headers).http_response_code); apr_brigade_cleanup(brigade); PHPAP_INI_OFF; return SG(sapi_headers).http_response_code; -- cgit v1.2.1 From d92606a4bee4381f6762a3cd157c304bea4934d0 Mon Sep 17 00:00:00 2001 From: Zheng SHAO Date: Wed, 28 Dec 2016 19:02:41 +0900 Subject: add old versions of httpd support --- sapi/apache2handler/sapi_apache2.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'sapi/apache2handler/sapi_apache2.c') diff --git a/sapi/apache2handler/sapi_apache2.c b/sapi/apache2handler/sapi_apache2.c index 1a4f36fa9e..9e9b853e1c 100644 --- a/sapi/apache2handler/sapi_apache2.c +++ b/sapi/apache2handler/sapi_apache2.c @@ -69,6 +69,28 @@ char *apache2_php_ini_path_override = NULL; ZEND_TSRMLS_CACHE_DEFINE() #endif +int +php_ap_map_http_request_error(apr_status_t rv, int status) +{ + switch (rv) { + case AP_FILTER_ERROR: { + return AP_FILTER_ERROR; + } + case APR_ENOSPC: { + return HTTP_REQUEST_ENTITY_TOO_LARGE; + } + case APR_ENOTIMPL: { + return HTTP_NOT_IMPLEMENTED; + } + case APR_ETIMEDOUT: { + return HTTP_REQUEST_TIME_OUT; + } + default: { + return status; + } + } +} + static size_t php_apache_sapi_ub_write(const char *str, size_t str_length) { @@ -207,6 +229,9 @@ php_apache_sapi_read_post(char *buf, size_t count_bytes) len = count_bytes - tlen; } +// Apache 2.2.31 or 2.4.16 above +#if MODULE_MAGIC_COOKIE == 0x41503232UL && AP_MODULE_MAGIC_AT_LEAST(20051115,40) || \ + MODULE_MAGIC_COOKIE == 0x41503234UL && AP_MODULE_MAGIC_AT_LEAST(20120211,47) if (ret != APR_SUCCESS) { if (APR_STATUS_IS_TIMEUP(ret)) { SG(sapi_headers).http_response_code = ap_map_http_request_error(ret, HTTP_REQUEST_TIME_OUT); @@ -214,6 +239,15 @@ php_apache_sapi_read_post(char *buf, size_t count_bytes) SG(sapi_headers).http_response_code = ap_map_http_request_error(ret, HTTP_BAD_REQUEST); } } +#else + if (ret != APR_SUCCESS) { + if (APR_STATUS_IS_TIMEUP(ret)) { + SG(sapi_headers).http_response_code = php_ap_map_http_request_error(ret, HTTP_REQUEST_TIME_OUT); + } else { + SG(sapi_headers).http_response_code = php_ap_map_http_request_error(ret, HTTP_BAD_REQUEST); + } + } +#endif return tlen; } -- cgit v1.2.1 From 587497e3a9f5d74442b35ad9d0bf5f67be142edc Mon Sep 17 00:00:00 2001 From: Zheng SHAO Date: Thu, 29 Dec 2016 13:00:31 +0900 Subject: define php_ap_map_http_request_error function for older httpd only --- sapi/apache2handler/sapi_apache2.c | 55 +++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 31 deletions(-) (limited to 'sapi/apache2handler/sapi_apache2.c') diff --git a/sapi/apache2handler/sapi_apache2.c b/sapi/apache2handler/sapi_apache2.c index 9e9b853e1c..81574a4784 100644 --- a/sapi/apache2handler/sapi_apache2.c +++ b/sapi/apache2handler/sapi_apache2.c @@ -69,27 +69,32 @@ char *apache2_php_ini_path_override = NULL; ZEND_TSRMLS_CACHE_DEFINE() #endif -int -php_ap_map_http_request_error(apr_status_t rv, int status) +/* if apache's version is newer than 2.2.31 or 2.4.16 */ +#if MODULE_MAGIC_COOKIE == 0x41503232UL && AP_MODULE_MAGIC_AT_LEAST(20051115,40) || \ + MODULE_MAGIC_COOKIE == 0x41503234UL && AP_MODULE_MAGIC_AT_LEAST(20120211,47) +#define php_ap_map_http_request_error ap_map_http_request_error +#else +static int php_ap_map_http_request_error(apr_status_t rv, int status) { - switch (rv) { - case AP_FILTER_ERROR: { - return AP_FILTER_ERROR; - } - case APR_ENOSPC: { - return HTTP_REQUEST_ENTITY_TOO_LARGE; - } - case APR_ENOTIMPL: { - return HTTP_NOT_IMPLEMENTED; - } - case APR_ETIMEDOUT: { - return HTTP_REQUEST_TIME_OUT; - } - default: { - return status; - } - } + switch (rv) { + case AP_FILTER_ERROR: { + return AP_FILTER_ERROR; + } + case APR_ENOSPC: { + return HTTP_REQUEST_ENTITY_TOO_LARGE; + } + case APR_ENOTIMPL: { + return HTTP_NOT_IMPLEMENTED; + } + case APR_ETIMEDOUT: { + return HTTP_REQUEST_TIME_OUT; + } + default: { + return status; + } + } } +#endif static size_t php_apache_sapi_ub_write(const char *str, size_t str_length) @@ -229,17 +234,6 @@ php_apache_sapi_read_post(char *buf, size_t count_bytes) len = count_bytes - tlen; } -// Apache 2.2.31 or 2.4.16 above -#if MODULE_MAGIC_COOKIE == 0x41503232UL && AP_MODULE_MAGIC_AT_LEAST(20051115,40) || \ - MODULE_MAGIC_COOKIE == 0x41503234UL && AP_MODULE_MAGIC_AT_LEAST(20120211,47) - if (ret != APR_SUCCESS) { - if (APR_STATUS_IS_TIMEUP(ret)) { - SG(sapi_headers).http_response_code = ap_map_http_request_error(ret, HTTP_REQUEST_TIME_OUT); - } else { - SG(sapi_headers).http_response_code = ap_map_http_request_error(ret, HTTP_BAD_REQUEST); - } - } -#else if (ret != APR_SUCCESS) { if (APR_STATUS_IS_TIMEUP(ret)) { SG(sapi_headers).http_response_code = php_ap_map_http_request_error(ret, HTTP_REQUEST_TIME_OUT); @@ -247,7 +241,6 @@ php_apache_sapi_read_post(char *buf, size_t count_bytes) SG(sapi_headers).http_response_code = php_ap_map_http_request_error(ret, HTTP_BAD_REQUEST); } } -#endif return tlen; } -- cgit v1.2.1