1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-02-08 20:58:58 +00:00

Prevent infinite loop on not-well-formed xml. (Bug#16344)

* 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.
This commit is contained in:
Ulf Jasper 2016-03-02 19:03:27 +01:00
parent 100346aa22
commit 8b01e6969f
2 changed files with 14 additions and 2 deletions

View 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.

View File

@ -72,7 +72,12 @@
;; 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