From: Greg Beaver Date: Mon, 12 May 2008 00:16:59 +0000 (+0000) Subject: increase code coverage to test mounting of phar URLs to internal file, and fix odd... X-Git-Tag: RELEASE_2_0_0b1~20 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e6558c56a335e0e2daea179fcf2fc94e72e7accd;p=php increase code coverage to test mounting of phar URLs to internal file, and fix odd semi-race condition where stream resources were not properly freed at script end --- diff --git a/ext/phar/phar.c b/ext/phar/phar.c index 16b5288f47..560a9f333b 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -196,6 +196,24 @@ static int phar_unalias_apply(void *pDest, void *argument TSRMLS_DC) /* {{{ */ } /* }}} */ +/** + * Delete aliases to phar's that got kicked out of the global table + */ +static int phar_tmpclose_apply(void *pDest TSRMLS_DC) /* {{{ */ +{ + phar_entry_info *entry = (phar_entry_info *) pDest; + + if (entry->fp_type != PHAR_TMP) { + return ZEND_HASH_APPLY_KEEP; + } + if (entry->fp && !entry->fp_refcount) { + php_stream_close(entry->fp); + entry->fp = NULL; + } + return ZEND_HASH_APPLY_KEEP; +} +/* }}} */ + /** * Filename map destructor */ @@ -205,6 +223,9 @@ static void destroy_phar_data(void *pDest) /* {{{ */ TSRMLS_FETCH(); if (PHAR_GLOBALS->request_ends) { + /* first, iterate over the manifest and close all PHAR_TMP entry fp handles, + this prevents unnecessary unfreed stream resources */ + zend_hash_apply(&(phar_data->manifest), phar_tmpclose_apply TSRMLS_CC); destroy_phar_data_only(pDest); return; } diff --git a/ext/phar/tests/phar_mount.phpt b/ext/phar/tests/phar_mount.phpt index 4578b3a33d..80f8cda389 100644 --- a/ext/phar/tests/phar_mount.phpt +++ b/ext/phar/tests/phar_mount.phpt @@ -41,6 +41,13 @@ include $fname2; } catch (Exception $e) { echo $e->getMessage(),"\n"; } +try { +Phar::mount($pname . '/oops', '/home/oops/../../etc/passwd:'); +} catch (Exception $e) { +echo $e->getMessage(),"\n"; +} +Phar::mount($pname . '/testit2', $pname . '/testit1'); +echo substr($a['testit2']->getContent(),0, 50),"\n"; ?> ===DONE=== --CLEAN-- @@ -50,4 +57,7 @@ echo $e->getMessage(),"\n"; Mounting of testit to %sphar_mount.php within phar %sphar_mount.phar.php failed Can only mount internal paths within a phar archive, use a relative path instead of "phar://%sphar_mount.phar.php/testit1" Mounting of testit to %sphar_mount.php within phar %sphar_mount.phar.tar failed +Mounting of /oops to /home/oops/../../etc/passwd: within phar %sphar_mount.phar.php failed +