]> granicus.if.org Git - php/commitdiff
Prevent double-free of Phar ZIP stream
authorChristoph M. Becker <cmbecker69@gmx.de>
Tue, 5 Jan 2021 11:52:00 +0000 (12:52 +0100)
committerChristoph M. Becker <cmbecker69@gmx.de>
Tue, 5 Jan 2021 13:31:43 +0000 (14:31 +0100)
We must not alias the closed stream to `phar_archive_data.fp`, and use
PHAR_ZIP_FAIL() for consistency with the rest of this function.

Closes GH-6578.

ext/phar/tests/zip/require_hash.phpt
ext/phar/zip.c

index 23943550ae33b57ee6901c1555b83d8089238cbf..994cc0eb676a4372f59ecd5ebc6fd59a98117c9a 100644 (file)
@@ -45,7 +45,7 @@ try {
 @unlink(__DIR__ . '/require_hash.zip');\r
 ?>\r
 --EXPECTF--\r
-zip-based phar "%srequire_hash.phar.zip" does not have a signature\r
+phar error: signature is missing in zip-based phar "%srequire_hash.phar.zip"\r
 bool(false)\r
 array(2) {\r
   ["hash"]=>\r
index 1b94943ad302e0611f6d98567e91dc2beb2e5118..f3aef85cd9a43129d2274bed39b2a5d877091bd6 100644 (file)
@@ -665,8 +665,6 @@ foundit:
                zend_hash_str_add_mem(&mydata->manifest, entry.filename, entry.filename_len, (void *)&entry, sizeof(phar_entry_info));
        }
 
-       mydata->fp = fp;
-
        if (zend_hash_str_exists(&(mydata->manifest), ".phar/stub.php", sizeof(".phar/stub.php")-1)) {
                mydata->is_data = 0;
        } else {
@@ -675,14 +673,11 @@ foundit:
 
        /* ensure signature set */
        if (!mydata->is_data && PHAR_G(require_hash) && !mydata->signature) {
-               php_stream_close(fp);
-               phar_destroy_phar_data(mydata);
-               if (error) {
-                       spprintf(error, 0, "zip-based phar \"%s\" does not have a signature", fname);
-               }
-               return FAILURE;
+               PHAR_ZIP_FAIL("signature is missing");
        }
 
+       mydata->fp = fp;
+
        zend_hash_str_add_ptr(&(PHAR_G(phar_fname_map)), mydata->fname, fname_len, mydata);
 
        if (actual_alias) {