Skip to content

Commit e2af49b

Browse files
committed
add allow_multipart_form INI option
1 parent a92fc9f commit e2af49b

4 files changed

Lines changed: 10 additions & 19 deletions

File tree

main/SAPI.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ SAPI_API void sapi_read_post_data(void)
199199
/* now try to find an appropriate POST content handler */
200200
if ((post_entry = zend_hash_str_find_ptr(&SG(known_post_content_types), content_type,
201201
content_type_length)) != NULL) {
202+
if(!SG(allow_multipart_form) && !strcmp(content_type, MULTIPART_CONTENT_TYPE)) {
203+
efree(content_type);
204+
return;
205+
}
202206
/* found one, register it for use */
203207
SG(request_info).post_entry = post_entry;
204208
post_reader_func = post_entry->post_reader;

main/SAPI.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ typedef struct _sapi_globals_struct {
141141
char *default_charset;
142142
HashTable *rfc1867_uploaded_files;
143143
zend_long post_max_size;
144-
char *multipart_uri_whitelist;
144+
bool allow_multipart_form;
145145
int options;
146146
bool sapi_started;
147147
double global_request_time;

main/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ PHP_INI_BEGIN()
878878
PHP_INI_ENTRY("disable_functions", "", PHP_INI_SYSTEM, NULL)
879879
PHP_INI_ENTRY("max_file_uploads", "20", PHP_INI_SYSTEM|PHP_INI_PERDIR, NULL)
880880
PHP_INI_ENTRY("max_multipart_body_parts", "-1", PHP_INI_SYSTEM|PHP_INI_PERDIR, NULL)
881-
STD_PHP_INI_ENTRY("multipart_uri_whitelist", NULL, PHP_INI_PERDIR, OnUpdateString, multipart_uri_whitelist, sapi_globals_struct, sapi_globals)
881+
STD_PHP_INI_ENTRY("allow_multipart_form", "1", PHP_INI_ALL, OnUpdateBool, allow_multipart_form, sapi_globals_struct, sapi_globals)
882882

883883
STD_PHP_INI_BOOLEAN("allow_url_fopen", "1", PHP_INI_SYSTEM, OnUpdateBool, allow_url_fopen, php_core_globals, core_globals)
884884
STD_PHP_INI_BOOLEAN("allow_url_include", "0", PHP_INI_SYSTEM, OnUpdateBool, allow_url_include, php_core_globals, core_globals)

main/rfc1867.c

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler)
670670
zend_long post_max_size = REQUEST_PARSE_BODY_OPTION_GET(post_max_size, SG(post_max_size));
671671
zend_long max_input_vars = REQUEST_PARSE_BODY_OPTION_GET(max_input_vars, PG(max_input_vars));
672672
zend_long upload_max_filesize = REQUEST_PARSE_BODY_OPTION_GET(upload_max_filesize, PG(upload_max_filesize));
673-
char *multipart_uri_whitelist = SG(multipart_uri_whitelist);
673+
bool allow_multipart_form = SG(allow_multipart_form);
674674
const zend_encoding *internal_encoding = zend_multibyte_get_internal_encoding();
675675
php_rfc1867_getword_t getword;
676676
php_rfc1867_getword_conf_t getword_conf;
@@ -695,22 +695,9 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler)
695695
_basename = php_ap_basename;
696696
}
697697

698-
if(multipart_uri_whitelist != NULL) {
699-
char *uri = strtok(multipart_uri_whitelist, ":");
700-
bool find = 0;
701-
702-
while (uri)
703-
{
704-
if(strcasecmp(SG(request_info).request_uri, uri) == 0) {
705-
find = 1;
706-
break;
707-
}
708-
uri = strtok(NULL, ":");
709-
}
710-
if(!find) {
711-
EMIT_WARNING_OR_ERROR("request uri %s is not allow POST multipart body", SG(request_info).request_uri);
712-
return;
713-
}
698+
if(!allow_multipart_form) {
699+
EMIT_WARNING_OR_ERROR("request uri %s is not allow POST multipart body", SG(request_info).request_uri);
700+
return;
714701
}
715702

716703
if (post_max_size > 0 && SG(request_info).content_length > post_max_size) {

0 commit comments

Comments
 (0)