diff options
| author | Ulf Jasper | 2016-03-02 19:03:27 +0100 |
|---|---|---|
| committer | Ulf Jasper | 2016-03-02 19:03:27 +0100 |
| commit | 8b01e6969f9e53a226d489cb721a7493fb3ad2de (patch) | |
| tree | 8f3dfe1bf72a4813a3bcda17644f8c784ce2639c | |
| parent | 100346aa226e4eacc56f390c099bb9aab585b5f4 (diff) | |
| download | emacs-8b01e6969f9e53a226d489cb721a7493fb3ad2de.tar.gz emacs-8b01e6969f9e53a226d489cb721a7493fb3ad2de.zip | |
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.
| -rw-r--r-- | lisp/xml.el | 9 | ||||
| -rw-r--r-- | test/automated/xml-parse-tests.el | 7 |
2 files changed, 14 insertions, 2 deletions
diff --git a/lisp/xml.el b/lisp/xml.el index 2c3b6a49f61..1802d04dfaf 100644 --- a/lisp/xml.el +++ b/lisp/xml.el | |||
| @@ -579,7 +579,14 @@ Return one of: | |||
| 579 | (error "XML: (Well-Formed) Invalid character")) | 579 | (error "XML: (Well-Formed) Invalid character")) |
| 580 | ;; However, if we're parsing incrementally, then we need to deal | 580 | ;; However, if we're parsing incrementally, then we need to deal |
| 581 | ;; with stray CDATA. | 581 | ;; with stray CDATA. |
| 582 | (xml-parse-string))))) | 582 | (let ((s (xml-parse-string))) |
| 583 | (when (string-empty-p s) | ||
| 584 | ;; We haven't consumed any input! We must throw an error in | ||
| 585 | ;; order to prevent looping forever. | ||
| 586 | (error "XML: (Not Well-Formed) Could not parse: %s" | ||
| 587 | (buffer-substring-no-properties | ||
| 588 | (point) (min (+ (point) 10) (point-max))))) | ||
| 589 | s))))) | ||
| 583 | 590 | ||
| 584 | (defun xml-parse-string () | 591 | (defun xml-parse-string () |
| 585 | "Parse character data at point, and return it as a string. | 592 | "Parse character data at point, and return it as a string. |
diff --git a/test/automated/xml-parse-tests.el b/test/automated/xml-parse-tests.el index 763febb9b69..488d2c6f920 100644 --- a/test/automated/xml-parse-tests.el +++ b/test/automated/xml-parse-tests.el | |||
| @@ -72,7 +72,12 @@ | |||
| 72 | ;; Invalid XML names | 72 | ;; Invalid XML names |
| 73 | "<0foo>abc</0foo>" | 73 | "<0foo>abc</0foo>" |
| 74 | "<‿foo>abc</‿foo>" | 74 | "<‿foo>abc</‿foo>" |
| 75 | "<f¿>abc</f¿>") | 75 | "<f¿>abc</f¿>" |
| 76 | ;; Two root tags | ||
| 77 | "<a/><b></b>" | ||
| 78 | ;; Bug#16344 | ||
| 79 | "<!----><x>< /x>" | ||
| 80 | "<a>< b/></a>") | ||
| 76 | "List of XML strings that should signal an error in the parser") | 81 | "List of XML strings that should signal an error in the parser") |
| 77 | 82 | ||
| 78 | (defvar xml-parse-tests--qnames | 83 | (defvar xml-parse-tests--qnames |