Sha256: a90d473d0a20043fa6019ccc7d2a56d80b93eee334603c494edf3b47c45806a1

Contents?: true

Size: 1.84 KB

Versions: 9

Compression:

Stored size: 1.84 KB

Contents

From 3ea8d08da310b645e37940eaae5cc28e251b155b Mon Sep 17 00:00:00 2001
From: Mike Dalessio <mike.dalessio@gmail.com>
Date: Sat, 17 Jul 2021 14:36:53 -0400
Subject: [PATCH] htmlParseComment: handle abruptly-closed comments

See guidance provided on abrutply-closed comments here:

https://html.spec.whatwg.org/multipage/parsing.html#parse-error-abrupt-closing-of-empty-comment
---
 HTMLparser.c              | 11 +++++++++++
 include/libxml/xmlerror.h |  1 +
 2 files changed, 12 insertions(+)

diff --git a/HTMLparser.c b/HTMLparser.c
index b56363a..f0bf294 100644
--- a/HTMLparser.c
+++ b/HTMLparser.c
@@ -3485,10 +3485,20 @@ htmlParseComment(htmlParserCtxtPtr ctxt) {
     q = CUR_CHAR(ql);
     if (q == 0)
         goto unfinished;
+    if (q == '>') {
+        htmlParseErr(ctxt, XML_ERR_COMMENT_ABRUPTLY_ENDED, "Comment abruptly ended", NULL, NULL);
+        cur = '>';
+        goto finished;
+    }
     NEXTL(ql);
     r = CUR_CHAR(rl);
     if (r == 0)
         goto unfinished;
+    if (q == '-' && r == '>') {
+        htmlParseErr(ctxt, XML_ERR_COMMENT_ABRUPTLY_ENDED, "Comment abruptly ended", NULL, NULL);
+        cur = '>';
+        goto finished;
+    }
     NEXTL(rl);
     cur = CUR_CHAR(l);
     while ((cur != 0) &&
@@ -3536,6 +3546,7 @@ htmlParseComment(htmlParserCtxtPtr ctxt) {
 	cur = next;
 	l = nl;
     }
+finished:
     buf[len] = 0;
     if (cur == '>') {
         NEXT;
diff --git a/include/libxml/xmlerror.h b/include/libxml/xmlerror.h
index c101997..7b68e40 100644
--- a/include/libxml/xmlerror.h
+++ b/include/libxml/xmlerror.h
@@ -209,6 +209,7 @@ typedef enum {
     XML_ERR_VERSION_MISMATCH, /* 109 */
     XML_ERR_NAME_TOO_LONG, /* 110 */
     XML_ERR_USER_STOP, /* 111 */
+    XML_ERR_COMMENT_ABRUPTLY_ENDED, /* 112 */
     XML_NS_ERR_XML_NAMESPACE = 200,
     XML_NS_ERR_UNDEFINED_NAMESPACE, /* 201 */
     XML_NS_ERR_QNAME, /* 202 */
-- 
2.31.0

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
nokogiri-1.13.8 patches/libxml2/0008-htmlParseComment-handle-abruptly-closed-comments.patch
nokogiri-1.13.7 patches/libxml2/0008-htmlParseComment-handle-abruptly-closed-comments.patch
nokogiri-1.13.6 patches/libxml2/0008-htmlParseComment-handle-abruptly-closed-comments.patch
nokogiri-1.13.5 patches/libxml2/0008-htmlParseComment-handle-abruptly-closed-comments.patch
nokogiri-1.13.4 patches/libxml2/0008-htmlParseComment-handle-abruptly-closed-comments.patch
nokogiri-1.13.3 patches/libxml2/0008-htmlParseComment-handle-abruptly-closed-comments.patch
nokogiri-1.13.2 patches/libxml2/0008-htmlParseComment-handle-abruptly-closed-comments.patch
nokogiri-1.13.1 patches/libxml2/0008-htmlParseComment-handle-abruptly-closed-comments.patch
nokogiri-1.13.0 patches/libxml2/0008-htmlParseComment-handle-abruptly-closed-comments.patch