helly           Sun Feb 26 15:48:28 2006 UTC

  Modified files:              
    /php-src/ext/simplexml      php_simplexml.h simplexml.c 
    /php-src/ext/simplexml/tests        006.phpt bug35785.phpt 
  Log:
  - Use get_property_ptr_ptr handler to prevent SEGV as in bug #35785
  # Issue not completley solved though
  
  
http://cvs.php.net/viewcvs.cgi/php-src/ext/simplexml/php_simplexml.h?r1=1.22&r2=1.23&diff_format=u
Index: php-src/ext/simplexml/php_simplexml.h
diff -u php-src/ext/simplexml/php_simplexml.h:1.22 
php-src/ext/simplexml/php_simplexml.h:1.23
--- php-src/ext/simplexml/php_simplexml.h:1.22  Sun Jan  1 13:09:53 2006
+++ php-src/ext/simplexml/php_simplexml.h       Sun Feb 26 15:48:28 2006
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: php_simplexml.h,v 1.22 2006/01/01 13:09:53 sniper Exp $ */
+/* $Id: php_simplexml.h,v 1.23 2006/02/26 15:48:28 helly Exp $ */
 
 #ifndef PHP_SIMPLEXML_H
 #define PHP_SIMPLEXML_H
@@ -53,6 +53,13 @@
 #endif
 PHP_MINFO_FUNCTION(simplexml);
 
+typedef enum {
+       SXE_ITER_NONE     = 0,
+       SXE_ITER_ELEMENT  = 1,
+       SXE_ITER_CHILD    = 2,
+       SXE_ITER_ATTRLIST = 3
+} SXE_ITER;
+
 typedef struct {
        zend_object zo;
        php_libxml_node_ptr *node;
@@ -63,16 +70,12 @@
                int                   itertype;
                char                  *name;
                char                  *nsprefix;
-               int                   type;
+               SXE_ITER              type;
                zval                  *data;
        } iter;
+       zval *tmp;
 } php_sxe_object;
 
-#define SXE_ITER_NONE 0
-#define SXE_ITER_ELEMENT 1
-#define SXE_ITER_CHILD 2
-#define SXE_ITER_ATTRLIST 3
-
 #ifdef ZTS
 #define SIMPLEXML_G(v) TSRMG(simplexml_globals_id, zend_simplexml_globals *, v)
 #else
http://cvs.php.net/viewcvs.cgi/php-src/ext/simplexml/simplexml.c?r1=1.191&r2=1.192&diff_format=u
Index: php-src/ext/simplexml/simplexml.c
diff -u php-src/ext/simplexml/simplexml.c:1.191 
php-src/ext/simplexml/simplexml.c:1.192
--- php-src/ext/simplexml/simplexml.c:1.191     Sun Feb 26 13:37:54 2006
+++ php-src/ext/simplexml/simplexml.c   Sun Feb 26 15:48:28 2006
@@ -18,7 +18,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: simplexml.c,v 1.191 2006/02/26 13:37:54 helly Exp $ */
+/* $Id: simplexml.c,v 1.192 2006/02/26 15:48:28 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -58,7 +58,7 @@
 
 /* {{{ _node_as_zval()
  */
-static void _node_as_zval(php_sxe_object *sxe, xmlNodePtr node, zval *value, 
int itertype, char *name, char *prefix TSRMLS_DC)
+static void _node_as_zval(php_sxe_object *sxe, xmlNodePtr node, zval *value, 
SXE_ITER itertype, char *name, char *prefix TSRMLS_DC)
 {
        php_sxe_object *subnode;
 
@@ -160,7 +160,6 @@
 }
 /* }}} */
 
