$NetBSD: patch-HTMLparser.c,v 1.1 2015/07/03 18:55:46 he Exp $
Suggested patch for arbitrary-memory-access vulnerability, from
https://bugzilla.gnome.org/show_bug.cgi?id=746048
--- HTMLparser.c.orig 2014-10-06 10:48:11.000000000 +0000
+++ HTMLparser.c
@@ -3245,13 +3245,20 @@ htmlParseComment(htmlParserCtxtPtr ctxt)
ctxt->instate = state;
return;
}
+ if ((ctxt->input->end - ctxt->input->cur) < 3) {
+ ctxt->instate = XML_PARSER_EOF;
+ htmlParseErr(ctxt, XML_ERR_COMMENT_NOT_FINISHED,
+ "Comment not terminated\n", NULL, NULL);
+ xmlFree(buf);
+ return;
+ }
q = CUR_CHAR(ql);
NEXTL(ql);
r = CUR_CHAR(rl);
NEXTL(rl);
cur = CUR_CHAR(l);
len = 0;
- while (IS_CHAR(cur) &&
+ while (((ctxt->input->end - ctxt->input->cur) > 0) && IS_CHAR(cur) &&
((cur != '>') ||
(r != '-') || (q != '-'))) {
if (len + 5 >= size) {
@@ -3281,7 +3288,7 @@ htmlParseComment(htmlParserCtxtPtr ctxt)
}
}
buf[len] = 0;
- if (!IS_CHAR(cur)) {
+ if (!(ctxt->input->end - ctxt->input->cur) || !IS_CHAR(cur)) {
htmlParseErr(ctxt, XML_ERR_COMMENT_NOT_FINISHED,
"Comment not terminated \n