]> code.delx.au - gnu-emacs/commitdiff
Prevent infinite loop on not-well-formed xml. (Bug#16344)
authorUlf Jasper <ulf.jasper@web.de>
Wed, 2 Mar 2016 18:03:27 +0000 (19:03 +0100)
committerUlf Jasper <ulf.jasper@web.de>
Wed, 2 Mar 2016 18:03:27 +0000 (19:03 +0100)
* lisp/xml.el (xml-parse-tag-1): Prevent inifinite loop. (Bug#16344)
* test/automated/xml-parse-tests.el (xml-parse-tests--bad-data): Add
  test cases for Bug#16344.

lisp/xml.el
test/automated/xml-parse-tests.el

index 2c3b6a49f61c211e9a493b7379c46404457884c1..1802d04dfaf8c53ea43a833d728df1a8766c807a 100644 (file)
@@ -579,7 +579,14 @@ Return one of:
        (error "XML: (Well-Formed) Invalid character"))
       ;; However, if we're parsing incrementally, then we need to deal
       ;; with stray CDATA.
-      (xml-parse-string)))))
+      (let ((s (xml-parse-string)))
+        (when (string-empty-p s)
+          ;; We haven't consumed any input! We must throw an error in
+          ;; order to prevent looping forever.
+          (error "XML: (Not Well-Formed) Could not parse: %s"
+                 (buffer-substring-no-properties
+                  (point) (min (+ (point) 10) (point-max)))))
+        s)))))
 
 (defun xml-parse-string ()
   "Parse character data at point, and return it as a string.
index 763febb9b69e2fdf6ab6e14bc47c066a3140919d..488d2c6f9209fa8c38c95a4a2ec5adec46e35fb3 100644 (file)
     ;; Invalid XML names
     "<0foo>abc</0foo>"
     "<‿foo>abc</‿foo>"
-    "<f¿>abc</f¿>")
+    "<f¿>abc</f¿>"
+    ;; Two root tags
+    "<a/><b></b>"
+    ;; Bug#16344
+    "<!----><x>< /x>"
+    "<a>< b/></a>")
   "List of XML strings that should signal an error in the parser")
 
 (defvar xml-parse-tests--qnames