rrichards               Wed Mar  2 13:27:25 2005 EDT

  Modified files:              
    /php-src/ext/xsl    xsltprocessor.c php_xsl.h php_xsl.c 
  Log:
  Fixed bug #31033 (php:function(string, nodeset) with xsl:key crashes PHP)
   - only in 5.1 branch for now due to significance of change
  
http://cvs.php.net/diff.php/php-src/ext/xsl/xsltprocessor.c?r1=1.35&r2=1.36&ty=u
Index: php-src/ext/xsl/xsltprocessor.c
diff -u php-src/ext/xsl/xsltprocessor.c:1.35 
php-src/ext/xsl/xsltprocessor.c:1.36
--- php-src/ext/xsl/xsltprocessor.c:1.35        Mon Jan 17 10:56:17 2005
+++ php-src/ext/xsl/xsltprocessor.c     Wed Mar  2 13:27:25 2005
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: xsltprocessor.c,v 1.35 2005/01/17 15:56:17 chregu Exp $ */
+/* $Id: xsltprocessor.c,v 1.36 2005/03/02 18:27:25 rrichards Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -198,14 +198,12 @@
                                        xmlFree(str);
                                } else if (type == 2) {
                                        int j;
-                                       dom_object *domintern;
+                                       dom_object *domintern = (dom_object 
*)intern->doc;
                                        array_init(args[i]);
                                        if (obj->nodesetval->nodeNr > 0) {
-                                               domintern = (dom_object *) 
php_dom_object_get_data((void *) obj->nodesetval->nodeTab[0]->doc);
                                                for (j = 0; j < 
obj->nodesetval->nodeNr; j++) {
                                                        xmlNodePtr node = 
obj->nodesetval->nodeTab[j];
                                                        zval *child;
-                                                       
                                                        MAKE_STD_ZVAL(child);
                                                        /* not sure, if we need 
this... it's copied from xpath.c */
                                                        if (node->type == 
XML_NAMESPACE_DECL) {
@@ -409,13 +407,26 @@
 /* }}} end xsl_xsltprocessor_import_stylesheet */
 
 
-static xmlDocPtr php_xsl_apply_stylesheet(xsl_object *intern, 
xsltStylesheetPtr style, xmlDocPtr doc TSRMLS_DC)
+static xmlDocPtr php_xsl_apply_stylesheet(xsl_object *intern, 
xsltStylesheetPtr style, zval *docp TSRMLS_DC)
 {
        xmlDocPtr newdocp;
+       xmlDocPtr doc = NULL;
+       xmlNodePtr node = NULL;
        xsltTransformContextPtr ctxt;
+       php_libxml_node_object *object;
        char **params = NULL;
        int clone;
 
+       node = php_libxml_import_node(docp TSRMLS_CC);
+       
+       if (node) {
+               doc = node->doc;
+       }
+       if (doc == NULL) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Document");
+               return NULL;
+       }
+
        if (style == NULL) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "No stylesheet 
associated to this object");
                return NULL;
@@ -424,10 +435,18 @@
                params = php_xsl_xslt_make_params(intern->parameter, 0 
TSRMLS_CC);
        }
 
+       intern->doc = emalloc(sizeof(php_libxml_node_object));
+       memset(intern->doc, 0, sizeof(php_libxml_node_object));
+
        if (intern->hasKeys == 1) {
                doc = xmlCopyDoc(doc, 1);
+       } else {
+               object = (php_libxml_node_object 
*)zend_object_store_get_object(docp TSRMLS_CC);
+               intern->doc->document = object->document;
        }
 
+       php_libxml_increment_doc_ref(intern->doc, doc TSRMLS_CC);
+
        ctxt = xsltNewTransformContext(style, doc);
        ctxt->_private = (void *) intern;
        
@@ -440,10 +459,11 @@
                FREE_HASHTABLE(intern->node_list);      
                intern->node_list = NULL;
        }
+
+       php_libxml_decrement_doc_ref(intern->doc TSRMLS_CC);
+       efree(intern->doc);
+       intern->doc = NULL;
        
