diff options
author | Reeze Xia <reeze.xia@gmail.com> | 2012-05-06 18:27:26 +0800 |
---|---|---|
committer | Reeze Xia <reeze.xia@gmail.com> | 2012-05-06 18:27:26 +0800 |
commit | 3e9923dd8d08f88740f58e54386c0f7c569a5aa6 (patch) | |
tree | 9909216ba815fbcbba5018949da10c9a9bfbeacc | |
parent | 0956c00af999c295c5a13644ec835da8f96ad48d (diff) | |
download | php-git-3e9923dd8d08f88740f58e54386c0f7c569a5aa6.tar.gz |
Fixed Bug #61961 (file_get_content leaks when access empty file with max length)
-rw-r--r-- | ext/standard/tests/file/bug61961.phpt | 14 | ||||
-rwxr-xr-x | main/streams/streams.c | 7 |
2 files changed, 20 insertions, 1 deletions
diff --git a/ext/standard/tests/file/bug61961.phpt b/ext/standard/tests/file/bug61961.phpt new file mode 100644 index 0000000000..ff0279a367 --- /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 116c0aa045..fe7800b9fe 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; } |