]> granicus.if.org Git - php/commitdiff
new test, free resources on error in webPhar() (thanks new test\!)
authorGreg Beaver <cellog@php.net>
Sat, 5 Jan 2008 05:47:47 +0000 (05:47 +0000)
committerGreg Beaver <cellog@php.net>
Sat, 5 Jan 2008 05:47:47 +0000 (05:47 +0000)
ext/phar/phar_object.c
ext/phar/tests/frontcontroller11.phpt [new file with mode: 0644]
ext/phar/tests/frontcontroller5.phar [new file with mode: 0644]
ext/phar/tests/frontcontroller5.phar.inc [new file with mode: 0644]

index 4532e6a1d53bcb390434f95b1631620ea0ba8321..0849559a9b7cf39a152efe035b3f1a0d6521b786 100755 (executable)
@@ -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 (file)
index 0000000..5160d71
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--
+Phar front controller rewrite array invalid
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--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 (file)
index 0000000..f206b59
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 (file)
index 0000000..d2d810c
--- /dev/null
@@ -0,0 +1,12 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller5.phar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller5.phar');
+$a['a.php'] = 'hio';
+$a['a.jpg'] = 'hio';
+$a['a.phps'] = '<?php function hio(){}';
+$a->setStub('<?php
+Phar::webPhar("whatever", "index.php", null, array(0 => "oops"));
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>