Skip to content

Commit

Permalink
Fixed Bug #61961 (file_get_content leaks when access empty file with …
Browse files Browse the repository at this point in the history
…max length)
  • Loading branch information
reeze committed May 6, 2012
1 parent 0956c00 commit 3e9923d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
14 changes: 14 additions & 0 deletions ext/standard/tests/file/bug61961.phpt
Original file line number Diff line number Diff line change
@@ -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==
7 changes: 6 additions & 1 deletion main/streams/streams.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 3e9923d

Please sign in to comment.