[libxml2] Fix memory leaks in XPointer error paths
- From: Nick Wellnhofer <nwellnhof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libxml2] Fix memory leaks in XPointer error paths
- Date: Sat, 27 May 2017 14:07:28 +0000 (UTC)
commit bd1571cdc56b40638d0aa431ff436e478139a0b8
Author: Nick Wellnhofer <wellnhofer aevum de>
Date: Mon May 22 00:33:12 2017 +0200
Fix memory leaks in XPointer error paths
Found with libFuzzer and ASan.
xpointer.c | 11 ++++++++++-
1 files changed, 10 insertions(+), 1 deletions(-)
---
diff --git a/xpointer.c b/xpointer.c
index e643ee9..1413868 100644
--- a/xpointer.c
+++ b/xpointer.c
@@ -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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]