From e8085939d62dc861d4d5a1690fa3b0699a9d69eb Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Tue, 4 Aug 2020 09:25:12 +0200 Subject: Core: Fix #79877 getimagesize function silently truncates after a null byte Phar: Fix #79797 use of freed hash key in the phar_parse_zipfile function CVE-2020-7068 --- php-bug79797.patch | 48 ++++++++++++++++++++++++++++++++++++++++++ php-bug79877.patch | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ php71.spec | 13 +++++++++++- 3 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 php-bug79797.patch create mode 100644 php-bug79877.patch diff --git a/php-bug79797.patch b/php-bug79797.patch new file mode 100644 index 0000000..9c964ca --- /dev/null +++ b/php-bug79797.patch @@ -0,0 +1,48 @@ +From bdf9d2ee3a565fef3160690d7a0dd06218e6efc0 Mon Sep 17 00:00:00 2001 +From: "Christoph M. Becker" +Date: Tue, 14 Jul 2020 17:04:24 +0200 +Subject: [PATCH] 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 7355ab81763a3d6a04ac11660e6a16d58838d187) +--- + NEWS | 6 ++++++ + ext/phar/tests/bug79797.phar | Bin 0 -> 274 bytes + ext/phar/tests/bug79797.phpt | 14 ++++++++++++++ + ext/phar/zip.c | 2 +- + 4 files changed, 21 insertions(+), 1 deletion(-) + create mode 100644 ext/phar/tests/bug79797.phar + create mode 100644 ext/phar/tests/bug79797.phpt + +diff --git a/NEWS b/NEWS +index 19fbb3adf2..69361ae49a 100644 +--- a/NEWS ++++ b/NEWS +@@ -1,6 +1,12 @@ + PHP NEWS + ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| + ++Backported from 7.2.33 ++ ++- Phar: ++ . Fixed bug #79797 (Use of freed hash key in the phar_parse_zipfile ++ function). (CVE-2020-7068) (cmb) ++ + Backported from 7.2.31 + + - Core: +diff --git a/ext/phar/zip.c b/ext/phar/zip.c +index d615e8adda..50c5d69e9b 100644 +--- a/ext/phar/zip.c ++++ b/ext/phar/zip.c +@@ -703,7 +703,7 @@ int phar_parse_zipfile(php_stream *fp, char *fname, int fname_len, char *alias, + efree(actual_alias); + } + +- zend_hash_str_add_ptr(&(PHAR_G(phar_alias_map)), actual_alias, mydata->alias_len, mydata); ++ zend_hash_str_add_ptr(&(PHAR_G(phar_alias_map)), mydata->alias, mydata->alias_len, mydata); + } else { + phar_archive_data *fd_ptr; + diff --git a/php-bug79877.patch b/php-bug79877.patch new file mode 100644 index 0000000..25738d7 --- /dev/null +++ b/php-bug79877.patch @@ -0,0 +1,62 @@ +From 2c27d6bdd38bd8c4a27da5aded3477457e72c639 Mon Sep 17 00:00:00 2001 +From: "Christoph M. Becker" +Date: Tue, 21 Jul 2020 11:07:43 +0200 +Subject: [PATCH] Fix #79877: getimagesize function silently truncates after a + null byte + +We have to check for NUL bytes if `getimagesize()` has been called. + +(cherry picked from commit ff577b04c0d250473a0ef46f8e332960fec3ca2c) +--- + NEWS | 4 ++++ + ext/standard/image.c | 5 +++++ + ext/standard/tests/image/bug79877.phpt | 9 +++++++++ + 3 files changed, 18 insertions(+) + create mode 100644 ext/standard/tests/image/bug79877.phpt + +diff --git a/NEWS b/NEWS +index 69361ae49a..2c340eb648 100644 +--- a/NEWS ++++ b/NEWS +@@ -3,6 +3,10 @@ PHP NEWS + + Backported from 7.2.33 + ++- Core: ++ . Fixed bug #79877 (getimagesize function silently truncates after a null ++ byte) (cmb) ++ + - Phar: + . Fixed bug #79797 (Use of freed hash key in the phar_parse_zipfile + function). (CVE-2020-7068) (cmb) +diff --git a/ext/standard/image.c b/ext/standard/image.c +index 1d999ca1b9..a5a86c2b52 100644 +--- a/ext/standard/image.c ++++ b/ext/standard/image.c +@@ -1474,6 +1474,11 @@ static void php_getimagesize_from_any(INTERNAL_FUNCTION_PARAMETERS, int mode) { + return; + } + ++ if (mode == FROM_PATH && CHECK_NULL_PATH(input, input_len)) { ++ php_error_docref(NULL, E_WARNING, "Invalid path"); ++ return; ++ } ++ + if (argc == 2) { + zval_dtor(info); + array_init(info); +diff --git a/ext/standard/tests/image/bug79877.phpt b/ext/standard/tests/image/bug79877.phpt +new file mode 100644 +index 0000000000..92e93e59e5 +--- /dev/null ++++ b/ext/standard/tests/image/bug79877.phpt +@@ -0,0 +1,9 @@ ++--TEST-- ++Bug #79877 (getimagesize function silently truncates after a null byte) ++--FILE-- ++ ++--EXPECTF-- ++Warning: getimagesize(): Invalid path in %s on line %d ++NULL diff --git a/php71.spec b/php71.spec index 063b31b..b8375d8 100644 --- a/php71.spec +++ b/php71.spec @@ -118,7 +118,7 @@ Summary: PHP scripting language for creating dynamic web sites Name: php Version: %{upver}%{?rcver:~%{rcver}} -Release: 8%{?dist} +Release: 9%{?dist} # All files licensed under PHP version 3.01, except # Zend is licensed under Zend # TSRM is licensed under BSD @@ -195,6 +195,8 @@ Patch214: php-bug79330.patch Patch215: php-bug79465.patch Patch216: php-bug78875.patch Patch217: php-bug78876.patch +Patch218: php-bug79797.patch +Patch219: php-bug79877.patch # Fixes for tests (300+) # Factory is droped from system tzdata @@ -1068,6 +1070,8 @@ support for JavaScript Object Notation (JSON) to PHP. %patch215 -p1 -b .bug79465 %patch216 -p1 -b .bug78875 %patch217 -p1 -b .bug78876 +%patch218 -p1 -b .bug79797 +%patch219 -p1 -b .bug79877 # Fixes for tests %if 0%{?fedora} >= 25 || 0%{?rhel} >= 6 @@ -2142,6 +2146,13 @@ EOF %changelog +* Tue Aug 4 2020 Remi Collet - 7.1.33-9 +- Core: + Fix #79877 getimagesize function silently truncates after a null byte +- Phar: + Fix #79797 use of freed hash key in the phar_parse_zipfile function + CVE-2020-7068 + * Tue May 12 2020 Remi Collet - 7.1.33-8 - Core: Fix #78875 Long filenames cause OOM and temp files are not cleaned -- cgit