Skip to content

Fix tests for libxml 2.9.12 #7046

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/dom/tests/DOMDocument_loadXML_error1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ domdocumentloadxml_test_method.inc
--EXPECTF--
Warning: DOMDocument::load%r(XML){0,1}%r(): Opening and ending tag mismatch: title line 5 and book %s

Warning: DOMDocument::load%r(XML){0,1}%r(): %rexpected '>'|Opening and ending tag mismatch: book line 5 and books%r %s
Warning: DOMDocument::load%r(XML){0,1}%r(): %rexpected '>'|Opening and ending tag mismatch: book line (4|5) and books%r %s

Warning: DOMDocument::load%r(XML){0,1}%r(): %rPremature end of data in tag books|EndTag: '<\/' not found in Entity, line: 13%r %s
2 changes: 1 addition & 1 deletion ext/dom/tests/DOMDocument_load_error1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ domdocumentload_test_method.inc
--EXPECTF--
Warning: DOMDocument::load%r(XML){0,1}%r(): Opening and ending tag mismatch: title line 5 and book %s

Warning: DOMDocument::load%r(XML){0,1}%r(): %rexpected '>'|Opening and ending tag mismatch: book line 5 and books%r %s
Warning: DOMDocument::load%r(XML){0,1}%r(): %rexpected '>'|Opening and ending tag mismatch: book line (4|5) and books%r %s

Warning: DOMDocument::load%r(XML){0,1}%r(): %rPremature end of data in tag books|EndTag: '<\/' not found%r %s
4 changes: 2 additions & 2 deletions ext/dom/tests/bug43364.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ $doc->xinclude();

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

var_dump($count);
var_dump($count == 13 || $count == 11);
?>
--EXPECT--
int(13)
bool(true)
4 changes: 4 additions & 0 deletions ext/dom/tests/bug80268.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Bug #80268 (loadHTML() truncates at NUL bytes)
--EXTENSIONS--
dom
--SKIPIF--
<?php
if (LIBXML_VERSION >= 20912) die('skip For libxml2 < 2.9.12 only');
?>
--FILE--
<?php
$doc = new DOMDocument;
Expand Down
31 changes: 31 additions & 0 deletions ext/dom/tests/bug80268_2.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
--TEST--
Bug #80268 (loadHTML() truncates at NUL bytes)
--EXTENSIONS--
dom
--SKIPIF--
<?php
if (LIBXML_VERSION < 20912) die('skip For libxml2 >= 2.9.12 only');
?>
--FILE--
<?php
$doc = new DOMDocument;
$doc->loadHTML("<p>foo\0bar</p>");
$html = $doc->saveHTML();
var_dump(strpos($html, '<p>foo</p>') !== false);

file_put_contents(__DIR__ . '/80268.html', "<p>foo\0bar</p>");
$doc = new DOMDocument;
$doc->loadHTMLFile(__DIR__ . '/80268.html');
$html = $doc->saveHTML();
var_dump(strpos($html, '<p>foo</p>') !== false);
?>
--CLEAN--
<?php
unlink(__DIR__ . '/80268.html');
?>
--EXPECTF--
Warning: DOMDocument::loadHTML(): Char 0x0 out of allowed range in Entity, line: 1 in %s on line %d
bool(false)

