Re: Patch incl: Sablotron compile problems/segfaults

From: Date: Fri, 24 Nov 2000 07:16:56 +0000
Subject: Re: Patch incl: Sablotron compile problems/segfaults
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-39078@lists.php.net to get a copy of this message
At 04:14 PM 11/23/2000 -0800, Lars Torben Wilson wrote:
The output buffering patch Andi committed a few hours ago means that the Sablot ext needs a tiny patch to supply the chunk_size parameter. Also, xslt_transform() now segfaults when either of xslt_params or xslt_args are given and 0. Both problems are fixed by the patch below. I'm pretty sure Sterling has a reason for testing IS_LONG, 0, and IS_NULL as special cases, but I missed the point and so the below patch just tests for IS_ARRAY. Seems like neither param would have much use if they aren't arrays anyway. :)
No, just bad logic ;-). Actually I just want to test the results of ar, if its not an array, ar will be NULL (which is what causes the nice ol' segfault). I just dealt with this the other day, I'll be committing the new logic soon, that is, unless you think that testing for IS_ARRAY is a better option.... If you don't object I'll commit your output buffering patch along with the modified segfault portion of the patch. I wish whenever someone changes the semantics of PHP's internal functions they would change all affected parts of PHP too. :) -Sterling
Index: sablot.c =================================================================== RCS file: /repository/php4/ext/sablot/sablot.c,v retrieving revision 1.16 diff -u -r1.16 sablot.c
--- sablot.c    2000/11/23 14:02:41     1.16
+++ sablot.c    2000/11/24 00:00:34
@@ -225,7 +225,7 @@
      * Start output buffering, NULL signifies that no "user-space" output function
      * will be used.
      */
-       php_start_ob_buffer(NULL);
+       php_start_ob_buffer(NULL, 0);
} /* }}} */ @@ -342,30 +342,27 @@
        * the third argument and decide whether or not there are Sablotron
        * parameters.
        */
-       if (argc > 3) {
-               if (Z_TYPE_PP(xslt_params) != IS_LONG || Z_LVAL_PP(xslt_params) != 0 ||
-                   Z_TYPE_PP(xslt_params) != IS_NULL) {
-                       int numelems,
-                           size;
-                       HashTable *ar = HASH_OF(*xslt_params);
-
-            /**
-             * Allocate 2 times the number of elements in
-             * the array, since with associative arrays in PHP
-             * keys are not counted.
-             */
-                       numelems = zend_hash_num_elements(ar);
-                       size = (numelems * 2 + 1) * sizeof(char *);
-
-                       params = (char **)emalloc(size+1);
-                       memset((char *)params, 0, size);
-
-                       /**
-                       * Translate a PHP array (HashTable *) into a
-                       * Sablotron array (char **).
-                       */
-                       _php_sablot_ht_char(ar, params);
-               }
+       if (argc > 3 && Z_TYPE_PP(xslt_params) == IS_ARRAY) {
+               int numelems,
+                       size;
+               HashTable *ar = HASH_OF(*xslt_params);
+
+               /**
+               * Allocate 2 times the number of elements in
+               * the array, since with associative arrays in PHP
+               * keys are not counted.
+               */
+               numelems = zend_hash_num_elements(ar);
+               size = (numelems * 2 + 1) * sizeof(char *);
+
+               params = (char **)emalloc(size+1);
+               memset((char *)params, 0, size);
+
+               /**
+               * Translate a PHP array (HashTable *) into a
+               * Sablotron array (char **).
+               */
+               _php_sablot_ht_char(ar, params);
        }
        /**
@@ -373,21 +370,18 @@
        * of the 4 argument and decide whether or not there are Sablotron
        * arguments.
        */
-       if (argc > 4) {
-               if (Z_TYPE_PP(xslt_args) != IS_LONG || Z_LVAL_PP(xslt_args) != 0 ||
-                   Z_TYPE_PP(xslt_args) != IS_NULL) {
-                       int numelems,
-                           size;
-                       HashTable *ar = HASH_OF(*xslt_args);
-
-                       numelems = zend_hash_num_elements(ar);
-                       size = (numelems * 2 + 1) * sizeof(char *);
-
-                       args = (char **)emalloc(size+1);
-                       memset((char *)args, 0, size);
-
-                       _php_sablot_ht_char(ar, args);
-               }
+       if (argc > 4 && Z_TYPE_PP(xslt_args) == IS_ARRAY) {
+               int numelems,
+                       size;
+               HashTable *ar = HASH_OF(*xslt_args);
+
+               numelems = zend_hash_num_elements(ar);
+               size = (numelems * 2 + 1) * sizeof(char *);
+
+               args = (char **)emalloc(size+1);
+               memset((char *)args, 0, size);
+
+               _php_sablot_ht_char(ar, args);
        }
        SABLOT_BASIC_CREATE_PROCESSOR();
-- +----------------------------------------------------------------+
|Torben Wilson <torben@php.net>                     Netmill iTech|
|http://www.coastnet.com/~torben            http://www.netmill.fi|
|Ph: 1 250 383-9735                             torben@netmill.fi|
+----------------------------------------------------------------+


« previous php.dev (#39078) next »