63
63
#define PHP_SOURCE_MAGIC_TYPE "application/x-httpd-php-source"
64
64
#define PHP_SCRIPT "php7-script"
65
65
66
+ /* if apache's version is newer than 2.2.31 or 2.4.16 */
67
+ #if MODULE_MAGIC_COOKIE == 0x41503232UL && AP_MODULE_MAGIC_AT_LEAST (20051115 ,40 ) || \
68
+ MODULE_MAGIC_COOKIE == 0x41503234UL && AP_MODULE_MAGIC_AT_LEAST (20120211 ,47 )
69
+ #define php_ap_map_http_request_error ap_map_http_request_error
70
+ #else
71
+ static int php_ap_map_http_request_error (apr_status_t rv , int status )
72
+ {
73
+ switch (rv ) {
74
+ case AP_FILTER_ERROR : {
75
+ return AP_FILTER_ERROR ;
76
+ }
77
+ case APR_ENOSPC : {
78
+ return HTTP_REQUEST_ENTITY_TOO_LARGE ;
79
+ }
80
+ case APR_ENOTIMPL : {
81
+ return HTTP_NOT_IMPLEMENTED ;
82
+ }
83
+ case APR_ETIMEDOUT : {
84
+ return HTTP_REQUEST_TIME_OUT ;
85
+ }
86
+ default : {
87
+ return status ;
88
+ }
89
+ }
90
+ }
91
+ #endif
92
+
66
93
/* A way to specify the location of the php.ini dir in an apache directive */
67
94
char * apache2_php_ini_path_override = NULL ;
68
95
#if defined(PHP_WIN32 ) && defined(ZTS )
@@ -184,6 +211,7 @@ php_apache_sapi_read_post(char *buf, size_t count_bytes)
184
211
php_struct * ctx = SG (server_context );
185
212
request_rec * r ;
186
213
apr_bucket_brigade * brigade ;
214
+ apr_status_t ret ;
187
215
188
216
r = ctx -> r ;
189
217
brigade = ctx -> brigade ;
@@ -195,7 +223,7 @@ php_apache_sapi_read_post(char *buf, size_t count_bytes)
195
223
* need to make sure that if data is available we fill the buffer completely.
196
224
*/
197
225
198
- while (ap_get_brigade (r -> input_filters , brigade , AP_MODE_READBYTES , APR_BLOCK_READ , len ) == APR_SUCCESS ) {
226
+ while (( ret = ap_get_brigade (r -> input_filters , brigade , AP_MODE_READBYTES , APR_BLOCK_READ , len ) ) == APR_SUCCESS ) {
199
227
apr_brigade_flatten (brigade , buf , & len );
200
228
apr_brigade_cleanup (brigade );
201
229
tlen += len ;
@@ -206,6 +234,15 @@ php_apache_sapi_read_post(char *buf, size_t count_bytes)
206
234
len = count_bytes - tlen ;
207
235
}
208
236
237
+ if (ret != APR_SUCCESS ) {
238
+ AP2 (post_read_error ) = 1 ;
239
+ if (APR_STATUS_IS_TIMEUP (ret )) {
240
+ SG (sapi_headers ).http_response_code = php_ap_map_http_request_error (ret , HTTP_REQUEST_TIME_OUT );
241
+ } else {
242
+ SG (sapi_headers ).http_response_code = php_ap_map_http_request_error (ret , HTTP_BAD_REQUEST );
243
+ }
244
+ }
245
+
209
246
return tlen ;
210
247
}
211
248
@@ -487,6 +524,7 @@ static int php_apache_request_ctor(request_rec *r, php_struct *ctx)
487
524
SG (request_info ).proto_num = r -> proto_num ;
488
525
SG (request_info ).request_uri = apr_pstrdup (r -> pool , r -> uri );
489
526
SG (request_info ).path_translated = apr_pstrdup (r -> pool , r -> filename );
527
+ AP2 (post_read_error ) = 0 ;
490
528
r -> no_local_copy = 1 ;
491
529
492
530
content_length = (char * ) apr_table_get (r -> headers_in , "Content-Length" );
@@ -656,6 +694,13 @@ zend_first_try {
656
694
brigade = ctx -> brigade ;
657
695
}
658
696
697
+ if (AP2 (post_read_error )) {
698
+ ap_log_rerror (APLOG_MARK , APLOG_ERR , 0 , r , "Error while attempting to read POST data: %d" , SG (sapi_headers ).http_response_code );
699
+ apr_brigade_cleanup (brigade );
700
+ PHPAP_INI_OFF ;
701
+ return SG (sapi_headers ).http_response_code ;
702
+ }
703
+
659
704
if (AP2 (last_modified )) {
660
705
ap_update_mtime (r , r -> finfo .mtime );
661
706
ap_set_last_modified (r );
0 commit comments