-#if SXE_ELEMENT_BY_NAME
 static xmlNodePtr sxe_find_element_by_name(php_sxe_object *sxe, xmlNodePtr 
node, char *name TSRMLS_DC) /* {{{ */
 {
        while (node) {
@@ -176,7 +175,7 @@
        return NULL;
 } /* }}} */
 
-static xmlNodePtr sxe_get_element_by_name(php_sxe_object *sxe, xmlNodePtr 
node, char **name, int *type TSRMLS_DC) /* {{{ */
+static xmlNodePtr sxe_get_element_by_name(php_sxe_object *sxe, xmlNodePtr 
node, char **name, SXE_ITER *type TSRMLS_DC) /* {{{ */
 {
        int         orgtype;
        xmlNodePtr  orgnode = node;
@@ -223,7 +222,6 @@
        return NULL;
 }
 /* }}} */
-#endif /* SXE_ELEMENT_BY_NAME */
 
 /* {{{ sxe_prop_dim_read()
  */
@@ -360,6 +358,11 @@
 {
        zval value_copy;
 
+       if (!value)
+       {
+               xmlNodeSetContentLen(node, "", 0);
+               return;
+       }
        switch (Z_TYPE_P(value)) {
                case IS_LONG:
                case IS_BOOL:
@@ -388,7 +391,7 @@
 
 /* {{{ sxe_property_write()
  */
-static void sxe_prop_dim_write(zval *object, zval *member, zval *value, 
zend_bool elements, zend_bool attribs TSRMLS_DC)
+static void sxe_prop_dim_write(zval *object, zval *member, zval *value, 
zend_bool elements, zend_bool attribs, xmlNodePtr *pnewnode TSRMLS_DC)
 {
        php_sxe_object *sxe;
        char           *name;
@@ -463,18 +466,20 @@
 
        mynode = node;
 
-       switch (Z_TYPE_P(value)) {
-               case IS_LONG:
-               case IS_BOOL:
-               case IS_DOUBLE:
-               case IS_NULL:
-               case IS_UNICODE:
-                       convert_to_string(value);
-                       break;
-               case IS_STRING:
-                       break;
-               default:
-                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "It is not 
yet possible to assign complex types to %s", attribs ? "attributes" : 
"properties");
+       if (value) {
+               switch (Z_TYPE_P(value)) {
+                       case IS_LONG:
+                       case IS_BOOL:
+                       case IS_DOUBLE:
+                       case IS_NULL:
+                       case IS_UNICODE:
+                               convert_to_string(value);
+                               break;
+                       case IS_STRING:
+                               break;
+                       default:
+                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "It 
is not yet possible to assign complex types to %s", attribs ? "attributes" : 
"properties");
+               }
        }
 
        if (node) {
@@ -530,30 +535,35 @@
                        if (is_attr) {
                                newnode = (xmlNodePtr) attr;
                        }
-                       while ((tempnode = (xmlNodePtr) newnode->children)) {
-                               xmlUnlinkNode(tempnode);
-                               php_libxml_node_free_resource((xmlNodePtr) 
tempnode TSRMLS_CC);
+                       if (value) {
+                               while ((tempnode = (xmlNodePtr) 
newnode->children)) {
+                                       xmlUnlinkNode(tempnode);
+                                       
php_libxml_node_free_resource((xmlNodePtr) tempnode TSRMLS_CC);
+                               }
+                               change_node_zval(newnode, value TSRMLS_CC);
                        }
-                       change_node_zval(newnode, value TSRMLS_CC);
                } else if (counter > 1) {
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot 
assign to an array of nodes (duplicate subnodes or attr detected)");
                } else if (elements) {
                        if (!node) {
-                               xmlNewTextChild(mynode, mynode->ns, name, 
Z_STRVAL_P(value));
+                               newnode = xmlNewTextChild(mynode, mynode->ns, 
name, value ? Z_STRVAL_P(value) : NULL);
                        } else if (Z_TYPE_P(member) == IS_LONG) {
                                if (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);
                                }
-                               xmlNewTextChild(mynode->parent, mynode->ns, 
mynode->name, Z_STRVAL_P(value));
+                               newnode = xmlNewTextChild(mynode->parent, 
mynode->ns, mynode->name, value ? Z_STRVAL_P(value) : NULL);
                        }
                } else if (attribs) {
-                       newnode = (xmlNodePtr)xmlNewProp(node, name, 
Z_STRVAL_P(value));
+                       newnode = (xmlNodePtr)xmlNewProp(node, name, value ? 
Z_STRVAL_P(value) : NULL);
                }
        }
 
        if (member == &tmp_zv) {
                zval_dtor(&tmp_zv);
        }
+       if (pnewnode) {
+               *pnewnode = newnode;
+       }
 }
 /* }}} */
 
@@ -561,7 +571,7 @@
  */
 static void sxe_property_write(zval *object, zval *member, zval *value 
TSRMLS_DC)
 {
-       sxe_prop_dim_write(object, member, value, 1, 0 TSRMLS_CC);
+       sxe_prop_dim_write(object, member, value, 1, 0, NULL TSRMLS_CC);
 }
 /* }}} */
 
@@ -569,7 +579,36 @@
  */
 static void sxe_dimension_write(zval *object, zval *offset, zval *value 
TSRMLS_DC)
 {
-       sxe_prop_dim_write(object, offset, value, 0, 1 TSRMLS_CC);
+       sxe_prop_dim_write(object, offset, value, 0, 1, NULL TSRMLS_CC);
+}
+/* }}} */
+
+static zval** sxe_property_get_adr(zval *object, zval *member TSRMLS_DC) /* 
{{{ */
+{
+       php_sxe_object *sxe;
+       xmlNodePtr      node;
+       zval           *return_value;
+       char           *name;
+       SXE_ITER        type;
+
+       sxe = php_sxe_fetch_object(object TSRMLS_CC);
+
+       GET_NODE(sxe, node);
+       name = Z_STRVAL_P(member);
+       node = sxe_get_element_by_name(sxe, node, &name, &type TSRMLS_CC);
+       if (!node) {
+               sxe_prop_dim_write(object, member, NULL, 1, 0, &node TSRMLS_CC);
+               type = SXE_ITER_NONE;
+               name = NULL;
+       }
+       MAKE_STD_ZVAL(return_value);
+       _node_as_zval(sxe, node, return_value, type, name, sxe->iter.nsprefix 
TSRMLS_CC);
+
+       sxe = php_sxe_fetch_object(return_value TSRMLS_CC);
+       sxe->tmp = return_value;
+       return_value->is_ref  = 1;
+
+       return &sxe->tmp;
 }
 /* }}} */
 
@@ -578,7 +617,6 @@
 static int sxe_prop_dim_exists(zval *object, zval *member, int check_empty, 
zend_bool elements, zend_bool attribs TSRMLS_DC)
 {
        php_sxe_object *sxe;
-       char           *name;
        xmlNodePtr      node;
        xmlAttrPtr      attr = NULL;
        int                             exists = 0;
@@ -586,8 +624,6 @@
 
        sxe = php_sxe_fetch_object(object TSRMLS_CC);
 
-       name = Z_STRVAL_P(member);
-
        GET_NODE(sxe, node);
 
        if (Z_TYPE_P(member) == IS_LONG) {
@@ -615,7 +651,7 @@
        if (node) {
                if (attribs) {
                        while (attr) {
-                               if ((!test || !xmlStrcmp(attr->name, 
sxe->iter.name)) && !xmlStrcmp(attr->name, name) && match_ns(sxe, (xmlNodePtr) 
attr, sxe->iter.nsprefix)) {
+                               if ((!test || !xmlStrcmp(attr->name, 
sxe->iter.name)) && !xmlStrcmp(attr->name, Z_STRVAL_P(member)) && match_ns(sxe, 
(xmlNodePtr) attr, sxe->iter.nsprefix)) {
                                        exists = 1;
                                        break;
                                }
@@ -1435,7 +1471,7 @@
        sxe_property_write,
        sxe_dimension_read,
        sxe_dimension_write,
-       NULL,
+       sxe_property_get_adr,
        sxe_get_value,                  /* get */
        NULL,
        sxe_property_exists,
@@ -1459,7 +1495,7 @@
        sxe_property_write,
        sxe_dimension_read,
        sxe_dimension_write,
-       NULL,
+       sxe_property_get_adr,
        sxe_get_value,                  /* get */
        NULL,
        sxe_property_exists,
@@ -1534,6 +1570,10 @@
                xmlFree(sxe->iter.nsprefix);
                sxe->iter.nsprefix = NULL;
        }
+       if (sxe->tmp) {
+               zval_ptr_dtor(&sxe->tmp);
+               sxe->tmp = NULL;
+       }
 }
 /* }}} */
 
@@ -2072,7 +2112,7 @@
 {
        php_info_print_table_start();
        php_info_print_table_header(2, "Simplexml support", "enabled");
-       php_info_print_table_row(2, "Revision", "$Revision: 1.191 $");
+       php_info_print_table_row(2, "Revision", "$Revision: 1.192 $");
        php_info_print_table_row(2, "Schema support",
 #ifdef LIBXML_SCHEMAS_ENABLED
                "enabled");
http://cvs.php.net/viewcvs.cgi/php-src/ext/simplexml/tests/006.phpt?r1=1.7&r2=1.8&diff_format=u
Index: php-src/ext/simplexml/tests/006.phpt
diff -u php-src/ext/simplexml/tests/006.phpt:1.7 
php-src/ext/simplexml/tests/006.phpt:1.8
--- php-src/ext/simplexml/tests/006.phpt:1.7    Sat Oct 29 16:12:57 2005
+++ php-src/ext/simplexml/tests/006.phpt        Sun Feb 26 15:48:28 2006
@@ -61,6 +61,7 @@
 
 ?>
 ===DONE===
+<?php exit(0); __halt_compiler(); ?>
 --EXPECT--
 string(5) "elem1"
 string(10) "Bla bla 1."
http://cvs.php.net/viewcvs.cgi/php-src/ext/simplexml/tests/bug35785.phpt?r1=1.2&r2=1.3&diff_format=u
Index: php-src/ext/simplexml/tests/bug35785.phpt
diff -u php-src/ext/simplexml/tests/bug35785.phpt:1.2 
php-src/ext/simplexml/tests/bug35785.phpt:1.3
--- php-src/ext/simplexml/tests/bug35785.phpt:1.2       Fri Dec 23 20:31:39 2005
+++ php-src/ext/simplexml/tests/bug35785.phpt   Sun Feb 26 15:48:28 2006
@@ -3,15 +3,16 @@
 --FILE--
 <?php
 
-$options["database"] = "xmldatabase";
 $xml = simplexml_load_string("<root></root>");
-$count = count($xml->posts) + 1;
-$xml->bla->posts[$count]->name = $_POST["name"];
+$count = count($xml->posts);
+var_dump($count);
+$xml->bla->posts[++$count]->name = "FooBar";
 echo $xml->asXML();
 ?>
 ===DONE===
 <?php exit(0); __halt_compiler(); ?>
 --EXPECTF--
+int(0)
 
 Notice: Undefined index:  name in %sbug35785.php on line %d
 

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

Reply via email to