From d19eba1b845d1c73f9d5cb8a84d4a08902fc84b3 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. --- ext/libxml/libxml.c | 8 +++-- .../tests/null_returned_by_resolver.phpt | 32 +++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 ext/libxml/tests/null_returned_by_resolver.phpt diff --git a/ext/libxml/libxml.c b/ext/libxml/libxml.c index 24ba80bd5de3..a6f28f0fbadb 100644 --- a/ext/libxml/libxml.c +++ b/ext/libxml/libxml.c @@ -784,10 +784,12 @@ static xmlParserInputPtr _php_libxml_external_entity_loader(const char *URL, 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 000000000000..8fdfbc6dc8b4 --- /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