diff options
| author | Yue Tao <Yue.Tao@windriver.com> | 2022-07-25 15:54:57 +0800 |
|---|---|---|
| committer | Armin Kuster <akuster808@gmail.com> | 2022-07-26 07:08:35 -0700 |
| commit | cb4e7fb4b08b7ebbdc21485e9a21845931132759 (patch) | |
| tree | 2648092b74e9a4ef2ff964973824f68fdea4d468 /meta-python/recipes-devtools/python/python3-lxml | |
| parent | 2763eaf35f9b2b1ed410809cadfbdce27c1fa5e5 (diff) | |
| download | meta-openembedded-cb4e7fb4b08b7ebbdc21485e9a21845931132759.tar.gz | |
python3-lxml: Security fix CVE-2022-2309
CVE-2022-0934:
lxml: NULL Pointer Dereference in lxml
Reference:
https://nvd.nist.gov/vuln/detail/CVE-2022-2309
Patch from:
https://github.com/lxml/lxml/commit/86368e9cf70a0ad23cccd5ee32de847149af0c6f
Signed-off-by: Yue Tao <Yue.Tao@windriver.com>
Diffstat (limited to 'meta-python/recipes-devtools/python/python3-lxml')
| -rw-r--r-- | meta-python/recipes-devtools/python/python3-lxml/CVE-2022-2309.patch | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/meta-python/recipes-devtools/python/python3-lxml/CVE-2022-2309.patch b/meta-python/recipes-devtools/python/python3-lxml/CVE-2022-2309.patch new file mode 100644 index 0000000000..5ec55dfd2a --- /dev/null +++ b/meta-python/recipes-devtools/python/python3-lxml/CVE-2022-2309.patch | |||
| @@ -0,0 +1,99 @@ | |||
| 1 | From 86368e9cf70a0ad23cccd5ee32de847149af0c6f Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Stefan Behnel <stefan_ml@behnel.de> | ||
| 3 | Date: Fri, 1 Jul 2022 21:06:10 +0200 | ||
| 4 | Subject: [PATCH] Fix a crash when incorrect parser input occurs together with | ||
| 5 | usages of iterwalk() on trees generated by the same parser. | ||
| 6 | |||
| 7 | CVE: CVE-2022-2309 | ||
| 8 | |||
| 9 | Upstream-Status: Backport | ||
| 10 | [https://github.com/lxml/lxml/commit/86368e9cf70a0ad23cccd5ee32de847149af0c6f] | ||
| 11 | |||
| 12 | Signed-off-by: Yue Tao <yue.tao@windriver.com> | ||
| 13 | |||
| 14 | --- | ||
| 15 | src/lxml/apihelpers.pxi | 7 ++++--- | ||
| 16 | src/lxml/iterparse.pxi | 11 ++++++----- | ||
| 17 | src/lxml/tests/test_etree.py | 20 ++++++++++++++++++++ | ||
| 18 | 3 files changed, 30 insertions(+), 8 deletions(-) | ||
| 19 | |||
| 20 | diff --git a/src/lxml/apihelpers.pxi b/src/lxml/apihelpers.pxi | ||
| 21 | index c1662762..9fae9fb1 100644 | ||
| 22 | --- a/src/lxml/apihelpers.pxi | ||
| 23 | +++ b/src/lxml/apihelpers.pxi | ||
| 24 | @@ -246,9 +246,10 @@ cdef dict _build_nsmap(xmlNode* c_node): | ||
| 25 | while c_node is not NULL and c_node.type == tree.XML_ELEMENT_NODE: | ||
| 26 | c_ns = c_node.nsDef | ||
| 27 | while c_ns is not NULL: | ||
| 28 | - prefix = funicodeOrNone(c_ns.prefix) | ||
| 29 | - if prefix not in nsmap: | ||
| 30 | - nsmap[prefix] = funicodeOrNone(c_ns.href) | ||
| 31 | + if c_ns.prefix or c_ns.href: | ||
| 32 | + prefix = funicodeOrNone(c_ns.prefix) | ||
| 33 | + if prefix not in nsmap: | ||
| 34 | + nsmap[prefix] = funicodeOrNone(c_ns.href) | ||
| 35 | c_ns = c_ns.next | ||
| 36 | c_node = c_node.parent | ||
| 37 | return nsmap | ||
| 38 | diff --git a/src/lxml/iterparse.pxi b/src/lxml/iterparse.pxi | ||
| 39 | index 138c23a6..a7299da6 100644 | ||
| 40 | --- a/src/lxml/iterparse.pxi | ||
| 41 | +++ b/src/lxml/iterparse.pxi | ||
| 42 | @@ -420,7 +420,7 @@ cdef int _countNsDefs(xmlNode* c_node): | ||
| 43 | count = 0 | ||
| 44 | c_ns = c_node.nsDef | ||
| 45 | while c_ns is not NULL: | ||
| 46 | - count += 1 | ||
| 47 | + count += (c_ns.href is not NULL) | ||
| 48 | c_ns = c_ns.next | ||
| 49 | return count | ||
| 50 | |||
| 51 | @@ -431,9 +431,10 @@ cdef int _appendStartNsEvents(xmlNode* c_node, list event_list) except -1: | ||
| 52 | count = 0 | ||
| 53 | c_ns = c_node.nsDef | ||
| 54 | while c_ns is not NULL: | ||
| 55 | - ns_tuple = (funicode(c_ns.prefix) if c_ns.prefix is not NULL else '', | ||
| 56 | - funicode(c_ns.href)) | ||
| 57 | - event_list.append( (u"start-ns", ns_tuple) ) | ||
| 58 | - count += 1 | ||
| 59 | + if c_ns.href: | ||
| 60 | + ns_tuple = (funicodeOrEmpty(c_ns.prefix), | ||
| 61 | + funicode(c_ns.href)) | ||
| 62 | + event_list.append( (u"start-ns", ns_tuple) ) | ||
| 63 | + count += 1 | ||
| 64 | c_ns = c_ns.next | ||
| 65 | return count | ||
| 66 | diff --git a/src/lxml/tests/test_etree.py b/src/lxml/tests/test_etree.py | ||
| 67 | index e5f08469..285313f6 100644 | ||
| 68 | --- a/src/lxml/tests/test_etree.py | ||
| 69 | +++ b/src/lxml/tests/test_etree.py | ||
| 70 | @@ -1460,6 +1460,26 @@ class ETreeOnlyTestCase(HelperTestCase): | ||
| 71 | [1,2,1,4], | ||
| 72 | counts) | ||
| 73 | |||
| 74 | + def test_walk_after_parse_failure(self): | ||
| 75 | + # This used to be an issue because libxml2 can leak empty namespaces | ||
| 76 | + # between failed parser runs. iterwalk() failed to handle such a tree. | ||
| 77 | + try: | ||
| 78 | + etree.XML('''<anot xmlns="1">''') | ||
| 79 | + except etree.XMLSyntaxError: | ||
| 80 | + pass | ||
| 81 | + else: | ||
| 82 | + assert False, "invalid input did not fail to parse" | ||
| 83 | + | ||
| 84 | + et = etree.XML('''<root> </root>''') | ||
| 85 | + try: | ||
| 86 | + ns = next(etree.iterwalk(et, events=('start-ns',))) | ||
| 87 | + except StopIteration: | ||
| 88 | + # This would be the expected result, because there was no namespace | ||
| 89 | + pass | ||
| 90 | + else: | ||
| 91 | + # This is a bug in libxml2 | ||
| 92 | + assert not ns, repr(ns) | ||
| 93 | + | ||
| 94 | def test_itertext_comment_pi(self): | ||
| 95 | # https://bugs.launchpad.net/lxml/+bug/1844674 | ||
| 96 | XML = self.etree.XML | ||
| 97 | -- | ||
| 98 | 2.17.1 | ||
| 99 | |||
