From 71a7a33e18fce3822405be2c4ce40d03064d48ea Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Fri, 3 May 2024 00:44:42 +0200 Subject: [PATCH] parser: Fix base URI of internal parameter entities Search parent inputs of internal parameter entities for base URI. Fixes a long-standing bug, which manifested in a different way after commit 955c177f. Reproduce with xmllint --noent xmlconf/eduni/errata-2e/E18.xml --- SAX2.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/SAX2.c b/SAX2.c index a347023b..b8011fec 100644 --- a/SAX2.c +++ b/SAX2.c @@ -559,9 +559,14 @@ xmlSAX2EntityDecl(void *ctx, const xmlChar *name, int type, if ((ent->URI == NULL) && (systemId != NULL)) { xmlChar *URI; const char *base = NULL; + int i; - if (ctxt->input != NULL) - base = ctxt->input->filename; + for (i = ctxt->inputNr - 1; i >= 0; i--) { + if (ctxt->inputTab[i]->filename != NULL) { + base = ctxt->inputTab[i]->filename; + break; + } + } if (xmlBuildURISafe(systemId, (const xmlChar *) base, &URI) < 0) { xmlSAX2ErrMemory(ctxt);