mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-16 13:56:29 +00:00
Bug 1539759 - improve DTD entity handling, r=peterv
Differential Revision: https://phabricator.services.mozilla.com/D27904 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
c7089180a6
commit
54d985d143
@ -1765,6 +1765,8 @@ XML_SetAttlistDeclHandler(XML_Parser parser,
|
||||
if (parser != NULL)
|
||||
attlistDeclHandler = attdecl;
|
||||
}
|
||||
#endif
|
||||
/* END MOZILLA CHANGE */
|
||||
|
||||
void XMLCALL
|
||||
XML_SetEntityDeclHandler(XML_Parser parser,
|
||||
@ -1773,8 +1775,6 @@ XML_SetEntityDeclHandler(XML_Parser parser,
|
||||
if (parser != NULL)
|
||||
entityDeclHandler = handler;
|
||||
}
|
||||
#endif
|
||||
/* END MOZILLA CHANGE */
|
||||
|
||||
void XMLCALL
|
||||
XML_SetXmlDeclHandler(XML_Parser parser,
|
||||
|
@ -154,6 +154,18 @@ static int Driver_HandleExternalEntityRef(void* aExternalEntityRefHandler,
|
||||
aPublicId);
|
||||
}
|
||||
|
||||
static void Driver_HandleEntityDecl(
|
||||
void* aUserData, const XML_Char* aEntityName, int aIsParameterEntity,
|
||||
const XML_Char* aValue, int aValueLength, const XML_Char* aBase,
|
||||
const XML_Char* aSystemId, const XML_Char* aPublicId,
|
||||
const XML_Char* aNotationName) {
|
||||
NS_ASSERTION(aUserData, "expat driver should exist");
|
||||
if (aUserData) {
|
||||
static_cast<nsExpatDriver*>(aUserData)->HandleEntityDecl(
|
||||
aEntityName, aValue, aValueLength);
|
||||
}
|
||||
}
|
||||
|
||||
/***************************** END CALL BACKS ********************************/
|
||||
|
||||
/***************************** CATALOG UTILS *********************************/
|
||||
@ -474,6 +486,19 @@ nsresult nsExpatDriver::HandleEndDoctypeDecl() {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void nsExpatDriver::HandleEntityDecl(const char16_t* aEntityName,
|
||||
const char16_t* aEntityValue,
|
||||
const uint32_t aLength) {
|
||||
MOZ_ASSERT(
|
||||
mInInternalSubset || mInExternalDTD,
|
||||
"Should only see entity declarations in the internal subset or in DTDs");
|
||||
auto charLength = aLength / sizeof(char16_t);
|
||||
nsDependentSubstring entityVal(aEntityValue, charLength);
|
||||
if (entityVal.FindChar('<') != -1) {
|
||||
MaybeStopParser(NS_ERROR_UNEXPECTED);
|
||||
}
|
||||
}
|
||||
|
||||
static nsresult ExternalDTDStreamReaderFunc(nsIUnicharInputStream* aIn,
|
||||
void* aClosure,
|
||||
const char16_t* aFromSegment,
|
||||
@ -1057,6 +1082,9 @@ nsExpatDriver::WillBuildModel(const CParserContext& aParserContext,
|
||||
|
||||
XML_SetParamEntityParsing(mExpatParser,
|
||||
XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE);
|
||||
if (doc->NodePrincipal()->IsSystemPrincipal()) {
|
||||
XML_SetEntityDeclHandler(mExpatParser, Driver_HandleEntityDecl);
|
||||
}
|
||||
XML_SetDoctypeDeclHandler(mExpatParser, Driver_HandleStartDoctypeDecl,
|
||||
Driver_HandleEndDoctypeDecl);
|
||||
|
||||
|
@ -49,6 +49,8 @@ class nsExpatDriver : public nsIDTD, public nsITokenizer {
|
||||
const char16_t* aPubid,
|
||||
bool aHasInternalSubset);
|
||||
nsresult HandleEndDoctypeDecl();
|
||||
void HandleEntityDecl(const char16_t* aEntityName,
|
||||
const char16_t* aEntityValue, const uint32_t aLength);
|
||||
|
||||
private:
|
||||
// Load up an external stream to get external entity information
|
||||
|
Loading…
x
Reference in New Issue
Block a user