msxml3: Handle NULL parameter in IXMLDOMElement::get_ownerDocument().

Zhenbo Li litimetal at gmail.com
Thu Jul 23 00:26:43 CDT 2015


Hi Nikolay,

2015-07-18 23:34 GMT+08:00 Nikolay Sivov <bunglehead at gmail.com>:
>>
>> Do you mean an iteration like that? Have I tested all the included nodes?
>
>
> In principle yes, but you're not testing anything in that patch,
> ownerDocument() is IXMLDOMNode property, you have to call it on 'node'.
> Also this document doesn't cover anything but elements I think, because
> childNodes() only iterates through immediate children, and grand-children
> are not included (I think, it's been a while since I looked into that). So I
> suggest adding a new document, with all kinds of nodes, and run a loop on
> it. Attribute nodes still need special handling.
Okay, so I write a recursive test for it. Could you have a check with it?

>
>> Also, we already have a helper function: test_get_ownerDocument()
>> Should I use this?
>>
>
> Right, I missed that, please move new loop there.
I'm wondering how to combine the tests now.
Can I just call test_null_owner in test_get_ownerDocument()?
It seems easier.

Thanks

-- 
Have a nice day!
Zhenbo Li
-------------- next part --------------
diff --git a/dlls/msxml3/node.c b/dlls/msxml3/node.c
index 1ddc9bf..90b5bde 100644
--- a/dlls/msxml3/node.c
+++ b/dlls/msxml3/node.c
@@ -654,6 +654,8 @@ HRESULT node_has_childnodes(const xmlnode *This, VARIANT_BOOL *ret)
 
 HRESULT node_get_owner_doc(const xmlnode *This, IXMLDOMDocument **doc)
 {
+    if(!doc)
+        return E_INVALIDARG;
     return get_domdoc_from_xmldoc(This->node->doc, (IXMLDOMDocument3**)doc);
 }
 
diff --git a/dlls/msxml3/tests/domdoc.c b/dlls/msxml3/tests/domdoc.c
index f7f57ac..6ec199c 100644
--- a/dlls/msxml3/tests/domdoc.c
+++ b/dlls/msxml3/tests/domdoc.c
@@ -3364,6 +3364,61 @@ static void test_get_childNodes(void)
     free_bstrs();
 }
 
+static void test_null_owner_recursive(IXMLDOMElement *root_element)
+{
+    IXMLDOMNodeList *node_list;
+    IXMLDOMNode *node;
+    IXMLDOMElement *element;
+    HRESULT hr;
+    LONG i, len;
+
+    hr = IXMLDOMElement_get_childNodes( root_element, &node_list );
+    EXPECT_HR(hr, S_OK);
+
+    hr = IXMLDOMNodeList_get_length( node_list, &len );
+    EXPECT_HR(hr, S_OK);
+
+    for(i = 0; i < len; i++) {
+        hr = IXMLDOMNodeList_get_item(node_list, 0, &node);
+        EXPECT_HR(hr, S_OK);
+
+        hr = IXMLDOMNode_get_ownerDocument( node, NULL );
+        EXPECT_HR(hr, E_INVALIDARG);
+
+        hr = IXMLDOMNode_QueryInterface( node, &IID_IXMLDOMElement, (void**)&element );
+        if(hr == S_OK) {
+            test_null_owner_recursive(element);
+            IXMLDOMElement_Release(element);
+        }
+
+        IXMLDOMNode_Release(node);
+    }
+    IXMLDOMNodeList_Release( node_list );
+}
+
+static void test_null_owner(void)
+{
+    VARIANT_BOOL b;
+    IXMLDOMDocument *doc;
+    IXMLDOMElement *element;
+    HRESULT hr;
+
+    doc = create_document(&IID_IXMLDOMDocument);
+
+    hr = IXMLDOMDocument_loadXML( doc, _bstr_(szNodeTypesXML), &b );
+    EXPECT_HR(hr, S_OK);
+    ok( b == VARIANT_TRUE, "failed to load XML string\n");
+
+    hr = IXMLDOMDocument_get_documentElement( doc, &element );
+    EXPECT_HR(hr, S_OK);
+
+    test_null_owner_recursive(element);
+
+    IXMLDOMElement_Release(element);
+    IXMLDOMDocument_Release( doc );
+    free_bstrs();
+}
+
 static void test_get_firstChild(void)
 {
     static const WCHAR xmlW[] = {'x','m','l',0};
@@ -11964,6 +12019,8 @@ START_TEST(domdoc)
     test_xsltemplate();
     test_xsltext();
 
+    test_null_owner();
+
     if (is_clsid_supported(&CLSID_MXNamespaceManager40, &IID_IMXNamespaceManager))
     {
         test_mxnamespacemanager();


More information about the wine-devel mailing list