mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-01-27 14:03:36 +03:00
Fix memory leak in xmlParseEntityDecl error path
When parsing the entity value, it can happen that an external entity with an unsupported encoding is loaded and the parser is stopped. This would lead to a memory leak. A custom SAX callback could also stop the parser. Found with libFuzzer and ASan.
This commit is contained in:
parent
94f6ce838c
commit
bedbef8065
16
parser.c
16
parser.c
@ -5713,7 +5713,7 @@ xmlParseEntityDecl(xmlParserCtxtPtr ctxt) {
|
||||
}
|
||||
}
|
||||
if (ctxt->instate == XML_PARSER_EOF)
|
||||
return;
|
||||
goto done;
|
||||
SKIP_BLANKS;
|
||||
if (RAW != '>') {
|
||||
xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_NOT_FINISHED,
|
||||
@ -5744,17 +5744,17 @@ xmlParseEntityDecl(xmlParserCtxtPtr ctxt) {
|
||||
cur = xmlSAX2GetEntity(ctxt, name);
|
||||
}
|
||||
}
|
||||
if (cur != NULL) {
|
||||
if (cur->orig != NULL)
|
||||
xmlFree(orig);
|
||||
else
|
||||
cur->orig = orig;
|
||||
} else
|
||||
xmlFree(orig);
|
||||
if ((cur != NULL) && (cur->orig == NULL)) {
|
||||
cur->orig = orig;
|
||||
orig = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
if (value != NULL) xmlFree(value);
|
||||
if (URI != NULL) xmlFree(URI);
|
||||
if (literal != NULL) xmlFree(literal);
|
||||
if (orig != NULL) xmlFree(orig);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user