Skip to content

Commit 1b379f5

Browse files
committed
ext/hash: Fix phpGH-16711: Segfault in mhash()
Closes phpGH-16713
1 parent fc8f30d commit 1b379f5

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ PHP NEWS
1111
- FPM:
1212
. Fixed GH-16432 (PHP-FPM 8.2 SIGSEGV in fpm_get_status). (Jakub Zelenka)
1313

14+
- Hash:
15+
. Fixed GH-16711: Segfault in mhash(). (Girgias)
16+
1417
- OpenSSL:
1518
. Prevent unexpected array entry conversion when reading key. (nielsdos)
1619
. Fix various memory leaks related to openssl exports. (nielsdos)

ext/hash/hash.c

+4
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,11 @@ PHP_FUNCTION(mhash)
12131213
struct mhash_bc_entry algorithm_lookup = mhash_to_hash[algorithm];
12141214
if (algorithm_lookup.hash_name) {
12151215
algo = zend_string_init(algorithm_lookup.hash_name, strlen(algorithm_lookup.hash_name), 0);
1216+
} else {
1217+
RETURN_FALSE;
12161218
}
1219+
} else {
1220+
RETURN_FALSE;
12171221
}
12181222

12191223
if (key) {

ext/hash/tests/gh16711_1.phpt

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
GH-16711: Segmentation fault in mhash()
33
--SKIPIF--
44
<?php if(!function_exists('mhash')) { die('skip mhash compatibility layer not available'); } ?>
5-
--XFAIL--
6-
SEGFAULT
75
--FILE--
86
<?php
97

@@ -97,4 +95,4 @@ array(40) {
9795
}
9896

9997
Deprecated: Function mhash() is deprecated in %s on line %d
100-
SEGFAULT
98+
bool(false)

ext/hash/tests/gh16711_2.phpt

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
GH-16711: Segmentation fault in mhash()
33
--SKIPIF--
44
<?php if(!function_exists('mhash')) { die('skip mhash compatibility layer not available'); } ?>
5-
--XFAIL--
6-
SEGFAULT
75
--FILE--
86
<?php
97

@@ -97,4 +95,4 @@ array(40) {
9795
}
9896

9997
Deprecated: Function mhash() is deprecated in %s on line %d
100-
SEGFAULT
98+
bool(false)

0 commit comments

Comments
 (0)