diff options
Diffstat (limited to 'ext/standard')
| -rw-r--r-- | ext/standard/basic_functions.c | 4 | ||||
| -rw-r--r-- | ext/standard/basic_functions.h | 8 | ||||
| -rw-r--r-- | ext/standard/exec.c | 4 | ||||
| -rw-r--r-- | ext/standard/file.c | 122 | ||||
| -rw-r--r-- | ext/standard/ftp_fopen_wrapper.c | 7 | ||||
| -rw-r--r-- | ext/standard/incomplete_class.c | 2 | ||||
| -rw-r--r-- | ext/standard/password.c | 22 | ||||
| -rw-r--r-- | ext/standard/php_fopen_wrapper.c | 2 | ||||
| -rw-r--r-- | ext/standard/php_fopen_wrappers.h | 4 | ||||
| -rw-r--r-- | ext/standard/php_incomplete_class.h | 2 | ||||
| -rw-r--r-- | ext/standard/tests/file/bug52820.phpt | 134 | ||||
| -rw-r--r-- | ext/standard/url_scanner_ex.c | 19 | ||||
| -rw-r--r-- | ext/standard/url_scanner_ex.h | 2 | ||||
| -rw-r--r-- | ext/standard/url_scanner_ex.re | 19 | ||||
| -rw-r--r-- | ext/standard/user_filters.c | 4 |
15 files changed, 179 insertions, 176 deletions
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 106bc54141..a168069cfb 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -4962,7 +4962,7 @@ static int user_tick_function_compare(user_tick_function_entry * tick_fe1, user_ } /* }}} */ -void php_call_shutdown_functions(TSRMLS_D) /* {{{ */ +PHPAPI void php_call_shutdown_functions(TSRMLS_D) /* {{{ */ { if (BG(user_shutdown_function_names)) { zend_try { @@ -4974,7 +4974,7 @@ void php_call_shutdown_functions(TSRMLS_D) /* {{{ */ } /* }}} */ -void php_free_shutdown_functions(TSRMLS_D) /* {{{ */ +PHPAPI void php_free_shutdown_functions(TSRMLS_D) /* {{{ */ { if (BG(user_shutdown_function_names)) zend_try { diff --git a/ext/standard/basic_functions.h b/ext/standard/basic_functions.h index 815227118e..c47ee0fb96 100644 --- a/ext/standard/basic_functions.h +++ b/ext/standard/basic_functions.h @@ -34,6 +34,10 @@ #include "url_scanner_ex.h" +#if defined(_WIN32) && defined(__clang__) +#include <intrin.h> +#endif + extern zend_module_entry basic_functions_module; #define basic_functions_module_ptr &basic_functions_module @@ -259,4 +263,8 @@ PHPAPI extern zend_bool register_user_shutdown_function(char *function_name, siz PHPAPI extern zend_bool remove_user_shutdown_function(char *function_name, size_t function_len TSRMLS_DC); PHPAPI extern zend_bool append_user_shutdown_function(php_shutdown_function_entry shutdown_function_entry TSRMLS_DC); +PHPAPI void php_call_shutdown_functions(TSRMLS_D); +PHPAPI void php_free_shutdown_functions(TSRMLS_D); + + #endif /* BASIC_FUNCTIONS_H */ diff --git a/ext/standard/exec.c b/ext/standard/exec.c index 6106fe2c86..15e4876af5 100644 --- a/ext/standard/exec.c +++ b/ext/standard/exec.c @@ -242,9 +242,11 @@ PHP_FUNCTION(passthru) PHPAPI zend_string *php_escape_shell_cmd(char *str) { register int x, y, l = (int)strlen(str); - char *p = NULL; size_t estimate = (2 * l) + 1; zend_string *cmd; +#ifndef PHP_WIN32 + char *p = NULL; +#endif TSRMLS_FETCH(); diff --git a/ext/standard/file.c b/ext/standard/file.c index ff7c5433eb..4804e49338 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -339,16 +339,16 @@ static int flock_values[] = { LOCK_SH, LOCK_EX, LOCK_UN }; Portable file locking */ PHP_FUNCTION(flock) { - zval *arg1, *arg3 = NULL; + zval *res, *wouldblock = NULL; int act; php_stream *stream; zend_long operation = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|z/", &arg1, &operation, &arg3) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|z/", &res, &operation, &wouldblock) == FAILURE) { return; } - PHP_STREAM_TO_ZVAL(stream, arg1); + PHP_STREAM_TO_ZVAL(stream, res); act = operation & 3; if (act < 1 || act > 3) { @@ -356,16 +356,16 @@ PHP_FUNCTION(flock) RETURN_FALSE; } - if (arg3) { - zval_dtor(arg3); - ZVAL_LONG(arg3, 0); + if (wouldblock) { + zval_dtor(wouldblock); + ZVAL_LONG(wouldblock, 0); } /* flock_values contains all possible actions if (operation & 4) we won't block on the lock */ act = flock_values[act - 1] | (operation & PHP_LOCK_NB ? LOCK_NB : 0); if (php_stream_lock(stream, act)) { - if (operation && errno == EWOULDBLOCK && arg3) { - ZVAL_LONG(arg3, 1); + if (operation && errno == EWOULDBLOCK && wouldblock) { + ZVAL_LONG(wouldblock, 1); } RETURN_FALSE; } @@ -887,20 +887,20 @@ PHP_NAMED_FUNCTION(php_if_fopen) Close an open file pointer */ PHPAPI PHP_FUNCTION(fclose) { - zval *arg1; + zval *res; php_stream *stream; #ifndef FAST_ZPP - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) { RETURN_FALSE; } #else ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_RESOURCE(arg1) + Z_PARAM_RESOURCE(res) ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); #endif - PHP_STREAM_TO_ZVAL(stream, arg1); + PHP_STREAM_TO_ZVAL(stream, res); if ((stream->flags & PHP_STREAM_FLAG_NO_FCLOSE) != 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%pd is not a valid stream resource", stream->res->handle); @@ -965,14 +965,14 @@ PHP_FUNCTION(popen) Close a file pointer opened by popen() */ PHP_FUNCTION(pclose) { - zval *arg1; + zval *res; php_stream *stream; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) { RETURN_FALSE; } - PHP_STREAM_TO_ZVAL(stream, arg1); + PHP_STREAM_TO_ZVAL(stream, res); FG(pclose_wait) = 1; zend_list_close(stream->res); @@ -985,14 +985,14 @@ PHP_FUNCTION(pclose) Test for end-of-file on a file pointer */ PHPAPI PHP_FUNCTION(feof) { - zval *arg1; + zval *res; php_stream *stream; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) { RETURN_FALSE; } - PHP_STREAM_TO_ZVAL(stream, arg1); + PHP_STREAM_TO_ZVAL(stream, res); if (php_stream_eof(stream)) { RETURN_TRUE; @@ -1006,18 +1006,18 @@ PHPAPI PHP_FUNCTION(feof) Get a line from file pointer */ PHPAPI PHP_FUNCTION(fgets) { - zval *arg1; + zval *res; zend_long len = 1024; char *buf = NULL; int argc = ZEND_NUM_ARGS(); size_t line_len = 0; php_stream *stream; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &arg1, &len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &res, &len) == FAILURE) { RETURN_FALSE; } - PHP_STREAM_TO_ZVAL(stream, arg1); + PHP_STREAM_TO_ZVAL(stream, res); if (argc == 1) { /* ask streams to give us a buffer of an appropriate size */ @@ -1062,16 +1062,16 @@ exit_failed: Get a character from file pointer */ PHPAPI PHP_FUNCTION(fgetc) { - zval *arg1; + zval *res; char buf[2]; int result; php_stream *stream; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) { RETURN_FALSE; } - PHP_STREAM_TO_ZVAL(stream, arg1); + PHP_STREAM_TO_ZVAL(stream, res); result = php_stream_getc(stream); @@ -1193,39 +1193,33 @@ PHP_FUNCTION(fscanf) Binary-safe file write */ PHPAPI PHP_FUNCTION(fwrite) { - zval *arg1; - char *arg2; - size_t arg2len; + zval *res; + char *input; + size_t inputlen; size_t ret; size_t num_bytes; - zend_long arg3 = 0; - char *buffer = NULL; + zend_long maxlen = 0; php_stream *stream; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|l", &arg1, &arg2, &arg2len, &arg3) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|l", &res, &input, &inputlen, &maxlen) == FAILURE) { RETURN_FALSE; } if (ZEND_NUM_ARGS() == 2) { - num_bytes = arg2len; + num_bytes = inputlen; + } else if (maxlen <= 0) { + num_bytes = 0; } else { - if (arg3 > 0) { - num_bytes = MIN((size_t)arg3, arg2len); - } else { - num_bytes = 0; - } + num_bytes = MIN((size_t) maxlen, inputlen); } if (!num_bytes) { RETURN_LONG(0); } - PHP_STREAM_TO_ZVAL(stream, arg1); + PHP_STREAM_TO_ZVAL(stream, res); - ret = php_stream_write(stream, buffer ? buffer : arg2, num_bytes); - if (buffer) { - efree(buffer); - } + ret = php_stream_write(stream, input, num_bytes); RETURN_LONG(ret); } @@ -1235,15 +1229,15 @@ PHPAPI PHP_FUNCTION(fwrite) Flushes output */ PHPAPI PHP_FUNCTION(fflush) { - zval *arg1; + zval *res; int ret; php_stream *stream; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) { RETURN_FALSE; } - PHP_STREAM_TO_ZVAL(stream, arg1); + PHP_STREAM_TO_ZVAL(stream, res); ret = php_stream_flush(stream); if (ret) { @@ -1257,14 +1251,14 @@ PHPAPI PHP_FUNCTION(fflush) Rewind the position of a file pointer */ PHPAPI PHP_FUNCTION(rewind) { - zval *arg1; + zval *res; php_stream *stream; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) { RETURN_FALSE; } - PHP_STREAM_TO_ZVAL(stream, arg1); + PHP_STREAM_TO_ZVAL(stream, res); if (-1 == php_stream_rewind(stream)) { RETURN_FALSE; @@ -1277,15 +1271,15 @@ PHPAPI PHP_FUNCTION(rewind) Get file pointer's read/write position */ PHPAPI PHP_FUNCTION(ftell) { - zval *arg1; + zval *res; zend_long ret; php_stream *stream; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) { RETURN_FALSE; } - PHP_STREAM_TO_ZVAL(stream, arg1); + PHP_STREAM_TO_ZVAL(stream, res); ret = php_stream_tell(stream); if (ret == -1) { @@ -1299,17 +1293,17 @@ PHPAPI PHP_FUNCTION(ftell) Seek on a file pointer */ PHPAPI PHP_FUNCTION(fseek) { - zval *arg1; - zend_long arg2, whence = SEEK_SET; + zval *res; + zend_long offset, whence = SEEK_SET; php_stream *stream; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|l", &arg1, &arg2, &whence) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|l", &res, &offset, &whence) == FAILURE) { RETURN_FALSE; } - PHP_STREAM_TO_ZVAL(stream, arg1); + PHP_STREAM_TO_ZVAL(stream, res); - RETURN_LONG(php_stream_seek(stream, arg2, (int)whence)); + RETURN_LONG(php_stream_seek(stream, offset, (int) whence)); } /* }}} */ @@ -1411,7 +1405,7 @@ PHP_FUNCTION(readfile) Return or change the umask */ PHP_FUNCTION(umask) { - zend_long arg1 = 0; + zend_long mask = 0; int oldumask; oldumask = umask(077); @@ -1420,14 +1414,14 @@ PHP_FUNCTION(umask) BG(umask) = oldumask; } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &arg1) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &mask) == FAILURE) { RETURN_FALSE; } if (ZEND_NUM_ARGS() == 0) { umask(oldumask); } else { - umask((int)arg1); + umask((int) mask); } RETURN_LONG(oldumask); @@ -1438,15 +1432,15 @@ PHP_FUNCTION(umask) Output all remaining data from a file pointer */ PHPAPI PHP_FUNCTION(fpassthru) { - zval *arg1; + zval *res; size_t size; php_stream *stream; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) { RETURN_FALSE; } - PHP_STREAM_TO_ZVAL(stream, arg1); + PHP_STREAM_TO_ZVAL(stream, res); size = php_stream_passthru(stream); RETURN_LONG(size); @@ -1780,15 +1774,15 @@ safe_to_copy: Binary-safe file read */ PHPAPI PHP_FUNCTION(fread) { - zval *arg1; + zval *res; zend_long len; php_stream *stream; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &arg1, &len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &res, &len) == FAILURE) { RETURN_FALSE; } - PHP_STREAM_TO_ZVAL(stream, arg1); + PHP_STREAM_TO_ZVAL(stream, res); if (len <= 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter must be greater than 0"); diff --git a/ext/standard/ftp_fopen_wrapper.c b/ext/standard/ftp_fopen_wrapper.c index ed93345bac..01522bc7a9 100644 --- a/ext/standard/ftp_fopen_wrapper.c +++ b/ext/standard/ftp_fopen_wrapper.c @@ -635,11 +635,10 @@ static size_t php_ftp_dirstream_read(php_stream *stream, char *buf, size_t count zend_string_release(basename); /* Trim off trailing whitespace characters */ - tmp_len--; while (tmp_len > 0 && - (ent->d_name[tmp_len] == '\n' || ent->d_name[tmp_len] == '\r' || - ent->d_name[tmp_len] == '\t' || ent->d_name[tmp_len] == ' ')) { - ent->d_name[tmp_len--] = '\0'; + (ent->d_name[tmp_len - 1] == '\n' || ent->d_name[tmp_len - 1] == '\r' || + ent->d_name[tmp_len - 1] == '\t' || ent->d_name[tmp_len - 1] == ' ')) { + ent->d_name[--tmp_len] = '\0'; } return sizeof(php_stream_dirent); diff --git a/ext/standard/incomplete_class.c b/ext/standard/incomplete_class.c index 011407da29..bb1b9c5a6a 100644 --- a/ext/standard/incomplete_class.c +++ b/ext/standard/incomplete_class.c @@ -150,7 +150,7 @@ PHPAPI zend_string *php_lookup_class_name(zval *object) /* {{{ php_store_class_name */ -PHPAPI void php_store_class_name(zval *object, const char *name, uint32_t len) +PHPAPI void php_store_class_name(zval *object, const char *name, size_t len) { zval val; TSRMLS_FETCH(); diff --git a/ext/standard/password.c b/ext/standard/password.c index c58c28ab3c..4f211dd35f 100644 --- a/ext/standard/password.c +++ b/ext/standard/password.c @@ -345,12 +345,11 @@ PHP_FUNCTION(password_hash) if (options && (option_buffer = zend_symtable_str_find(options, "salt", sizeof("salt")-1)) != NULL) { char *buffer; - size_t buffer_len_int = 0; - size_t buffer_len; + size_t buffer_len = 0; switch (Z_TYPE_P(option_buffer)) { case IS_STRING: buffer = estrndup(Z_STRVAL_P(option_buffer), Z_STRLEN_P(option_buffer)); - buffer_len_int = Z_STRLEN_P(option_buffer); + buffer_len = Z_STRLEN_P(option_buffer); break; case IS_LONG: case IS_DOUBLE: @@ -361,7 +360,7 @@ PHP_FUNCTION(password_hash) convert_to_string(&cast_option_buffer); if (Z_TYPE(cast_option_buffer) == IS_STRING) { buffer = estrndup(Z_STRVAL(cast_option_buffer), Z_STRLEN(cast_option_buffer)); - buffer_len_int = Z_STRLEN(cast_option_buffer); + buffer_len = Z_STRLEN(cast_option_buffer); zval_dtor(&cast_option_buffer); break; } @@ -377,16 +376,19 @@ PHP_FUNCTION(password_hash) php_error_docref(NULL TSRMLS_CC, E_WARNING, "Non-string salt parameter supplied"); RETURN_NULL(); } - if (buffer_len_int < 0) { + + /* XXX all the crypt related APIs work with int for string length. + That should be revised for size_t and then we maybe don't require + the > INT_MAX check. */ + if (buffer_len > INT_MAX) { efree(hash_format); efree(buffer); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Supplied salt is too long"); - } - buffer_len = (size_t) buffer_len_int; - if (buffer_len < required_salt_len) { + RETURN_NULL(); + } else if (buffer_len < required_salt_len) { efree(hash_format); efree(buffer); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Provided salt is too short: %lu expecting %lu", (unsigned long) buffer_len, (unsigned long) required_salt_len); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Provided salt is too short: %zd expecting %zd", buffer_len, required_salt_len); RETURN_NULL(); } else if (php_password_salt_is_alphabet(buffer, buffer_len) == FAILURE) { salt = safe_emalloc(required_salt_len, 1, 1); @@ -394,7 +396,7 @@ PHP_FUNCTION(password_hash) efree(hash_format); efree(buffer); efree(salt); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Provided salt is too short: %lu", (unsigned long) buffer_len); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Provided salt is too short: %zd", buffer_len); RETURN_NULL(); } salt_len = required_salt_len; diff --git a/ext/standard/php_fopen_wrapper.c b/ext/standard/php_fopen_wrapper.c index 1989a2eabc..8026b08d45 100644 --- a/ext/standard/php_fopen_wrapper.c +++ b/ext/standard/php_fopen_wrapper.c @@ -418,7 +418,7 @@ static php_stream_wrapper_ops php_stdio_wops = { NULL /* rmdir */ }; -php_stream_wrapper php_stream_php_wrapper = { +PHPAPI php_stream_wrapper php_stream_php_wrapper = { &php_stdio_wops, NULL, 0, /* is_url */ diff --git a/ext/standard/php_fopen_wrappers.h b/ext/standard/php_fopen_wrappers.h index 084efc291c..6d6a5bde27 100644 --- a/ext/standard/php_fopen_wrappers.h +++ b/ext/standard/php_fopen_wrappers.h @@ -27,7 +27,7 @@ php_stream *php_stream_url_wrap_http(php_stream_wrapper *wrapper, const char *pa php_stream *php_stream_url_wrap_ftp(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC); extern PHPAPI php_stream_wrapper php_stream_http_wrapper; extern PHPAPI php_stream_wrapper php_stream_ftp_wrapper; -extern php_stream_wrapper php_stream_php_wrapper; -extern php_stream_wrapper php_plain_files_wrapper; +extern PHPAPI php_stream_wrapper php_stream_php_wrapper; +extern PHPAPI php_stream_wrapper php_plain_files_wrapper; #endif diff --git a/ext/standard/php_incomplete_class.h b/ext/standard/php_incomplete_class.h index 177e960765..fa2747f3bf 100644 --- a/ext/standard/php_incomplete_class.h +++ b/ext/standard/php_incomplete_class.h @@ -54,7 +54,7 @@ extern "C" { PHPAPI zend_class_entry *php_create_incomplete_class(TSRMLS_D); PHPAPI zend_string *php_lookup_class_name(zval *object); -PHPAPI void php_store_class_name(zval *object, const char *name, uint32_t len); +PHPAPI void php_store_class_name(zval *object, const char *name, size_t len); #ifdef __cplusplus }; diff --git a/ext/standard/tests/file/bug52820.phpt b/ext/standard/tests/file/bug52820.phpt index 3a9f9c31a4..a00ebf50b6 100644 --- a/ext/standard/tests/file/bug52820.phpt +++ b/ext/standard/tests/file/bug52820.phpt @@ -1,71 +1,63 @@ ---TEST--
-Bug #52820 (writes to fopencookie FILE* not committed when seeking the stream)
---SKIPIF--
-<?php
-if (!function_exists('leak_variable'))
- die("skip only for debug builds");
-/* unfortunately no standard function does a cast to FILE*, so we need
- * curl to test this */
-if (!extension_loaded("curl")) exit("skip curl extension not loaded");
-$handle=curl_init('http://127.0.0.1:37349/');
-curl_setopt($handle, CURLOPT_VERBOSE, true);
-curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
-if (!curl_setopt($handle, CURLOPT_STDERR, fopen("php://memory", "w+")))
- die("skip fopencookie not supported on this platform");
---FILE--
-<?php
-function do_stuff($url) {
- $handle=curl_init('http://127.0.0.1:37349/');
- curl_setopt($handle, CURLOPT_VERBOSE, true);
- curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($handle, CURLOPT_STDERR, $o = fopen($url, "w+"));
- curl_exec($handle);
- echo "About to rewind!\n";
- rewind($o);
- echo stream_get_contents($o);
- return $o;
-}
-
-echo "temp stream (close after):\n";
-fclose(do_stuff("php://temp"));
-
-echo "\nmemory stream (close after):\n";
-fclose(do_stuff("php://memory"));
-
-echo "\ntemp stream (leak):\n";
-leak_variable(do_stuff("php://temp"), true);
-
-echo "\nmemory stream (leak):\n";
-leak_variable(do_stuff("php://memory"), true);
-
-echo "\nDone.\n";
---EXPECTF--
-temp stream (close after):
-About to rewind!
-* About to connect() to 127.0.0.1 port 37349%r.*%r
-* Trying 127.0.0.1...%A* Connection refused
-* couldn't connect to host%S
-* Closing connection #0
-
-memory stream (close after):
-About to rewind!
-* About to connect() to 127.0.0.1 port 37349%r.*%r
-* Trying 127.0.0.1...%A* Connection refused
-* couldn't connect to host%S
-* Closing connection #0
-
-temp stream (leak):
-About to rewind!
-* About to connect() to 127.0.0.1 port 37349%r.*%r
-* Trying 127.0.0.1...%A* Connection refused
-* couldn't connect to host%S
-* Closing connection #0
-
-memory stream (leak):
-About to rewind!
-* About to connect() to 127.0.0.1 port 37349%r.*%r
-* Trying 127.0.0.1...%A* Connection refused
-* couldn't connect to host%S
-* Closing connection #0
-
-Done.
+--TEST-- +Bug #52820 (writes to fopencookie FILE* not committed when seeking the stream) +--SKIPIF-- +<?php +if (!function_exists('leak_variable')) + die("skip only for debug builds"); +/* unfortunately no standard function does a cast to FILE*, so we need + * curl to test this */ +if (!extension_loaded("curl")) exit("skip curl extension not loaded"); +$handle=curl_init('http://127.0.0.1:37349/'); +curl_setopt($handle, CURLOPT_VERBOSE, true); +curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); +if (!curl_setopt($handle, CURLOPT_STDERR, fopen("php://memory", "w+"))) + die("skip fopencookie not supported on this platform"); +--FILE-- +<?php +function do_stuff($url) { + $handle=curl_init('http://127.0.0.1:37349/'); + curl_setopt($handle, CURLOPT_VERBOSE, true); + curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); + curl_setopt($handle, CURLOPT_STDERR, $o = fopen($url, "w+")); + curl_exec($handle); + echo "About to rewind!\n"; + rewind($o); + echo stream_get_contents($o); + return $o; +} + +echo "temp stream (close after):\n"; +fclose(do_stuff("php://temp")); + +echo "\nmemory stream (close after):\n"; +fclose(do_stuff("php://memory")); + +echo "\ntemp stream (leak):\n"; +leak_variable(do_stuff("php://temp"), true); + +echo "\nmemory stream (leak):\n"; +leak_variable(do_stuff("php://memory"), true); + +echo "\nDone.\n"; +--EXPECTF-- +temp stream (close after): +About to rewind! +* %ATrying 127.0.0.1...%AConnection refused%A +* Closing connection%A%d + +memory stream (close after): +About to rewind! +* %ATrying 127.0.0.1...%AConnection refused%A +* Closing connection%A%d + +temp stream (leak): +About to rewind! +* %ATrying 127.0.0.1...%AConnection refused%A +* Closing connection%A%d + +memory stream (leak): +About to rewind! +* %ATrying 127.0.0.1...%AConnection refused%A +* Closing connection%A%d + +Done. diff --git a/ext/standard/url_scanner_ex.c b/ext/standard/url_scanner_ex.c index 3d7aa985b8..6b406e673f 100644 --- a/ext/standard/url_scanner_ex.c +++ b/ext/standard/url_scanner_ex.c @@ -79,7 +79,7 @@ static PHP_INI_MH(OnUpdateTags) val = strchr(key, '='); if (val) { char *q; - int keylen; + size_t keylen; *val++ = '\0'; for (q = key; *q; q++) @@ -351,7 +351,7 @@ static inline void xx_mainloop(url_adapt_state_ex_t *ctx, const char *newdata, s char *end, *q; char *xp; char *start; - int rest; + size_t rest; smart_str_appendl(&ctx->buf, newdata, newlen); @@ -906,10 +906,13 @@ yy76: stop: - rest = YYLIMIT - start; - scdebug(("stopped in state %d at pos %d (%d:%c) %d\n", STATE, YYCURSOR - ctx->buf.c, *YYCURSOR, *YYCURSOR, rest)); - /* XXX: Crash avoidance. Need to work with reporter to figure out what goes wrong */ - if (rest < 0) rest = 0; + if (YYLIMIT < start) { + /* XXX: Crash avoidance. Need to work with reporter to figure out what goes wrong */ + rest = 0; + } else { + rest = YYLIMIT - start; + scdebug(("stopped in state %d at pos %d (%d:%c) %d\n", STATE, YYCURSOR - ctx->buf.c, *YYCURSOR, *YYCURSOR, rest)); + } if (rest) memmove(ctx->buf.s->val, start, rest); ctx->buf.s->len = rest; @@ -993,7 +996,7 @@ static int php_url_scanner_ex_deactivate(TSRMLS_D) return SUCCESS; } -static void php_url_scanner_output_handler(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode TSRMLS_DC) +static void php_url_scanner_output_handler(char *output, size_t output_len, char **handled_output, size_t *handled_output_len, int mode TSRMLS_DC) { size_t len; @@ -1023,7 +1026,7 @@ static void php_url_scanner_output_handler(char *output, uint output_len, char * } } -PHPAPI int php_url_scanner_add_var(char *name, int name_len, char *value, int value_len, int urlencode TSRMLS_DC) +PHPAPI int php_url_scanner_add_var(char *name, size_t name_len, char *value, size_t value_len, int urlencode TSRMLS_DC) { smart_str val = {0}; zend_string *encoded; diff --git a/ext/standard/url_scanner_ex.h b/ext/standard/url_scanner_ex.h index 3c5b68c95b..2a9b6921bf 100644 --- a/ext/standard/url_scanner_ex.h +++ b/ext/standard/url_scanner_ex.h @@ -28,7 +28,7 @@ PHP_RINIT_FUNCTION(url_scanner_ex); PHP_RSHUTDOWN_FUNCTION(url_scanner_ex); PHPAPI char *php_url_scanner_adapt_single_url(const char *url, size_t urllen, const char *name, const char *value, size_t *newlen TSRMLS_DC); -PHPAPI int php_url_scanner_add_var(char *name, int name_len, char *value, int value_len, int urlencode TSRMLS_DC); +PHPAPI int php_url_scanner_add_var(char *name, size_t name_len, char *value, size_t value_len, int urlencode TSRMLS_DC); PHPAPI int php_url_scanner_reset_vars(TSRMLS_D); #include "zend_smart_str_public.h" diff --git a/ext/standard/url_scanner_ex.re b/ext/standard/url_scanner_ex.re index 2e74b1fb30..fed628f089 100644 --- a/ext/standard/url_scanner_ex.re +++ b/ext/standard/url_scanner_ex.re @@ -77,7 +77,7 @@ static PHP_INI_MH(OnUpdateTags) val = strchr(key, '='); if (val) { char *q; - int keylen; + size_t keylen; *val++ = '\0'; for (q = key; *q; q++) @@ -287,7 +287,7 @@ static inline void xx_mainloop(url_adapt_state_ex_t *ctx, const char *newdata, s char *end, *q; char *xp; char *start; - int rest; + size_t rest; smart_str_appendl(&ctx->buf, newdata, newlen); @@ -358,10 +358,13 @@ state_val: */ stop: - rest = YYLIMIT - start; - scdebug(("stopped in state %d at pos %d (%d:%c) %d\n", STATE, YYCURSOR - ctx->buf.c, *YYCURSOR, *YYCURSOR, rest)); - /* XXX: Crash avoidance. Need to work with reporter to figure out what goes wrong */ - if (rest < 0) rest = 0; + if (YYLIMIT < start) { + /* XXX: Crash avoidance. Need to work with reporter to figure out what goes wrong */ + rest = 0; + } else { + rest = YYLIMIT - start; + scdebug(("stopped in state %d at pos %d (%d:%c) %d\n", STATE, YYCURSOR - ctx->buf.c, *YYCURSOR, *YYCURSOR, rest)); + } if (rest) memmove(ctx->buf.s->val, start, rest); ctx->buf.s->len = rest; @@ -445,7 +448,7 @@ static int php_url_scanner_ex_deactivate(TSRMLS_D) return SUCCESS; } -static void php_url_scanner_output_handler(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode TSRMLS_DC) +static void php_url_scanner_output_handler(char *output, size_t output_len, char **handled_output, size_t *handled_output_len, int mode TSRMLS_DC) { size_t len; @@ -475,7 +478,7 @@ static void php_url_scanner_output_handler(char *output, uint output_len, char * } } -PHPAPI int php_url_scanner_add_var(char *name, int name_len, char *value, int value_len, int urlencode TSRMLS_DC) +PHPAPI int php_url_scanner_add_var(char *name, size_t name_len, char *value, size_t value_len, int urlencode TSRMLS_DC) { smart_str val = {0}; zend_string *encoded; diff --git a/ext/standard/user_filters.c b/ext/standard/user_filters.c index 19e8e454df..f310e64ae9 100644 --- a/ext/standard/user_filters.c +++ b/ext/standard/user_filters.c @@ -221,7 +221,7 @@ php_stream_filter_status_t userfilter_filter( if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) { convert_to_long(&retval); - ret = Z_LVAL(retval); + ret = (int)Z_LVAL(retval); } else if (call_result == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to call filter function"); } @@ -287,7 +287,7 @@ static php_stream_filter *user_filter_factory_create(const char *filtername, return NULL; } - len = strlen(filtername); + len = (int)strlen(filtername); /* determine the classname/class entry */ if (NULL == (fdat = zend_hash_str_find_ptr(BG(user_filter_map), (char*)filtername, len))) { |
