Skip to content

Commit 2363825

Browse files
committed
Adjust or fork tests for libxml 2.9.12
1 parent 4db8275 commit 2363825

File tree

7 files changed

+146
-8
lines changed

7 files changed

+146
-8
lines changed

ext/dom/tests/bug43364.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ $doc->xinclude();
3636

3737
$count = loopElements(array($doc->documentElement));
3838

39-
var_dump($count);
39+
var_dump($count == 13 || $count == 11);
4040
?>
4141
--EXPECT--
42-
int(13)
42+
bool(true)

ext/dom/tests/bug80268.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
Bug #80268 (loadHTML() truncates at NUL bytes)
33
--EXTENSIONS--
44
dom
5+
--SKIPIF--
6+
<?php
7+
if (LIBXML_VERSION >= 20912) die('skip For libxml2 < 2.9.12 only');
8+
?>
59
--FILE--
610
<?php
711
$doc = new DOMDocument;

ext/dom/tests/bug80268_2.phpt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
Bug #80268 (loadHTML() truncates at NUL bytes)
3+
--EXTENSIONS--
4+
dom
5+
--SKIPIF--
6+
<?php
7+
if (LIBXML_VERSION < 20912) die('skip For libxml2 >= 2.9.12 only');
8+
?>
9+
--FILE--
10+
<?php
11+
$doc = new DOMDocument;
12+
$doc->loadHTML("<p>foo\0bar</p>");
13+
$html = $doc->saveHTML();
14+
var_dump(strpos($html, '<p>foo</p>') !== false);
15+
16+
file_put_contents(__DIR__ . '/80268.html', "<p>foo\0bar</p>");
17+
$doc = new DOMDocument;
18+
$doc->loadHTMLFile(__DIR__ . '/80268.html');
19+
$html = $doc->saveHTML();
20+
var_dump(strpos($html, '<p>foo</p>') !== false);
21+
?>
22+
--CLEAN--
23+
<?php
24+
unlink(__DIR__ . '/80268.html');
25+
?>
26+
--EXPECTF--
27+
Warning: DOMDocument::loadHTML(): Char 0x0 out of allowed range in Entity, line: 1 in %s on line %d
28+
bool(false)
29+
30+
Warning: DOMDocument::loadHTMLFile(): Char 0x0 out of allowed range in %s on line %d
31+
bool(false)

ext/libxml/tests/bug61367-read.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
--TEST--
22
Bug #61367: open_basedir bypass in libxml RSHUTDOWN: read test
33
--SKIPIF--
4-
<?php if(!extension_loaded('dom')) echo 'skip dom extension not available'; ?>
4+
<?php
5+
if(!extension_loaded('dom')) echo 'skip dom extension not available';
6+
if (LIBXML_VERSION >= 20912) die('skip For libxml2 < 2.9.12 only');
7+
?>
58
--INI--
69
open_basedir=.
710
--FILE--

ext/libxml/tests/bug61367-read_2.phpt

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
--TEST--
2+
Bug #61367: open_basedir bypass in libxml RSHUTDOWN: read test
3+
--SKIPIF--
4+
<?php
5+
if(!extension_loaded('dom')) echo 'skip dom extension not available';
6+
if (LIBXML_VERSION < 20912) die('skip For libxml2 >= 2.9.12 only');
7+
?>
8+
--INI--
9+
open_basedir=.
10+
--FILE--
11+
<?php
12+
/*
13+
* Note: Using error_reporting=E_ALL & ~E_NOTICE to suppress "Trying to get property of non-object" notices.
14+
*/
15+
class StreamExploiter {
16+
public function stream_close ( ) {
17+
$doc = new DOMDocument;
18+
$doc->resolveExternals = true;
19+
$doc->substituteEntities = true;
20+
$dir = htmlspecialchars(dirname(getcwd()));
21+
$dir = str_replace('\\', '/', $dir); // fix for windows
22+
$doc->loadXML( <<<XML
23+
<!DOCTYPE doc [
24+
<!ENTITY file SYSTEM "file:///$dir/bad">
25+
]>
26+
<doc>&file;</doc>
27+
XML
28+
);
29+
print $doc->documentElement->firstChild->nodeValue;
30+
}
31+
32+
public function stream_open ( $path , $mode , $options , &$opened_path ) {
33+
return true;
34+
}
35+
}
36+
37+
var_dump(mkdir('test_bug_61367-read'));
38+
var_dump(mkdir('test_bug_61367-read/base'));
39+
var_dump(file_put_contents('test_bug_61367-read/bad', 'blah'));
40+
var_dump(chdir('test_bug_61367-read/base'));
41+
42+
stream_wrapper_register( 'exploit', 'StreamExploiter' );
43+
$s = fopen( 'exploit://', 'r' );
44+
45+
?>
46+
--CLEAN--
47+
<?php
48+
unlink('test_bug_61367-read/bad');
49+
rmdir('test_bug_61367-read/base');
50+
rmdir('test_bug_61367-read');
51+
?>
52+
--EXPECTF--
53+
bool(true)
54+
bool(true)
55+
int(4)
56+
bool(true)
57+
58+
Warning: DOMDocument::loadXML(): I/O warning : failed to load external entity "file:///%s/test_bug_61367-read/bad" in %s on line %d
59+
60+
Warning: Attempt to read property "nodeValue" on null in %s on line %d

