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 922589af1ab4fe1e7cefd4ab96fbf63a6e1ba9a9..eecfe7ef24d08dbb7be13fe3e0e7ab78cf03968c 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 ac0a5e4d23ebe31400f180b4c36512b764736c72..a884d2ffe432d804c145cf2685757049a914fbea 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===