[PATCH v2] msxml3: Fix crash with property xmlns without prefix.

Bernhard Übelacker bernhardu at mailbox.org
Thu Sep 9 04:40:16 CDT 2021


Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=50475
Signed-off-by: Bernhard Übelacker <bernhardu at mailbox.org>
---
Changes since v1:
- Move test into existing function test_namespaces_as_attributes.
---
 dlls/msxml3/element.c      |  5 ++++-
 dlls/msxml3/tests/domdoc.c | 21 +++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/dlls/msxml3/element.c b/dlls/msxml3/element.c
index 1a523798328..c11d28b066c 100644
--- a/dlls/msxml3/element.c
+++ b/dlls/msxml3/element.c
@@ -1832,7 +1832,10 @@ static HRESULT domelem_get_item(const xmlNodePtr node, LONG index, IXMLDOMNode *
     if (!xmlns)
         return E_OUTOFMEMORY;
 
-    curr = xmlNewNsProp(NULL, xmlns, ns->prefix, ns->href);
+    if (ns->prefix)
+        curr = xmlNewNsProp(NULL, xmlns, ns->prefix, ns->href);
+    else
+        curr = xmlNewProp(NULL, xmlns->prefix, ns->href);
     if (!curr) {
         xmlFreeNs(xmlns);
         return E_OUTOFMEMORY;
diff --git a/dlls/msxml3/tests/domdoc.c b/dlls/msxml3/tests/domdoc.c
index 063f9433a77..361f8341ca3 100644
--- a/dlls/msxml3/tests/domdoc.c
+++ b/dlls/msxml3/tests/domdoc.c
@@ -13403,6 +13403,15 @@ static void test_namespaces_as_attributes(void)
             { "" },         /* namespaceURI */
             { "nshref" },   /* text */
         },
+        /* xmlns without prefix */
+        {
+            "<a xmlns=\"nshref\" />", 1,
+            { "xmlns" },    /* nodeName */
+            { NULL },       /* prefix */
+            { "xmlns" },    /* baseName */
+            { NULL },       /* namespaceURI */
+            { "nshref" },   /* text */
+        },
         /* no properties or namespaces */
         {
             "<a />", 0,
@@ -13439,6 +13448,18 @@ static void test_namespaces_as_attributes(void)
             hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("a"), &node);
             ok(SUCCEEDED(hr), "Failed to select a node, hr %#x.\n", hr);
 
+            if (!node)
+            {
+                IXMLDOMNodeList *node_list;
+                hr = IXMLDOMDocument_get_childNodes(doc, &node_list);
+                ok(hr == S_OK, "Failed to get_childNodes, hr %#x.\n", hr);
+
+                hr = IXMLDOMNodeList_get_item(node_list, 0, &node);
+                ok(hr == S_OK, "Failed to get_item, hr %#x.\n", hr);
+
+                IXMLDOMNodeList_Release(node_list);
+            }
+
             hr = IXMLDOMNode_get_attributes(node, &map);
             ok(SUCCEEDED(hr), "Failed to get attributes, hr %#x.\n", hr);
 
-- 
2.30.2




More information about the wine-devel mailing list