mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-08-24 09:49:22 +03:00
Fix memory leak in xmlXPathEvalExpression()
* xpath.c: plug some leaks when parsing misformed XPath expressions * python/tests/xpathleak.py: expand the regression tests for those
This commit is contained in:
@ -15,6 +15,14 @@ expect="""--> Invalid expression
|
||||
--> xmlXPathEval: evaluation failed
|
||||
--> Invalid expression
|
||||
--> xmlXPathEval: evaluation failed
|
||||
--> Invalid expression
|
||||
--> xmlXPathEval: evaluation failed
|
||||
--> Invalid expression
|
||||
--> xmlXPathEval: evaluation failed
|
||||
--> Invalid expression
|
||||
--> xmlXPathEval: evaluation failed
|
||||
--> Invalid expression
|
||||
--> xmlXPathEval: evaluation failed
|
||||
"""
|
||||
err=""
|
||||
def callback(ctx, str):
|
||||
@ -27,7 +35,11 @@ libxml2.registerErrorHandler(callback, "-->")
|
||||
doc = libxml2.parseDoc("<fish/>")
|
||||
ctxt = doc.xpathNewContext()
|
||||
ctxt.setContextNode(doc)
|
||||
for expr in (":false()","bad:()","bad(:)",":bad(:)","bad:(:)","bad:bad(:)"):
|
||||
badexprs = (
|
||||
":false()", "bad:()", "bad(:)", ":bad(:)", "bad:(:)", "bad:bad(:)",
|
||||
"a:/b", "/c:/d", "//e:/f", "g://h"
|
||||
)
|
||||
for expr in badexprs:
|
||||
try:
|
||||
ctxt.xpathEval(expr)
|
||||
except libxml2.xpathError, e:
|
||||
|
2
xpath.c
2
xpath.c
@ -11333,6 +11333,7 @@ xmlXPathCompRelativeLocationPath
|
||||
SKIP_BLANKS;
|
||||
}
|
||||
xmlXPathCompStep(ctxt);
|
||||
CHECK_ERROR;
|
||||
SKIP_BLANKS;
|
||||
while (CUR == '/') {
|
||||
if ((CUR == '/') && (NXT(1) == '/')) {
|
||||
@ -11392,6 +11393,7 @@ xmlXPathCompLocationPath(xmlXPathParserContextPtr ctxt) {
|
||||
(CUR == '@') || (CUR == '*')))
|
||||
xmlXPathCompRelativeLocationPath(ctxt);
|
||||
}
|
||||
CHECK_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user