1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Improve warning when returning null from the resolver set by libxml_set_external_entity_loader

Fixes GH-11952.
Closes GH-12022.
This commit is contained in:
Niels Dossche
2023-08-22 20:28:07 +02:00
parent 3e0e7e3f90
commit e1cb721679
3 changed files with 41 additions and 3 deletions

4
NEWS
View File

@@ -7,6 +7,10 @@ PHP NEWS
. Introduced Zend guard recursion protection to fix __debugInfo issue.
(Jakub Zelenka)
- DOM:
. Fixed GH-11952 (Confusing warning when blocking entity loading via
libxml_set_external_entity_loader). (nielsdos)
- Standard:
. Added $before_needle argument to strrchr(). (HypeMC)

View File

@@ -784,10 +784,12 @@ is_string:
if (ret == NULL) {
if (resource == NULL) {
if (ID == NULL) {
ID = "NULL";
php_libxml_ctx_error(context,
"Failed to load external entity because the resolver function returned null\n");
} else {
php_libxml_ctx_error(context,
"Failed to load external entity \"%s\"\n", ID);
}
php_libxml_ctx_error(context,
"Failed to load external entity \"%s\"\n", ID);
} else {
/* we got the resource in the form of a string; open it */
ret = xmlNewInputFromFile(context, resource);

View File

@@ -0,0 +1,32 @@
--TEST--
null returned by resolver function
--EXTENSIONS--
libxml
dom
--FILE--
<?php
libxml_set_external_entity_loader(function ($public_id, $system_id, $context) {
var_dump($public_id, $system_id, $context);
return null;
});
$doc = new DOMDocument();
$doc->loadHTMLFile("foobar");
?>
--EXPECTF--
NULL
string(6) "foobar"
array(4) {
["directory"]=>
NULL
["intSubName"]=>
NULL
["extSubURI"]=>
NULL
["extSubSystem"]=>
NULL
}
Warning: DOMDocument::loadHTMLFile(): Failed to load external entity because the resolver function returned null in %s on line %d