ext/libxml/tests/libxml_disable_entity_loader.phpt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ libxml_disable_entity_loader()
44
<?php
55
if (!extension_loaded('libxml')) die('skip libxml extension not available');
66
if (!extension_loaded('dom')) die('skip dom extension not available');
7+
if (LIBXML_VERSION >= 20912) die('skip For libxml2 < 2.9.12 only');
78
--FILE--
89
<?php
910

@@ -37,10 +38,6 @@ bool(true)
3738
Deprecated: Function libxml_disable_entity_loader() is deprecated in %s on line %d
3839
bool(false)
3940

40-
Warning: DOMDocument::loadXML(): I/O warning : failed to load external entity "%s" in %s on line %d
41-
42-
Warning: DOMDocument::loadXML(): Failure to process entity xxe in Entity, line: %d in %s on line %d
43-
44-
Warning: DOMDocument::loadXML(): Entity 'xxe' not defined in Entity, line: %d in %s on line %d
41+
Warning: DOMDocument::loadXML(): I/O warning : failed to load external entity "/home/nikic/php/php-src/ext/libxml/tests/libxml_disable_entity_loader_payload.txt" in %s on line %d
4542
bool(true)
4643
Done
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--TEST--
2+
libxml_disable_entity_loader()
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('libxml')) die('skip libxml extension not available');
6+
if (!extension_loaded('dom')) die('skip dom extension not available');
7+
if (LIBXML_VERSION < 20912) die('skip For libxml2 >= 2.9.12 only');
8+
--FILE--
9+
<?php
10+
11+
$xml = <<<EOT
12+
<?xml version="1.0" encoding="UTF-8"?>
13+
<!DOCTYPE test [<!ENTITY xxe SYSTEM "XXE_URI">]>
14+
<foo>&xxe;</foo>
15+
EOT;
16+
17+
$dir = str_replace('\\', '/', __DIR__);
18+
$xml = str_replace('XXE_URI', $dir . '/libxml_disable_entity_loader_payload.txt', $xml);
19+
20+
function parseXML($xml) {
21+
$doc = new DOMDocument();
22+
$doc->resolveExternals = true;
23+
$doc->substituteEntities = true;
24+
$doc->validateOnParse = false;
25+
$doc->loadXML($xml, 0);
26+
return $doc->saveXML();
27+
}
28+
29+
var_dump(strpos(parseXML($xml), 'SECRET_DATA') !== false);
30+
var_dump(libxml_disable_entity_loader(true));
31+
var_dump(strpos(parseXML($xml), 'SECRET_DATA') === false);
32+
33+
echo "Done\n";
34+
?>
35+
--EXPECTF--
36+
bool(true)
37+
38+
Deprecated: Function libxml_disable_entity_loader() is deprecated in %s on line %d
39+
bool(false)
40+
41+
Warning: DOMDocument::loadXML(): I/O warning : failed to load external entity "/home/nikic/php/php-src/ext/libxml/tests/libxml_disable_entity_loader_payload.txt" in %s on line %d
42+
bool(true)
43+
Done

0 commit comments

Comments
 (0)