From 4fefe8247331936729153ea86aaec1fd2453526a Mon Sep 17 00:00:00 2001 From: "@ran-zhao-yu" Date: Thu, 5 Sep 2024 17:25:53 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E8=93=9D=E9=BB=84=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: @ran-zhao-yu --- Fix-CVE-2023-45322-pre-patch.patch | 0 Fix-CVE-2023-45322.patch | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 Fix-CVE-2023-45322-pre-patch.patch create mode 100644 Fix-CVE-2023-45322.patch diff --git a/Fix-CVE-2023-45322-pre-patch.patch b/Fix-CVE-2023-45322-pre-patch.patch new file mode 100644 index 0000000..e69de29 diff --git a/Fix-CVE-2023-45322.patch b/Fix-CVE-2023-45322.patch new file mode 100644 index 0000000..e69de29 -- Gitee From ae5f4a47e37d6953d4e5afc2fcc4b5ce9fd03c7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=89=E5=8F=AC=E5=AE=87?= Date: Thu, 5 Sep 2024 09:29:16 +0000 Subject: [PATCH 2/6] update Fix-CVE-2023-45322-pre-patch.patch. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 冉召宇 --- Fix-CVE-2023-45322-pre-patch.patch | 74 ++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/Fix-CVE-2023-45322-pre-patch.patch b/Fix-CVE-2023-45322-pre-patch.patch index e69de29..44cb26b 100644 --- a/Fix-CVE-2023-45322-pre-patch.patch +++ b/Fix-CVE-2023-45322-pre-patch.patch @@ -0,0 +1,74 @@ +From d39f78069dff496ec865c73aa44d7110e429bce9 Mon Sep 17 00:00:00 2001 +From: Nick Wellnhofer +Date: Wed, 23 Aug 2023 20:24:24 +0200 +Subject: [PATCH] tree: Fix copying of DTDs + +- Don't create multiple DTD nodes. +- Fix UAF if malloc fails. +- Skip DTD nodes if tree module is disabled. + +Fixes #583. +--- + tree.c | 31 ++++++++++++++++--------------- + 1 file changed, 16 insertions(+), 15 deletions(-) + +diff --git a/tree.c b/tree.c +index 6c8a875b9..02c1b5791 100644 +--- a/tree.c ++++ b/tree.c +@@ -4370,29 +4370,28 @@ xmlNodePtr + xmlStaticCopyNodeList(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent) { + xmlNodePtr ret = NULL; + xmlNodePtr p = NULL,q; ++ xmlDtdPtr newSubset = NULL; + + while (node != NULL) { +-#ifdef LIBXML_TREE_ENABLED + if (node->type == XML_DTD_NODE ) { +- if (doc == NULL) { ++#ifdef LIBXML_TREE_ENABLED ++ if ((doc == NULL) || (doc->intSubset != NULL)) { + node = node->next; + continue; + } +- if (doc->intSubset == NULL) { +- q = (xmlNodePtr) xmlCopyDtd( (xmlDtdPtr) node ); +- if (q == NULL) goto error; +- q->doc = doc; +- q->parent = parent; +- doc->intSubset = (xmlDtdPtr) q; +- xmlAddChild(parent, q); +- } else { +- q = (xmlNodePtr) doc->intSubset; +- xmlAddChild(parent, q); +- } +- } else ++ q = (xmlNodePtr) xmlCopyDtd( (xmlDtdPtr) node ); ++ if (q == NULL) goto error; ++ q->doc = doc; ++ q->parent = parent; ++ newSubset = (xmlDtdPtr) q; ++#else ++ node = node->next; ++ continue; + #endif /* LIBXML_TREE_ENABLED */ ++ } else { + q = xmlStaticCopyNode(node, doc, parent, 1); +- if (q == NULL) goto error; ++ if (q == NULL) goto error; ++ } + if (ret == NULL) { + q->prev = NULL; + ret = p = q; +@@ -4404,6 +4403,8 @@ xmlStaticCopyNodeList(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent) { + } + node = node->next; + } ++ if (newSubset != NULL) ++ doc->intSubset = newSubset; + return(ret); + error: + xmlFreeNodeList(ret); +-- +GitLab + -- Gitee From a92dc3badb41506a4cfc522d845a058930c3edf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=89=E5=8F=AC=E5=AE=87?= Date: Thu, 5 Sep 2024 09:29:33 +0000 Subject: [PATCH 3/6] update Fix-CVE-2023-45322-pre-patch.patch. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 冉召宇 --- Fix-CVE-2023-45322-pre-patch.patch | 81 ++++++++++-------------------- 1 file changed, 26 insertions(+), 55 deletions(-) diff --git a/Fix-CVE-2023-45322-pre-patch.patch b/Fix-CVE-2023-45322-pre-patch.patch index 44cb26b..e80a8ea 100644 --- a/Fix-CVE-2023-45322-pre-patch.patch +++ b/Fix-CVE-2023-45322-pre-patch.patch @@ -1,74 +1,45 @@ -From d39f78069dff496ec865c73aa44d7110e429bce9 Mon Sep 17 00:00:00 2001 +From a22bd982bf10291deea8ba0c61bf75b898c604ce Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer -Date: Wed, 23 Aug 2023 20:24:24 +0200 -Subject: [PATCH] tree: Fix copying of DTDs +Date: Wed, 2 Nov 2022 15:44:42 +0100 +Subject: [PATCH] malloc-fail: Fix memory leak in xmlStaticCopyNodeList -- Don't create multiple DTD nodes. -- Fix UAF if malloc fails. -- Skip DTD nodes if tree module is disabled. - -Fixes #583. +Found with libFuzzer, see #344. --- - tree.c | 31 ++++++++++++++++--------------- - 1 file changed, 16 insertions(+), 15 deletions(-) + tree.c | 7 +++++-- + 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tree.c b/tree.c -index 6c8a875b9..02c1b5791 100644 +index 507869efe..647288ce3 100644 --- a/tree.c +++ b/tree.c -@@ -4370,29 +4370,28 @@ xmlNodePtr - xmlStaticCopyNodeList(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent) { - xmlNodePtr ret = NULL; - xmlNodePtr p = NULL,q; -+ xmlDtdPtr newSubset = NULL; - - while (node != NULL) { --#ifdef LIBXML_TREE_ENABLED - if (node->type == XML_DTD_NODE ) { -- if (doc == NULL) { -+#ifdef LIBXML_TREE_ENABLED -+ if ((doc == NULL) || (doc->intSubset != NULL)) { - node = node->next; - continue; +@@ -4380,7 +4380,7 @@ xmlStaticCopyNodeList(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent) { } -- if (doc->intSubset == NULL) { -- q = (xmlNodePtr) xmlCopyDtd( (xmlDtdPtr) node ); -- if (q == NULL) goto error; -- q->doc = doc; -- q->parent = parent; -- doc->intSubset = (xmlDtdPtr) q; -- xmlAddChild(parent, q); -- } else { -- q = (xmlNodePtr) doc->intSubset; -- xmlAddChild(parent, q); -- } -- } else -+ q = (xmlNodePtr) xmlCopyDtd( (xmlDtdPtr) node ); -+ if (q == NULL) goto error; -+ q->doc = doc; -+ q->parent = parent; -+ newSubset = (xmlDtdPtr) q; -+#else -+ node = node->next; -+ continue; + if (doc->intSubset == NULL) { + q = (xmlNodePtr) xmlCopyDtd( (xmlDtdPtr) node ); +- if (q == NULL) return(NULL); ++ if (q == NULL) goto error; + q->doc = doc; + q->parent = parent; + doc->intSubset = (xmlDtdPtr) q; +@@ -4392,7 +4392,7 @@ xmlStaticCopyNodeList(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent) { + } else #endif /* LIBXML_TREE_ENABLED */ -+ } else { q = xmlStaticCopyNode(node, doc, parent, 1); -- if (q == NULL) goto error; -+ if (q == NULL) goto error; -+ } +- if (q == NULL) return(NULL); ++ if (q == NULL) goto error; if (ret == NULL) { q->prev = NULL; ret = p = q; -@@ -4404,6 +4403,8 @@ xmlStaticCopyNodeList(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent) { - } +@@ -4405,6 +4405,9 @@ xmlStaticCopyNodeList(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent) { node = node->next; } -+ if (newSubset != NULL) -+ doc->intSubset = newSubset; return(ret); - error: - xmlFreeNodeList(ret); ++error: ++ xmlFreeNodeList(ret); ++ return(NULL); + } + + /** -- GitLab -- Gitee From 85acfeb6f4f3508d0e814d22b6df0fb62b096faa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=89=E5=8F=AC=E5=AE=87?= Date: Thu, 5 Sep 2024 09:29:53 +0000 Subject: [PATCH 4/6] update Fix-CVE-2023-45322.patch. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 冉召宇 --- Fix-CVE-2023-45322.patch | 74 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/Fix-CVE-2023-45322.patch b/Fix-CVE-2023-45322.patch index e69de29..44cb26b 100644 --- a/Fix-CVE-2023-45322.patch +++ b/Fix-CVE-2023-45322.patch @@ -0,0 +1,74 @@ +From d39f78069dff496ec865c73aa44d7110e429bce9 Mon Sep 17 00:00:00 2001 +From: Nick Wellnhofer +Date: Wed, 23 Aug 2023 20:24:24 +0200 +Subject: [PATCH] tree: Fix copying of DTDs + +- Don't create multiple DTD nodes. +- Fix UAF if malloc fails. +- Skip DTD nodes if tree module is disabled. + +Fixes #583. +--- + tree.c | 31 ++++++++++++++++--------------- + 1 file changed, 16 insertions(+), 15 deletions(-) + +diff --git a/tree.c b/tree.c +index 6c8a875b9..02c1b5791 100644 +--- a/tree.c ++++ b/tree.c +@@ -4370,29 +4370,28 @@ xmlNodePtr + xmlStaticCopyNodeList(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent) { + xmlNodePtr ret = NULL; + xmlNodePtr p = NULL,q; ++ xmlDtdPtr newSubset = NULL; + + while (node != NULL) { +-#ifdef LIBXML_TREE_ENABLED + if (node->type == XML_DTD_NODE ) { +- if (doc == NULL) { ++#ifdef LIBXML_TREE_ENABLED ++ if ((doc == NULL) || (doc->intSubset != NULL)) { + node = node->next; + continue; + } +- if (doc->intSubset == NULL) { +- q = (xmlNodePtr) xmlCopyDtd( (xmlDtdPtr) node ); +- if (q == NULL) goto error; +- q->doc = doc; +- q->parent = parent; +- doc->intSubset = (xmlDtdPtr) q; +- xmlAddChild(parent, q); +- } else { +- q = (xmlNodePtr) doc->intSubset; +- xmlAddChild(parent, q); +- } +- } else ++ q = (xmlNodePtr) xmlCopyDtd( (xmlDtdPtr) node ); ++ if (q == NULL) goto error; ++ q->doc = doc; ++ q->parent = parent; ++ newSubset = (xmlDtdPtr) q; ++#else ++ node = node->next; ++ continue; + #endif /* LIBXML_TREE_ENABLED */ ++ } else { + q = xmlStaticCopyNode(node, doc, parent, 1); +- if (q == NULL) goto error; ++ if (q == NULL) goto error; ++ } + if (ret == NULL) { + q->prev = NULL; + ret = p = q; +@@ -4404,6 +4403,8 @@ xmlStaticCopyNodeList(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent) { + } + node = node->next; + } ++ if (newSubset != NULL) ++ doc->intSubset = newSubset; + return(ret); + error: + xmlFreeNodeList(ret); +-- +GitLab + -- Gitee From 9dd152a3006af17c8991e884d090b0b19a87330f Mon Sep 17 00:00:00 2001 From: "@ran-zhao-yu" Date: Tue, 15 Oct 2024 14:17:53 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: @ran-zhao-yu --- BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/BUILD.gn b/BUILD.gn index a01357c..974ffd0 100755 --- a/BUILD.gn +++ b/BUILD.gn @@ -146,6 +146,7 @@ group("xml2") { } ohos_shared_library("libxml2") { + branch_protector_ret = "pac_ret" output_values = get_target_outputs(":libxml2_install_action") sources = filter_exclude(output_values, [ -- Gitee From 519f821389c5ca6bbdaa112dcf93f6c5e0097d4b Mon Sep 17 00:00:00 2001 From: "@ran-zhao-yu" Date: Tue, 11 Mar 2025 10:08:45 +0800 Subject: [PATCH 6/6] =?UTF-8?q?5.0.3=E4=BF=AE=E8=A1=A5=E6=BC=8F=E6=B4=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: @ran-zhao-yu --- Fix-CVE-2024-56171.patch | 41 +++++++++++++++++++++++++++++ Fix-CVE-2025-24928.patch | 56 ++++++++++++++++++++++++++++++++++++++++ Fix-CVE-2025-27113.patch | 31 ++++++++++++++++++++++ install.py | 5 +++- 4 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 Fix-CVE-2024-56171.patch create mode 100644 Fix-CVE-2025-24928.patch create mode 100644 Fix-CVE-2025-27113.patch diff --git a/Fix-CVE-2024-56171.patch b/Fix-CVE-2024-56171.patch new file mode 100644 index 0000000..320a579 --- /dev/null +++ b/Fix-CVE-2024-56171.patch @@ -0,0 +1,41 @@ +From 5880a9a6bd97c0f9ac8fc4f30110fe023f484746 Mon Sep 17 00:00:00 2001 +From: Nick Wellnhofer +Date: Tue, 10 Dec 2024 16:52:05 +0100 +Subject: [PATCH] [CVE-2024-56171] Fix use-after-free after + xmlSchemaItemListAdd + +xmlSchemaItemListAdd can reallocate the items array. Update local +variables after adding item in + +- xmlSchemaIDCFillNodeTables +- xmlSchemaBubbleIDCNodeTables + +Fixes #828. +--- + xmlschemas.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/xmlschemas.c b/xmlschemas.c +index 1b3c524f2..95be97c96 100644 +--- a/xmlschemas.c ++++ b/xmlschemas.c +@@ -23374,6 +23374,7 @@ xmlSchemaIDCFillNodeTables(xmlSchemaValidCtxtPtr vctxt, + } + if (xmlSchemaItemListAdd(bind->dupls, bind->nodeTable[j]) == -1) + goto internal_error; ++ dupls = (xmlSchemaPSVIIDCNodePtr *) bind->dupls->items; + /* + * Remove the duplicate entry from the IDC node-table. + */ +@@ -23590,6 +23591,8 @@ xmlSchemaBubbleIDCNodeTables(xmlSchemaValidCtxtPtr vctxt) + goto internal_error; + } + xmlSchemaItemListAdd(parBind->dupls, parNode); ++ dupls = (xmlSchemaPSVIIDCNodePtr *) ++ parBind->dupls->items; + } else { + /* + * Add the node-table entry (node and key-sequence) of +-- +GitLab + diff --git a/Fix-CVE-2025-24928.patch b/Fix-CVE-2025-24928.patch new file mode 100644 index 0000000..7e38b31 --- /dev/null +++ b/Fix-CVE-2025-24928.patch @@ -0,0 +1,56 @@ +From 8c8753ad5280ee13aee5eec9b0f6eee2ed920f57 Mon Sep 17 00:00:00 2001 +From: Nick Wellnhofer +Date: Tue, 11 Feb 2025 17:30:40 +0100 +Subject: [PATCH] [CVE-2025-24928] Fix stack-buffer-overflow in + xmlSnprintfElements + +Fixes #847. +--- + valid.c | 22 +++++++++++----------- + 1 file changed, 11 insertions(+), 11 deletions(-) + +diff --git a/valid.c b/valid.c +index d63137fa0..6a8ae1fb4 100644 +--- a/valid.c ++++ b/valid.c +@@ -4997,26 +4997,26 @@ xmlSnprintfElements(char *buf, int size, xmlNodePtr node, int glob) { + return; + } + switch (cur->type) { +- case XML_ELEMENT_NODE: ++ case XML_ELEMENT_NODE: { ++ int qnameLen = xmlStrlen(cur->name); ++ ++ if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) ++ qnameLen += xmlStrlen(cur->ns->prefix) + 1; ++ if (size - len < qnameLen + 10) { ++ if ((size - len > 4) && (buf[len - 1] != '.')) ++ strcat(buf, " ..."); ++ return; ++ } + if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) { +- if (size - len < xmlStrlen(cur->ns->prefix) + 10) { +- if ((size - len > 4) && (buf[len - 1] != '.')) +- strcat(buf, " ..."); +- return; +- } + strcat(buf, (char *) cur->ns->prefix); + strcat(buf, ":"); + } +- if (size - len < xmlStrlen(cur->name) + 10) { +- if ((size - len > 4) && (buf[len - 1] != '.')) +- strcat(buf, " ..."); +- return; +- } + if (cur->name != NULL) + strcat(buf, (char *) cur->name); + if (cur->next != NULL) + strcat(buf, " "); + break; ++ } + case XML_TEXT_NODE: + if (xmlIsBlankNode(cur)) + break; +-- +GitLab + diff --git a/Fix-CVE-2025-27113.patch b/Fix-CVE-2025-27113.patch new file mode 100644 index 0000000..3602af6 --- /dev/null +++ b/Fix-CVE-2025-27113.patch @@ -0,0 +1,31 @@ +From 6c716d491dd2e67f08066f4dc0619efeb49e43e6 Mon Sep 17 00:00:00 2001 +From: Nick Wellnhofer +Date: Thu, 13 Feb 2025 16:48:53 +0100 +Subject: [PATCH] pattern: Fix compilation of explicit child axis + +The child axis is the default axis and should generate XML_OP_ELEM like +the case without an axis. +--- + pattern.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/pattern.c b/pattern.c +index 0877fc1a0..6fa88f759 100644 +--- a/pattern.c ++++ b/pattern.c +@@ -1035,10 +1035,10 @@ xmlCompileStepPattern(xmlPatParserContextPtr ctxt) { + goto error; + } + } else { +- PUSH(XML_OP_CHILD, token, URL); ++ PUSH(XML_OP_ELEM, token, URL); + } + } else +- PUSH(XML_OP_CHILD, name, NULL); ++ PUSH(XML_OP_ELEM, name, NULL); + return; + } else if (xmlStrEqual(name, (const xmlChar *) "attribute")) { + XML_PAT_FREE_STRING(ctxt, name) +-- +GitLab + diff --git a/install.py b/install.py index 078f04a..9fdb839 100755 --- a/install.py +++ b/install.py @@ -230,7 +230,10 @@ def do_patch(args, target_dir): "backport-xpath-Ignore-entity-ref-nodes-when-computing-node-ha.patch", "backport-SAX-Always-initialize-SAX1-element-handlers.patch", "Fix-malloc-fail.patch", - "Fix-CVE-2024-34459.patch" + "Fix-CVE-2024-34459.patch", + "Fix-CVE-2024-56171.patch", + "Fix-CVE-2025-24928.patch", + "Fix-CVE-2025-27113.patch" ] for patch in patch_file: -- Gitee