Commit: 3e9923dd8d08f88740f58e54386c0f7c569a5aa6 Author: Reeze Xia <reeze....@gmail.com> Sun, 6 May 2012 18:27:26 +0800 Parents: 0956c00af999c295c5a13644ec835da8f96ad48d Branches: PHP-5.3 PHP-5.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=3e9923dd8d08f88740f58e54386c0f7c569a5aa6 Log: Fixed Bug #61961 (file_get_content leaks when access empty file with max length) Bugs: https://bugs.php.net/61961 Changed paths: A ext/standard/tests/file/bug61961.phpt M main/streams/streams.c Diff: diff --git a/ext/standard/tests/file/bug61961.phpt b/ext/standard/tests/file/bug61961.phpt new file mode 100644 index 0000000..ff0279a --- /dev/null +++ b/ext/standard/tests/file/bug61961.phpt @@ -0,0 +1,14 @@ +--TEST-- +Bug #61961 (file_get_content leaks when access empty file with max length) +--FILE-- +<?php +$tmp_empty_file = __FILE__ . ".tmp"; +file_put_contents($tmp_empty_file, ""); + +var_dump(file_get_contents($tmp_empty_file, NULL, NULL, NULL, 10)); +unlink($tmp_empty_file); +?> +==DONE== +--EXPECT-- +string(0) "" +==DONE== \ No newline at end of file diff --git a/main/streams/streams.c b/main/streams/streams.c index 116c0aa..fe7800b 100755 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -1366,7 +1366,12 @@ PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen len += ret; ptr += ret; } - *ptr = '\0'; + if (len) { + *ptr = '\0'; + } else { + pefree(*buf, persistent); + *buf = NULL; + } return len; } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php