]> granicus.if.org Git - php/commitdiff
- Fixed missing NULL check
authorFelipe Pena <felipensp@gmail.com>
Sat, 10 May 2014 14:39:08 +0000 (11:39 -0300)
committerFelipe Pena <felipensp@gmail.com>
Sat, 10 May 2014 14:39:08 +0000 (11:39 -0300)
ext/simplexml/simplexml.c
ext/simplexml/tests/SimpleXMLElement_getDocNamespaces.phpt [new file with mode: 0644]

index 15a8512a436de6d6f9ec16fb4a5620496e05ce8d..006d6c9491608602c6d0afd0b748b869a63967b1 100644 (file)
@@ -1533,15 +1533,18 @@ SXE_METHOD(getDocNamespaces)
                return;
        }
 
-       array_init(return_value);
-
        sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
        if(from_root){
                node = xmlDocGetRootElement((xmlDocPtr)sxe->document->ptr);
        }else{
                GET_NODE(sxe, node);
        }
-
+       
+       if (node == NULL) {
+               RETURN_FALSE;
+       }
+       
+       array_init(return_value);
        sxe_add_registered_namespaces(sxe, node, recursive, return_value TSRMLS_CC);
 }
 /* }}} */
diff --git a/ext/simplexml/tests/SimpleXMLElement_getDocNamespaces.phpt b/ext/simplexml/tests/SimpleXMLElement_getDocNamespaces.phpt
new file mode 100644 (file)
index 0000000..9df7591
--- /dev/null
@@ -0,0 +1,9 @@
+--TEST--
+Testing getDocNamespaces() with invalid XML
+--FILE--
+<?php
+$xml = @new SimpleXMLElement("X",1);
+var_dump($xml->getDocNamespaces());
+?>
+--EXPECTF--
+bool(false)