Fix gh-issue #7
authorMichael Wallner <mike@php.net>
Wed, 22 Jul 2015 05:18:21 +0000 (07:18 +0200)
committerMichael Wallner <mike@php.net>
Wed, 22 Jul 2015 05:18:21 +0000 (07:18 +0200)
Fix crash on returning from a sub-call to querystring from env_request
after an exception.

Closes gh-issue #7

package.xml
php_http_env_request.c
tests/gh-issue7.phpt [new file with mode: 0644]

index 922589a..eecfe7e 100644 (file)
@@ -49,6 +49,7 @@ http://dev.iworks.at/ext-http/lcov/ext/http/
 * Fixed VC11 build (Jan Erhardt)
 * Fixed gh-issue #2: comparison of obsolete pointers in the header parser (xiaoyjy)
 * Fixed gh-issue #6: allow RFC1738 unsafe characters in query/fragment
+* Fixed gh-issue #7: crash with querystring and exception from error handler
 + SSL certinfo is available for libcurl >= 7.42 with gnutls (openssl has already been since 7.19.1)
 + Added "falsestart" SSL request option (available with libcurl >= 7.42 and darwinssl/NSS)
 + Added "service_name" and "proxy_service_name" request options for SPNEGO (available with libcurl >= 7.43)
@@ -248,6 +249,7 @@ http://dev.iworks.at/ext-http/lcov/ext/http/
      <file role="test" name="filterchunked.phpt"/>
      <file role="test" name="filterzlib.phpt"/>
      <file role="test" name="gh-issue6.phpt"/>
+     <file role="test" name="gh-issue7.phpt"/>
      <file role="test" name="header001.phpt"/>
      <file role="test" name="header002.phpt"/>
      <file role="test" name="header003.phpt"/>
index ac0a5e4..a884d2f 100644 (file)
@@ -172,7 +172,7 @@ static PHP_METHOD(HttpEnvRequest, __construct)
        do {\
                zend_fcall_info fci; \
                zend_fcall_info_cache fcc; \
-               zval *rv, mn, ***args = ecalloc(sizeof(zval **), ZEND_NUM_ARGS()); \
+               zval *rv = NULL, mn, ***args = ecalloc(sizeof(zval **), ZEND_NUM_ARGS()); \
                zval *qs = zend_read_property(Z_OBJCE_P(getThis()), getThis(), ZEND_STRL(prop), 0 TSRMLS_CC); \
                 \
                INIT_PZVAL(&mn); \
@@ -187,7 +187,9 @@ static PHP_METHOD(HttpEnvRequest, __construct)
                zend_fcall_info_args_clear(&fci, 1); \
                efree(args); \
                zval_dtor(&mn); \
-               RETVAL_ZVAL(rv, 0, 1); \
+               if (rv) { \
+                       RETVAL_ZVAL(rv, 0, 1); \
+               } \
        } while(0);
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvRequest_getForm, 0, 0, 0)
diff --git a/tests/gh-issue7.phpt b/tests/gh-issue7.phpt
new file mode 100644 (file)
index 0000000..38e597c
--- /dev/null
@@ -0,0 +1,32 @@
+--TEST--
+crash with querystring and exception from error handler
+--SKIPIF--
+<?php include "skipif.inc"; ?>
+--GET--
+q[]=1&r[]=2
+--FILE--
+<?php 
+echo "Test\n";
+
+set_error_handler(function($c,$e) { throw new Exception($e); });
+
+try {
+       $q = http\QueryString::getGlobalInstance();
+       var_dump($q->get("q","s"));
+} catch (\Exception $e) {
+       echo $e->getMessage(),"\n";
+}
+try {
+       $r = new http\Env\Request;
+       var_dump($r->getQuery("r", "s"));
+} catch (\Exception $e) {
+       echo $e->getMessage(),"\n";
+}
+
+?>
+===DONE===
+--EXPECT--
+Test
+Array to string conversion
+Array to string conversion
+===DONE===