Skip to content

Commit e757ef0

Browse files
committed
Fix phpGH-15908 and phpGH-15026: leak / assertion failure in streams.c
This was first reported as a leak in phpGH-15026, but was mistakingly believed to be a false positive. Then an assertion was added and it got triggered in phpGH-15908. This fixes the leak. Upon merging into master the assertion should be removed as well.
1 parent b26e610 commit e757ef0

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--TEST--
2+
GH-15908 (leak / assertion failure in streams.c)
3+
--CREDITS--
4+
YuanchengJiang
5+
LuMingYinDetect
6+
--FILE--
7+
<?php
8+
class TestStream {
9+
public $context;
10+
private $s = 0;
11+
function stream_open($path, $mode, $options, &$opened_path) {
12+
return true;
13+
}
14+
function stream_read($count) {
15+
echo "Read done\n";
16+
if ($this->s++ == 0)
17+
return "a\nbb\ncc";
18+
return "";
19+
}
20+
function stream_eof() {
21+
return $this->s >= 2;
22+
}
23+
}
24+
touch(__DIR__."/gh15908.tmp");
25+
stream_wrapper_register("test", "TestStream");
26+
$f = fopen("test://", "r");
27+
try {
28+
file_put_contents(__DIR__."/gh15908.tmp", $f, FILE_USE_INCLUDE_PATH, $f);
29+
} catch (Error $e) {
30+
echo $e->getMessage(), "\n";
31+
}
32+
?>
33+
--CLEAN--
34+
<?php
35+
@unlink(__DIR__."/gh15908.tmp");
36+
?>
37+
--EXPECT--
38+
file_put_contents(): supplied resource is not a valid Stream-Context resource

main/streams/streams.c

+3
Original file line numberDiff line numberDiff line change
@@ -2175,6 +2175,9 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod
21752175
options &= ~USE_PATH;
21762176
}
21772177
if (EG(exception)) {
2178+
if (resolved_path) {
2179+
zend_string_release_ex(resolved_path, false);
2180+
}
21782181
return NULL;
21792182
}
21802183
}

0 commit comments

Comments
 (0)