From: Greg Beaver Date: Sat, 5 Jan 2008 05:47:47 +0000 (+0000) Subject: new test, free resources on error in webPhar() (thanks new test\!) X-Git-Tag: RELEASE_2_0_0a1~1020 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e864f512bb409c213219d5a54b9d52cec6ed3088;p=php new test, free resources on error in webPhar() (thanks new test\!) --- diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index 4532e6a1d5..0849559a9b 100755 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -476,6 +476,10 @@ PHP_METHOD(Phar, webPhar) /* check for "rewrite" urls */ if (SUCCESS == zend_hash_find(Z_ARRVAL_P(rewrites), entry, entry_len+1, (void **) &fd_ptr)) { if (IS_STRING != Z_TYPE_PP(fd_ptr)) { + phar_entry_delref(phar TSRMLS_CC); +#ifdef PHP_WIN32 + efree(fname); +#endif zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "phar rewrite value for \"%s\" was not a string", entry); return; } @@ -489,6 +493,7 @@ PHP_METHOD(Phar, webPhar) if (FAILURE == phar_get_entry_data(&phar, fname, fname_len, entry, entry_len, "r", &error TSRMLS_CC)) { phar_do_404(fname, fname_len, f404, f404_len, entry, entry_len TSRMLS_CC); + phar_entry_delref(phar TSRMLS_CC); #ifdef PHP_WIN32 efree(fname); #endif @@ -552,6 +557,7 @@ PHP_METHOD(Phar, webPhar) ulong intkey; if (HASH_KEY_IS_LONG == zend_hash_get_current_key_ex(Z_ARRVAL_P(mimeoverride), &key, &keylen, &intkey, 0, NULL)) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Key of MIME type overrides array must be a file extension, was \"%d\"", intkey); + phar_entry_delref(phar TSRMLS_CC); #ifdef PHP_WIN32 efree(fname); #endif @@ -559,6 +565,7 @@ PHP_METHOD(Phar, webPhar) } if (FAILURE == zend_hash_get_current_data(Z_ARRVAL_P(mimeoverride), (void **) &val)) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Failed to retrieve Mime type for extension \"%s\"", key); + phar_entry_delref(phar TSRMLS_CC); #ifdef PHP_WIN32 efree(fname); #endif @@ -570,6 +577,10 @@ PHP_METHOD(Phar, webPhar) PHAR_SET_USER_MIME(Z_LVAL_P(val)) } else { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Unknown mime type specifier used, only Phar::PHP, Phar::PHPS and a mime type string are allowed"); + phar_entry_delref(phar TSRMLS_CC); +#ifdef PHP_WIN32 + efree(fname); +#endif RETURN_FALSE; } break; @@ -578,6 +589,10 @@ PHP_METHOD(Phar, webPhar) break; default : zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Unknown mime type specifier used, only Phar::PHP, Phar::PHPS and a mime type string are allowed"); + phar_entry_delref(phar TSRMLS_CC); +#ifdef PHP_WIN32 + efree(fname); +#endif RETURN_FALSE; } } diff --git a/ext/phar/tests/frontcontroller11.phpt b/ext/phar/tests/frontcontroller11.phpt new file mode 100644 index 0000000000..5160d71273 --- /dev/null +++ b/ext/phar/tests/frontcontroller11.phpt @@ -0,0 +1,17 @@ +--TEST-- +Phar front controller rewrite array invalid +--SKIPIF-- + +--ENV-- +SCRIPT_NAME=/frontcontroller11.php/a.php +REQUEST_URI=/frontcontroller11.php/a.php +--FILE_EXTERNAL-- +frontcontroller5.phar +--EXPECTHEADERS-- +Content-type: text/html +--EXPECTF-- +Fatal error: Uncaught exception 'UnexpectedValueException' with message 'Key of MIME type overrides array must be a file extension, was "0"' in %sfrontcontroller11.php:2 +Stack trace: +#0 %sfrontcontroller11.php(2): Phar::webPhar('whatever', 'index.php', '', Array) +#1 {main} + thrown in %sfrontcontroller11.php on line 2 \ No newline at end of file diff --git a/ext/phar/tests/frontcontroller5.phar b/ext/phar/tests/frontcontroller5.phar new file mode 100644 index 0000000000..f206b5996d Binary files /dev/null and b/ext/phar/tests/frontcontroller5.phar differ diff --git a/ext/phar/tests/frontcontroller5.phar.inc b/ext/phar/tests/frontcontroller5.phar.inc new file mode 100644 index 0000000000..d2d810c367 --- /dev/null +++ b/ext/phar/tests/frontcontroller5.phar.inc @@ -0,0 +1,12 @@ +setStub(' "oops")); +echo "oops did not run\n"; +var_dump($_ENV, $_SERVER); +__HALT_COMPILER();'); +?>