diff options
author | Gustavo André dos Santos Lopes <cataphract@php.net> | 2010-10-04 01:27:33 +0000 |
---|---|---|
committer | Gustavo André dos Santos Lopes <cataphract@php.net> | 2010-10-04 01:27:33 +0000 |
commit | e1aa908468171956caa3726dde316adf0f7b0cd9 (patch) | |
tree | 43e3848fa5a87a3a8d22bd4dbd03eed8cd39cd53 /main | |
parent | 87a237342282fe036bb90486fdd6cdc392e16ac7 (diff) | |
download | php-git-e1aa908468171956caa3726dde316adf0f7b0cd9.tar.gz |
- Implemented FR #50692, not uploaded files don't count towards
max_file_uploads limit.
- As a side improvement, temporary files are not opened for
empty uploads and, in debug mode, 0-length uploads.
Diffstat (limited to 'main')
-rw-r--r-- | main/rfc1867.c | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/main/rfc1867.c b/main/rfc1867.c index e77093c344..0bebe6fb5d 100644 --- a/main/rfc1867.c +++ b/main/rfc1867.c @@ -1003,16 +1003,8 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ } total_bytes = cancel_upload = 0; - - if (!skip_upload) { - /* Handle file */ - fd = php_open_temporary_fd_ex(PG(upload_tmp_dir), "php", &temp_filename, 1 TSRMLS_CC); - upload_cnt--; - if (fd == -1) { - sapi_module.sapi_error(E_WARNING, "File upload error - unable to create a temporary file"); - cancel_upload = UPLOAD_ERROR_E; - } - } + temp_filename = NULL; + fd = -1; if (!skip_upload && php_rfc1867_callback != NULL) { multipart_event_file_start event_file_start; @@ -1021,13 +1013,6 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ event_file_start.name = param; event_file_start.filename = &filename; if (php_rfc1867_callback(MULTIPART_EVENT_FILE_START, &event_file_start, &event_extra_data TSRMLS_CC) == FAILURE) { - if (temp_filename) { - if (cancel_upload != UPLOAD_ERROR_E) { /* file creation failed */ - close(fd); - unlink(temp_filename); - } - efree(temp_filename); - } temp_filename = ""; efree(param); efree(filename); @@ -1050,7 +1035,26 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ offset = 0; end = 0; - while (!cancel_upload && (blen = multipart_buffer_read(mbuff, buff, sizeof(buff), &end TSRMLS_CC))) + + if (!cancel_upload) { + /* only bother to open temp file if we have data */ + blen = multipart_buffer_read(mbuff, buff, sizeof(buff), &end TSRMLS_CC); +#if DEBUG_FILE_UPLOAD + if (blen > 0) { +#else + /* in non-debug mode we have no problem with 0-length files */ + { +#endif + fd = php_open_temporary_fd_ex(PG(upload_tmp_dir), "php", &temp_filename, 1 TSRMLS_CC); + upload_cnt--; + if (fd == -1) { + sapi_module.sapi_error(E_WARNING, "File upload error - unable to create a temporary file"); + cancel_upload = UPLOAD_ERROR_E; + } + } + } + + while (!cancel_upload && (blen > 0)) { if (php_rfc1867_callback != NULL) { multipart_event_file_data event_file_data; @@ -1095,10 +1099,15 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ } offset += wlen; } + + /* read data for next iteration */ + blen = multipart_buffer_read(mbuff, buff, sizeof(buff), &end TSRMLS_CC); } + if (fd != -1) { /* may not be initialized if file could not be created */ close(fd); } + if (!cancel_upload && !end) { #if DEBUG_FILE_UPLOAD sapi_module.sapi_error(E_NOTICE, "Missing mime boundary at the end of the data for file %s", strlen(filename) > 0 ? filename : ""); |