From d3fe0d3a8786f471713d4b04d7078791050b6f47 Mon Sep 17 00:00:00 2001 From: "heikki%netscape.com" Date: Fri, 25 Jan 2002 23:19:23 +0000 Subject: [PATCH] Bug 35984, make an undefined entity always a fatal error; report errors while parsing external entities (regression) and a minor optimization in loading external entities. r=harishd, sr=jst. git-svn-id: svn://10.0.0.236/trunk@112898 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/expat/xmlparse/xmlparse.c | 11 +++-------- mozilla/htmlparser/src/nsExpatDriver.cpp | 6 ++++-- mozilla/parser/expat/lib/xmlparse.c | 11 +++-------- mozilla/parser/htmlparser/src/nsExpatDriver.cpp | 6 ++++-- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/mozilla/expat/xmlparse/xmlparse.c b/mozilla/expat/xmlparse/xmlparse.c index d3033c3a8cc..b9c67c172f8 100644 --- a/mozilla/expat/xmlparse/xmlparse.c +++ b/mozilla/expat/xmlparse/xmlparse.c @@ -1278,13 +1278,8 @@ doContent(XML_Parser parser, return XML_ERROR_NO_MEMORY; entity = (ENTITY *)lookup(&dtd.generalEntities, name, 0); poolDiscard(&dtd.pool); - if (!entity) { - if (dtd.complete || dtd.standalone) - return XML_ERROR_UNDEFINED_ENTITY; - if (defaultHandler) - reportDefault(parser, enc, s, next); - break; - } + if (!entity) + return XML_ERROR_UNDEFINED_ENTITY; if (entity->open) return XML_ERROR_RECURSIVE_ENTITY_REF; if (entity->notation) @@ -2959,8 +2954,8 @@ appendAttributeValue(XML_Parser parser, const ENCODING *enc, int isCdata, if (dtd.complete) { if (enc == encoding) eventPtr = ptr; - return XML_ERROR_UNDEFINED_ENTITY; } + return XML_ERROR_UNDEFINED_ENTITY; } else if (entity->open) { if (enc == encoding) diff --git a/mozilla/htmlparser/src/nsExpatDriver.cpp b/mozilla/htmlparser/src/nsExpatDriver.cpp index b0c63c3d232..daa0c818867 100644 --- a/mozilla/htmlparser/src/nsExpatDriver.cpp +++ b/mozilla/htmlparser/src/nsExpatDriver.cpp @@ -200,7 +200,7 @@ Driver_HandleExternalEntityRef(XML_Parser parser, XML_SetBase(entParser, (const XML_Char*) absURL.get()); - while (NS_SUCCEEDED(uniIn->Read(uniBuf, 0, 1024, &readCount))) { + while (NS_SUCCEEDED(uniIn->Read(uniBuf, 0, 1024, &readCount)) && result) { if (readCount) { // Pass the buffer to expat for parsing result = XML_Parse(entParser, (char *)uniBuf, readCount * sizeof(PRUnichar), 0); @@ -459,7 +459,9 @@ IsLoadableDTD(const XML_Char* aFPIStr, nsCOMPtr* aDTD) if (!isLoadable) { // try to see if we can map the public ID to a known local DTD nsXPIDLCString fileName; - RemapDTD(aFPIStr, fileName); + if (aFPIStr) { + RemapDTD(aFPIStr, fileName); + } if (fileName.IsEmpty()) { // try to see if the user has installed the DTD file -- we extract the // filename.ext of the DTD here. Hence, for any DTD for which we have diff --git a/mozilla/parser/expat/lib/xmlparse.c b/mozilla/parser/expat/lib/xmlparse.c index d3033c3a8cc..b9c67c172f8 100644 --- a/mozilla/parser/expat/lib/xmlparse.c +++ b/mozilla/parser/expat/lib/xmlparse.c @@ -1278,13 +1278,8 @@ doContent(XML_Parser parser, return XML_ERROR_NO_MEMORY; entity = (ENTITY *)lookup(&dtd.generalEntities, name, 0); poolDiscard(&dtd.pool); - if (!entity) { - if (dtd.complete || dtd.standalone) - return XML_ERROR_UNDEFINED_ENTITY; - if (defaultHandler) - reportDefault(parser, enc, s, next); - break; - } + if (!entity) + return XML_ERROR_UNDEFINED_ENTITY; if (entity->open) return XML_ERROR_RECURSIVE_ENTITY_REF; if (entity->notation) @@ -2959,8 +2954,8 @@ appendAttributeValue(XML_Parser parser, const ENCODING *enc, int isCdata, if (dtd.complete) { if (enc == encoding) eventPtr = ptr; - return XML_ERROR_UNDEFINED_ENTITY; } + return XML_ERROR_UNDEFINED_ENTITY; } else if (entity->open) { if (enc == encoding) diff --git a/mozilla/parser/htmlparser/src/nsExpatDriver.cpp b/mozilla/parser/htmlparser/src/nsExpatDriver.cpp index b0c63c3d232..daa0c818867 100644 --- a/mozilla/parser/htmlparser/src/nsExpatDriver.cpp +++ b/mozilla/parser/htmlparser/src/nsExpatDriver.cpp @@ -200,7 +200,7 @@ Driver_HandleExternalEntityRef(XML_Parser parser, XML_SetBase(entParser, (const XML_Char*) absURL.get()); - while (NS_SUCCEEDED(uniIn->Read(uniBuf, 0, 1024, &readCount))) { + while (NS_SUCCEEDED(uniIn->Read(uniBuf, 0, 1024, &readCount)) && result) { if (readCount) { // Pass the buffer to expat for parsing result = XML_Parse(entParser, (char *)uniBuf, readCount * sizeof(PRUnichar), 0); @@ -459,7 +459,9 @@ IsLoadableDTD(const XML_Char* aFPIStr, nsCOMPtr* aDTD) if (!isLoadable) { // try to see if we can map the public ID to a known local DTD nsXPIDLCString fileName; - RemapDTD(aFPIStr, fileName); + if (aFPIStr) { + RemapDTD(aFPIStr, fileName); + } if (fileName.IsEmpty()) { // try to see if the user has installed the DTD file -- we extract the // filename.ext of the DTD here. Hence, for any DTD for which we have