tony2001                Wed Jan 23 09:59:42 2008 UTC

  Modified files:              
    /php-src/ext/simplexml      simplexml.c 
    /php-src/ext/simplexml/tests        bug37076_1.phpt 
  Log:
  MFH: fix leak appearing when appending data to unnamed attribute
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/simplexml/simplexml.c?r1=1.249&r2=1.250&diff_format=u
Index: php-src/ext/simplexml/simplexml.c
diff -u php-src/ext/simplexml/simplexml.c:1.249 
php-src/ext/simplexml/simplexml.c:1.250
--- php-src/ext/simplexml/simplexml.c:1.249     Tue Jan 22 20:40:30 2008
+++ php-src/ext/simplexml/simplexml.c   Wed Jan 23 09:59:42 2008
@@ -18,7 +18,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: simplexml.c,v 1.249 2008/01/22 20:40:30 helly Exp $ */
+/* $Id: simplexml.c,v 1.250 2008/01/23 09:59:42 tony2001 Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -461,7 +461,7 @@
 
 /* {{{ sxe_property_write()
  */
-static void sxe_prop_dim_write(zval *object, zval *member, zval *value, 
zend_bool elements, zend_bool attribs, xmlNodePtr *pnewnode TSRMLS_DC)
+static int sxe_prop_dim_write(zval *object, zval *member, zval *value, 
zend_bool elements, zend_bool attribs, xmlNodePtr *pnewnode TSRMLS_DC)
 {
        php_sxe_object *sxe;
        xmlNodePtr      node;
@@ -475,6 +475,7 @@
        int             test = 0;
        int                             new_value = 0;
        long            cnt = 0;
+       int                             retval = SUCCESS;
        zval            tmp_zv, trim_zv, value_copy;
 
        sxe = php_sxe_fetch_object(object TSRMLS_CC);
@@ -489,7 +490,7 @@
                         * and this is during runtime.
                         */
                        php_error_docref(NULL TSRMLS_CC, E_ERROR, "Cannot 
create unnamed attribute");
-                       return;
+                       return FAILURE;
                }
        } else {
                if (Z_TYPE_P(member) != IS_STRING) {
@@ -506,7 +507,7 @@
                        if (member == &tmp_zv) {
                                zval_dtor(&tmp_zv);
                        }
-                       return;
+                       return FAILURE;
                }
        }
 
@@ -530,7 +531,7 @@
                         * and this is during runtime.
                         */
                        php_error_docref(NULL TSRMLS_CC, E_ERROR, "Cannot 
create unnamed attribute");
-                       return;
+                       return FAILURE;
                }
                if (attribs && !node && sxe->iter.type == SXE_ITER_ELEMENT) {
                        node = xmlNewChild(mynode, mynode->ns, sxe->iter.name, 
NULL);
@@ -572,7 +573,7 @@
                                        zval_dtor(&tmp_zv);
                                }
                                zend_error(E_WARNING, "It is not yet possible 
to assign complex types to %s", attribs ? "attributes" : "properties");
-                               return;
+                               return FAILURE;
                }
        }
 
@@ -607,7 +608,7 @@
                        if (!member || Z_TYPE_P(member) == IS_LONG) {
                                if (node->type == XML_ATTRIBUTE_NODE) {
                                        php_error_docref(NULL TSRMLS_CC, 
E_ERROR, "Cannot create duplicate attribute");
-                                       return;
+                                       return FAILURE;
                                }
 
                                if (sxe->iter.type == SXE_ITER_NONE) {
@@ -615,6 +616,7 @@
                                        ++counter;
                                        if (member && Z_LVAL_P(member) > 0) {
                                                php_error_docref(NULL 
TSRMLS_CC, E_WARNING, "Cannot add element %s number %ld when only 0 such 
elements exist", mynode->name, Z_LVAL_P(member));
+                                               retval = FAILURE;
                                        }
                                } else if (member) {
                                        newnode = 
sxe_get_element_by_offset(sxe, Z_LVAL_P(member), node, &cnt);
@@ -651,6 +653,7 @@
                        }
                } else if (counter > 1) {
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot 
assign to an array of nodes (duplicate subnodes or attr detected)");
+                       retval = FAILURE;
                } else if (elements) {
                        if (!node) {
                                if (!member || Z_TYPE_P(member) == IS_LONG) {
@@ -661,12 +664,14 @@
                        } else if (!member || Z_TYPE_P(member) == IS_LONG) {
                                if (member && cnt < Z_LVAL_P(member)) {
                                        php_error_docref(NULL TSRMLS_CC, 
E_WARNING, "Cannot add element %s number %ld when only %ld such elements 
exist", mynode->name, Z_LVAL_P(member), cnt);
+                                       retval = FAILURE;
                                }
                                newnode = xmlNewTextChild(mynode->parent, 
mynode->ns, mynode->name, value ? (xmlChar *)Z_STRVAL_P(value) : NULL);
                        }
                } else if (attribs) {
                        if (Z_TYPE_P(member) == IS_LONG) {
                                php_error_docref(NULL TSRMLS_CC, E_WARNING, 
"Cannot change attribute number %ld when only %d attributes exist", 
Z_LVAL_P(member), nodendx);
+                               retval = FAILURE;
                        } else {
                                newnode = (xmlNodePtr)xmlNewProp(node, (xmlChar 
*)Z_STRVAL_P(member), value ? (xmlChar *)Z_STRVAL_P(value) : NULL);
                        }
@@ -685,6 +690,7 @@
        if (new_value) {
                zval_ptr_dtor(&value);
        }
+       return retval;
 }
 /* }}} */
 
@@ -722,7 +728,9 @@
        if (node) {
                return NULL;
        }
-       sxe_prop_dim_write(object, member, NULL, 1, 0, &node TSRMLS_CC);
+       if (sxe_prop_dim_write(object, member, NULL, 1, 0, &node TSRMLS_CC) != 
SUCCESS) {
+               return NULL;
+       }
        type = SXE_ITER_NONE;
        name = NULL;
 
@@ -2533,7 +2541,7 @@
 {
        php_info_print_table_start();
        php_info_print_table_header(2, "Simplexml support", "enabled");
-       php_info_print_table_row(2, "Revision", "$Revision: 1.249 $");
+       php_info_print_table_row(2, "Revision", "$Revision: 1.250 $");
        php_info_print_table_row(2, "Schema support",
 #ifdef LIBXML_SCHEMAS_ENABLED
                "enabled");
http://cvs.php.net/viewvc.cgi/php-src/ext/simplexml/tests/bug37076_1.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/simplexml/tests/bug37076_1.phpt
diff -u /dev/null php-src/ext/simplexml/tests/bug37076_1.phpt:1.2
--- /dev/null   Wed Jan 23 09:59:42 2008
+++ php-src/ext/simplexml/tests/bug37076_1.phpt Wed Jan 23 09:59:42 2008
@@ -0,0 +1,16 @@
+--TEST--
+Bug #37076 (SimpleXML ignores .=) (appending to unnamed attribute)
+--FILE--
+<?php
+$xml = simplexml_load_string("<root><foo /></root>");
+$xml->{""} .= "bar";
+print $xml->asXML();
+?>
+===DONE===
+--EXPECTF--
+Warning: main(): Cannot write or create unnamed element in %s on line %d
+
+Warning: main(): Cannot write or create unnamed element in %s on line %d
+<?xml version="1.0"?>
+<root><foo/></root>
+===DONE===

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to