From e1cb721679338b33ed2653c945369df6ef1cd10d Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Tue, 22 Aug 2023 20:28:07 +0200 Subject: [PATCH] Improve warning when returning null from the resolver set by libxml_set_external_entity_loader Fixes GH-11952. Closes GH-12022. --- NEWS | 4 +++ ext/libxml/libxml.c | 8 +++-- .../tests/null_returned_by_resolver.phpt | 32 +++++++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 ext/libxml/tests/null_returned_by_resolver.phpt diff --git a/NEWS b/NEWS index 4e2ecddcd85..33a9713ade2 100644 --- a/NEWS +++ b/NEWS @@ -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) diff --git a/ext/libxml/libxml.c b/ext/libxml/libxml.c index 24ba80bd5de..a6f28f0fbad 100644 --- a/ext/libxml/libxml.c +++ b/ext/libxml/libxml.c @@ -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); diff --git a/ext/libxml/tests/null_returned_by_resolver.phpt b/ext/libxml/tests/null_returned_by_resolver.phpt new file mode 100644 index 00000000000..8fdfbc6dc8b --- /dev/null +++ b/ext/libxml/tests/null_returned_by_resolver.phpt @@ -0,0 +1,32 @@ +--TEST-- +null returned by resolver function +--EXTENSIONS-- +libxml +dom +--FILE-- +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