1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-10-26 12:25:09 +03:00

Fix memory leaks in XPointer error paths

Found with libFuzzer and ASan.
This commit is contained in:
Nick Wellnhofer 2017-05-22 00:33:12 +02:00
parent 9d08b34716
commit bd1571cdc5

View File

@ -99,6 +99,10 @@ xmlXPtrErr(xmlXPathParserContextPtr ctxt, int error,
msg, extra);
return;
}
/* cleanup current last error */
xmlResetError(&ctxt->context->lastError);
ctxt->context->lastError.domain = XML_FROM_XPOINTER;
ctxt->context->lastError.code = error;
ctxt->context->lastError.level = XML_ERR_ERROR;
@ -949,8 +953,10 @@ xmlXPtrEvalXPtrPart(xmlXPathParserContextPtr ctxt, xmlChar *name) {
if (name == NULL)
XP_ERROR(XPATH_EXPR_ERROR);
if (CUR != '(')
if (CUR != '(') {
xmlFree(name);
XP_ERROR(XPATH_EXPR_ERROR);
}
NEXT;
level = 1;
@ -959,6 +965,7 @@ xmlXPtrEvalXPtrPart(xmlXPathParserContextPtr ctxt, xmlChar *name) {
buffer = (xmlChar *) xmlMallocAtomic(len * sizeof (xmlChar));
if (buffer == NULL) {
xmlXPtrErrMemory("allocating buffer");
xmlFree(name);
return;
}
@ -983,6 +990,7 @@ xmlXPtrEvalXPtrPart(xmlXPathParserContextPtr ctxt, xmlChar *name) {
*cur = 0;
if ((level != 0) && (CUR == 0)) {
xmlFree(name);
xmlFree(buffer);
XP_ERROR(XPTR_SYNTAX_ERROR);
}
@ -1015,6 +1023,7 @@ xmlXPtrEvalXPtrPart(xmlXPathParserContextPtr ctxt, xmlChar *name) {
if (name2 == NULL) {
CUR_PTR = left;
xmlFree(buffer);
xmlFree(name);
XP_ERROR(XPATH_EXPR_ERROR);
}
xmlXPtrEvalChildSeq(ctxt, name2);