summaryrefslogtreecommitdiff
path: root/parser.c
diff options
context:
space:
mode:
Diffstat (limited to 'parser.c')
-rw-r--r--parser.c36
1 files changed, 27 insertions, 9 deletions
diff --git a/parser.c b/parser.c
index 6cc8277..9d05111 100644
--- a/parser.c
+++ b/parser.c
@@ -3817,10 +3817,24 @@ xmlParseCommentComplex(xmlParserCtxtPtr ctxt, xmlChar *buf, int len, int size) {
q = CUR_CHAR(ql);
if (q == 0)
goto not_terminated;
+ if (!IS_CHAR(q)) {
+ xmlFatalErrMsgInt(ctxt, XML_ERR_INVALID_CHAR,
+ "xmlParseComment: invalid xmlChar value %d\n",
+ q);
+ xmlFree (buf);
+ return;
+ }
NEXTL(ql);
r = CUR_CHAR(rl);
if (r == 0)
goto not_terminated;
+ if (!IS_CHAR(r)) {
+ xmlFatalErrMsgInt(ctxt, XML_ERR_INVALID_CHAR,
+ "xmlParseComment: invalid xmlChar value %d\n",
+ q);
+ xmlFree (buf);
+ return;
+ }
NEXTL(rl);
cur = CUR_CHAR(l);
if (cur == 0)
@@ -3862,10 +3876,13 @@ xmlParseCommentComplex(xmlParserCtxtPtr ctxt, xmlChar *buf, int len, int size) {
}
}
buf[len] = 0;
- if (!IS_CHAR(cur)) {
+ if (cur == 0) {
xmlFatalErrMsgStr(ctxt, XML_ERR_COMMENT_NOT_FINISHED,
"Comment not terminated \n<!--%.50s\n", buf);
- xmlFree(buf);
+ } else if (!IS_CHAR(cur)) {
+ xmlFatalErrMsgInt(ctxt, XML_ERR_INVALID_CHAR,
+ "xmlParseComment: invalid xmlChar value %d\n",
+ cur);
} else {
if (input != ctxt->input) {
xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
@@ -3875,14 +3892,16 @@ xmlParseCommentComplex(xmlParserCtxtPtr ctxt, xmlChar *buf, int len, int size) {
if ((ctxt->sax != NULL) && (ctxt->sax->comment != NULL) &&
(!ctxt->disableSAX))
ctxt->sax->comment(ctxt->userData, buf);
- xmlFree(buf);
}
+ xmlFree(buf);
return;
not_terminated:
xmlFatalErrMsgStr(ctxt, XML_ERR_COMMENT_NOT_FINISHED,
"Comment not terminated\n", NULL);
xmlFree(buf);
+ return;
}
+
/**
* xmlParseComment:
* @ctxt: an XML parser context
@@ -12468,9 +12487,7 @@ xmlSAXUserParseFile(xmlSAXHandlerPtr sax, void *user_data,
ctxt = xmlCreateFileParserCtxt(filename);
if (ctxt == NULL) return -1;
-#ifdef LIBXML_SAX1_ENABLED
if (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler)
-#endif /* LIBXML_SAX1_ENABLED */
xmlFree(ctxt->sax);
ctxt->sax = sax;
xmlDetectSAX2(ctxt);
@@ -12674,14 +12691,14 @@ int xmlSAXUserParseMemory(xmlSAXHandlerPtr sax, void *user_data,
const char *buffer, int size) {
int ret = 0;
xmlParserCtxtPtr ctxt;
- xmlSAXHandlerPtr oldsax = NULL;
- if (sax == NULL) return -1;
ctxt = xmlCreateMemoryParserCtxt(buffer, size);
if (ctxt == NULL) return -1;
- oldsax = ctxt->sax;
+ if (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler)
+ xmlFree(ctxt->sax);
ctxt->sax = sax;
xmlDetectSAX2(ctxt);
+
if (user_data != NULL)
ctxt->userData = user_data;
@@ -12695,7 +12712,8 @@ int xmlSAXUserParseMemory(xmlSAXHandlerPtr sax, void *user_data,
else
ret = -1;
}
- ctxt->sax = oldsax;
+ if (sax != NULL)
+ ctxt->sax = NULL;
if (ctxt->myDoc != NULL) {
xmlFreeDoc(ctxt->myDoc);
ctxt->myDoc = NULL;