Permalink
Browse files

Fixed Bug #61961 (file_get_content leaks when access empty file with …

…max length)
  • Loading branch information...
1 parent 0956c00 commit 3e9923dd8d08f88740f58e54386c0f7c569a5aa6 @reeze reeze committed May 6, 2012
Showing with 20 additions and 1 deletion.
  1. +14 −0 ext/standard/tests/file/bug61961.phpt
  2. +6 −1 main/streams/streams.c
@@ -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==
View
@@ -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;
}

0 comments on commit 3e9923d

Please sign in to comment.