Skip to content

Commit f57a999

Browse files
committed
Fix #79797: Use of freed hash key in the phar_parse_zipfile function
We must not use heap memory after we freed it. (cherry picked from commit 7355ab8)
1 parent 82949e5 commit f57a999

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ PHP NEWS
3030
- Mbstring:
3131
. Fixed bug #79787 (mb_strimwidth does not trim string). (XXiang)
3232

33+
- Phar:
34+
. Fixed bug #79797 (Use of freed hash key in the phar_parse_zipfile
35+
function). (CVE-2020-7068) (cmb)
36+
3337
- Standard:
3438
. Fixed bug #70362 (Can't copy() large 'data://' with open_basedir). (cmb)
3539
. Fixed bug #79817 (str_replace() does not handle INDIRECT elements). (Nikita)

ext/phar/tests/bug79797.phar

274 Bytes
Binary file not shown.

ext/phar/tests/bug79797.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Bug #79797 (Use of freed hash key in the phar_parse_zipfile function)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('phar')) die('skip phar extension not available');
6+
?>
7+
--INI--
8+
phar.cache_list={PWD}/bug79797.phar
9+
--FILE--
10+
<?php
11+
echo "done\n";
12+
?>
13+
--EXPECT--
14+
done

ext/phar/zip.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ int phar_parse_zipfile(php_stream *fp, char *fname, size_t fname_len, char *alia
705705
efree(actual_alias);
706706
}
707707

708-
zend_hash_str_add_ptr(&(PHAR_G(phar_alias_map)), actual_alias, mydata->alias_len, mydata);
708+
zend_hash_str_add_ptr(&(PHAR_G(phar_alias_map)), mydata->alias, mydata->alias_len, mydata);
709709
} else {
710710
phar_archive_data *fd_ptr;
711711

0 commit comments

Comments
 (0)