]> granicus.if.org Git - php/commitdiff
increase code coverage to test mounting of phar URLs to internal file, and fix odd...
authorGreg Beaver <cellog@php.net>
Mon, 12 May 2008 00:16:59 +0000 (00:16 +0000)
committerGreg Beaver <cellog@php.net>
Mon, 12 May 2008 00:16:59 +0000 (00:16 +0000)
where stream resources were not properly freed at script end

ext/phar/phar.c
ext/phar/tests/phar_mount.phpt

index 16b5288f475beafa8f5678bd76297bae0637b3ff..560a9f333b429b4fe3695f9b3e03607ab76f0fd2 100644 (file)
@@ -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;
        }
index 4578b3a33debe5c83a172f66b0f8fa9e5c5ef38f..80f8cda38943ef9e934379f2aa2a79577037239b 100644 (file)
@@ -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
+<?php
+$fname = dirname(__FILE__) . '/' . basename(
 ===DONE===
\ No newline at end of file