Warning: DOMDocument::loadHTMLFile(): Char 0x0 out of allowed range in %s on line %d
bool(false)
5 changes: 4 additions & 1 deletion ext/libxml/tests/bug61367-read.phpt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
--TEST--
Bug #61367: open_basedir bypass in libxml RSHUTDOWN: read test
--SKIPIF--
<?php if(!extension_loaded('dom')) echo 'skip dom extension not available'; ?>
<?php
if(!extension_loaded('dom')) echo 'skip dom extension not available';
if (LIBXML_VERSION >= 20912) die('skip For libxml2 < 2.9.12 only');
?>
--INI--
open_basedir=.
--FILE--
Expand Down
60 changes: 60 additions & 0 deletions ext/libxml/tests/bug61367-read_2.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
--TEST--
Bug #61367: open_basedir bypass in libxml RSHUTDOWN: read test
--SKIPIF--
<?php
if(!extension_loaded('dom')) echo 'skip dom extension not available';
if (LIBXML_VERSION < 20912) die('skip For libxml2 >= 2.9.12 only');
?>
--INI--
open_basedir=.
--FILE--
<?php
/*
* Note: Using error_reporting=E_ALL & ~E_NOTICE to suppress "Trying to get property of non-object" notices.
*/
class StreamExploiter {
public function stream_close ( ) {
$doc = new DOMDocument;
$doc->resolveExternals = true;
$doc->substituteEntities = true;
$dir = htmlspecialchars(dirname(getcwd()));
$dir = str_replace('\\', '/', $dir); // fix for windows
$doc->loadXML( <<<XML
<!DOCTYPE doc [
<!ENTITY file SYSTEM "file:///$dir/bad">
]>
<doc>&file;</doc>
XML
);
print $doc->documentElement->firstChild->nodeValue;
}

public function stream_open ( $path , $mode , $options , &$opened_path ) {
return true;
}
}

var_dump(mkdir('test_bug_61367-read'));
var_dump(mkdir('test_bug_61367-read/base'));
var_dump(file_put_contents('test_bug_61367-read/bad', 'blah'));
var_dump(chdir('test_bug_61367-read/base'));

stream_wrapper_register( 'exploit', 'StreamExploiter' );
$s = fopen( 'exploit://', 'r' );

?>
--CLEAN--
<?php
unlink('test_bug_61367-read/bad');
rmdir('test_bug_61367-read/base');
rmdir('test_bug_61367-read');
?>
--EXPECTF--
bool(true)
bool(true)
int(4)
bool(true)

Warning: DOMDocument::loadXML(): I/O warning : failed to load external entity "file:///%s/test_bug_61367-read/bad" in %s on line %d

Warning: Attempt to read property "nodeValue" on null in %s on line %d
1 change: 1 addition & 0 deletions ext/libxml/tests/libxml_disable_entity_loader.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ libxml_disable_entity_loader()
<?php
if (!extension_loaded('libxml')) die('skip libxml extension not available');
if (!extension_loaded('dom')) die('skip dom extension not available');
if (LIBXML_VERSION >= 20912) die('skip For libxml2 < 2.9.12 only');
--FILE--
<?php

Expand Down
43 changes: 43 additions & 0 deletions ext/libxml/tests/libxml_disable_entity_loader_2.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
--TEST--
libxml_disable_entity_loader()
--SKIPIF--
<?php
if (!extension_loaded('libxml')) die('skip libxml extension not available');
if (!extension_loaded('dom')) die('skip dom extension not available');
if (LIBXML_VERSION < 20912) die('skip For libxml2 >= 2.9.12 only');
--FILE--
<?php

$xml = <<<EOT
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE test [<!ENTITY xxe SYSTEM "XXE_URI">]>
<foo>&xxe;</foo>
EOT;

$dir = str_replace('\\', '/', __DIR__);
$xml = str_replace('XXE_URI', $dir . '/libxml_disable_entity_loader_payload.txt', $xml);

function parseXML($xml) {
$doc = new DOMDocument();
$doc->resolveExternals = true;
$doc->substituteEntities = true;
$doc->validateOnParse = false;
$doc->loadXML($xml, 0);
return $doc->saveXML();
}

var_dump(strpos(parseXML($xml), 'SECRET_DATA') !== false);
var_dump(libxml_disable_entity_loader(true));
var_dump(strpos(parseXML($xml), 'SECRET_DATA') === false);

echo "Done\n";
?>
--EXPECTF--
bool(true)

Deprecated: Function libxml_disable_entity_loader() is deprecated in %s on line %d
bool(false)

Warning: DOMDocument::loadXML(): I/O warning : failed to load external entity "%s" in %s on line %d
bool(true)
Done