-       if (intern->hasKeys == 1) {
-               xmlFreeDoc(doc);
-       }
 
        if (params) {
                clone = 0;
@@ -464,8 +484,6 @@
 PHP_FUNCTION(xsl_xsltprocessor_transform_to_doc)
 {
        zval *id, *rv = NULL, *docp = NULL;
-       xmlDoc *doc = NULL;
-       xmlNodePtr node = NULL;
        xmlDoc *newdocp;
        xsltStylesheetPtr sheetp;
        int ret;
@@ -479,17 +497,7 @@
                RETURN_FALSE;
        }
 
-       node = php_libxml_import_node(docp TSRMLS_CC);
-       
-       if (node) {
-               doc = node->doc;
-       }
-       if (doc == NULL) {
-               php_error(E_WARNING, "Invalid Document");
-               RETURN_NULL();
-       }
-
-       newdocp = php_xsl_apply_stylesheet(intern, sheetp, doc TSRMLS_CC);
+       newdocp = php_xsl_apply_stylesheet(intern, sheetp, docp TSRMLS_CC);
 
        if (newdocp) {
                DOM_RET_OBJ(rv, (xmlNodePtr) newdocp, &ret, NULL);
@@ -506,9 +514,7 @@
 PHP_FUNCTION(xsl_xsltprocessor_transform_to_uri)
 {
        zval *id, *docp = NULL;
-       xmlDoc *doc = NULL;
        xmlDoc *newdocp;
-       xmlNodePtr node = NULL;
        xsltStylesheetPtr sheetp;
        int ret, uri_len;
        char *uri;
@@ -522,17 +528,7 @@
                RETURN_FALSE;
        }
 
-       node = php_libxml_import_node(docp TSRMLS_CC);
-       
-       if (node) {
-               doc = node->doc;
-       }
-       if (doc == NULL) {
-               php_error(E_WARNING, "Invalid Document");
-               RETURN_NULL();
-       }
-
-       newdocp = php_xsl_apply_stylesheet(intern, sheetp, doc TSRMLS_CC);
+       newdocp = php_xsl_apply_stylesheet(intern, sheetp, docp TSRMLS_CC);
 
        ret = -1;
        if (newdocp) {
@@ -550,9 +546,7 @@
 PHP_FUNCTION(xsl_xsltprocessor_transform_to_xml)
 {
        zval *id, *docp = NULL;
-       xmlDoc *doc = NULL;
        xmlDoc *newdocp;
-       xmlNodePtr node = NULL;
        xsltStylesheetPtr sheetp;
        int ret;
        xmlChar *doc_txt_ptr;
@@ -567,17 +561,7 @@
                RETURN_FALSE;
        }
 
-       node = php_libxml_import_node(docp TSRMLS_CC);
-       
-       if (node) {
-               doc = node->doc;
-       }
-       if (doc == NULL) {
-               php_error(E_WARNING, "Invalid Document");
-               RETURN_NULL();
-       }
-
-       newdocp = php_xsl_apply_stylesheet(intern, sheetp, doc TSRMLS_CC);
+       newdocp = php_xsl_apply_stylesheet(intern, sheetp, docp TSRMLS_CC);
 
        ret = -1;
        if (newdocp) {
http://cvs.php.net/diff.php/php-src/ext/xsl/php_xsl.h?r1=1.12&r2=1.13&ty=u
Index: php-src/ext/xsl/php_xsl.h
diff -u php-src/ext/xsl/php_xsl.h:1.12 php-src/ext/xsl/php_xsl.h:1.13
--- php-src/ext/xsl/php_xsl.h:1.12      Wed Sep  8 12:54:17 2004
+++ php-src/ext/xsl/php_xsl.h   Wed Mar  2 13:27:25 2005
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: php_xsl.h,v 1.12 2004/09/08 16:54:17 rrichards Exp $ */
+/* $Id: php_xsl.h,v 1.13 2005/03/02 18:27:25 rrichards Exp $ */
 
 #ifndef PHP_XSL_H
 #define PHP_XSL_H
@@ -58,6 +58,7 @@
        int hasKeys;
        int registerPhpFunctions;
        HashTable *node_list;
+       php_libxml_node_object *doc;
 } xsl_object;
 
 void php_xsl_set_object(zval *wrapper, void *obj TSRMLS_DC);
http://cvs.php.net/diff.php/php-src/ext/xsl/php_xsl.c?r1=1.27&r2=1.28&ty=u
Index: php-src/ext/xsl/php_xsl.c
diff -u php-src/ext/xsl/php_xsl.c:1.27 php-src/ext/xsl/php_xsl.c:1.28
--- php-src/ext/xsl/php_xsl.c:1.27      Wed Sep  8 12:54:17 2004
+++ php-src/ext/xsl/php_xsl.c   Wed Mar  2 13:27:25 2005
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: php_xsl.c,v 1.27 2004/09/08 16:54:17 rrichards Exp $ */
+/* $Id: php_xsl.c,v 1.28 2005/03/02 18:27:25 rrichards Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -83,6 +83,11 @@
                FREE_HASHTABLE(intern->node_list);
        }
 
+       if (intern->doc) {
+               php_libxml_decrement_doc_ref(intern->doc TSRMLS_CC);
+               efree(intern->doc);
+       }
+
        if (intern->ptr) {
                /* free wrapper */
                if (((xsltStylesheetPtr) intern->ptr)->_private != NULL) {
@@ -112,6 +117,7 @@
        intern->hasKeys = 0;
        intern->registerPhpFunctions = 0;
        intern->node_list = NULL;
+       intern->doc = NULL;
 
        ALLOC_HASHTABLE(intern->std.properties);
        zend_hash_init(intern->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0);

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

Reply via email to