Skip to content

Commit 311ee8f

Browse files
committed
Merge branch 'pull-request/76' into PHP-5.3
2 parents 4632fe0 + 3e9923d commit 311ee8f

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

ext/standard/tests/file/bug61961.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Bug #61961 (file_get_content leaks when access empty file with max length)
3+
--FILE--
4+
<?php
5+
$tmp_empty_file = __FILE__ . ".tmp";
6+
file_put_contents($tmp_empty_file, "");
7+
8+
var_dump(file_get_contents($tmp_empty_file, NULL, NULL, NULL, 10));
9+
unlink($tmp_empty_file);
10+
?>
11+
==DONE==
12+
--EXPECT--
13+
string(0) ""
14+
==DONE==

main/streams/streams.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1366,7 +1366,12 @@ PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen
13661366
len += ret;
13671367
ptr += ret;
13681368
}
1369-
*ptr = '\0';
1369+
if (len) {
1370+
*ptr = '\0';
1371+
} else {
1372+
pefree(*buf, persistent);
1373+
*buf = NULL;
1374+
}
13701375
return len;
13711376
}
13721377

0 commit comments

Comments
 (0)