Skip to content

Commit d8ad2f4

Browse files
committed
Fixed bug #79029 (Use After Free's in XMLReader / XMLWriter)
1 parent b5e0043 commit d8ad2f4

File tree

4 files changed

+37
-13
lines changed

4 files changed

+37
-13
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ PHP NEWS
4848
. Fixed bug #79000 (Non-blocking socket stream reports EAGAIN as error).
4949
(Nikita)
5050

51+
- Libxml:
52+
. Fixed bug #79029 (Use After Free's in XMLReader / XMLWriter). (Laruence)
53+
5154
18 Dec 2019, PHP 7.4.1
5255

5356
- Core:

ext/libxml/libxml.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ static void *php_libxml_streams_IO_open_wrapper(const char *filename, const char
355355
context = php_stream_context_from_zval(Z_ISUNDEF(LIBXML(stream_context))? NULL : &LIBXML(stream_context), 0);
356356

357357
ret_val = php_stream_open_wrapper_ex(path_to_open, (char *)mode, REPORT_ERRORS, NULL, context);
358+
/* Prevent from closing this by fclose() */
359+
((php_stream*)ret_val)->flags |= PHP_STREAM_FLAG_NO_FCLOSE;
358360
if (isescaped) {
359361
xmlFree(resolved_path);
360362
}

ext/xmlwriter/tests/bug79029.phpt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
#79029 (Use After Free's in XMLReader / XMLWriter)
3+
--SKIPIF--
4+
<?php if (!extension_loaded("xmlwriter")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
$x = array( new XMLWriter() );
8+
$x[0]->openUri("bug79029.txt");
9+
$x[0]->startComment();
10+
@unlink("bug79029.txt");
11+
12+
$x = new XMLWriter();
13+
$x->openUri("bug79029.txt");
14+
fclose(@end(get_resources()));
15+
@unlink("bug79029.txt");
16+
17+
file_put_contents("bug79029.txt", "a");
18+
$x = new XMLReader();
19+
$x->open("bug79029.txt");
20+
fclose(@end(get_resources()));
21+
@unlink("bug79029.txt");
22+
?>
23+
okey
24+
--CLEAN--
25+
<?php
26+
@unlink("bug79029.txt");
27+
?>
28+
--EXPECTF--
29+
Warning: fclose(): %d is not a valid stream resource in %sbug79029.php on line %d
30+
31+
Warning: fclose(): %d is not a valid stream resource in %sbug79029.php on line %d
32+
okey

ext/xmlwriter/tests/bug79029_1.phpt

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)