Skip to content

Commit 4154618

Browse files
vi3tL0u1sericmann
authored andcommitted
GHSA-wm6j-2649-pv75: [mbstring] Fix null pointer dereference in php_mb_check_encoding() via mb_ereg_search_init()
Fixes GHSA-wm6j-2649-pv75 Fixes CVE-2026-7259
1 parent 560a5ec commit 4154618

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
GHSA-wm6j-2649-pv75: Null pointer dereference in php_mb_check_encoding() via mb_ereg_search_init()
3+
--CREDITS--
4+
vi3tL0u1s
5+
--EXTENSIONS--
6+
mbstring
7+
--SKIPIF--
8+
<?php
9+
if (!function_exists('mb_regex_encoding')) die('skip No mbregex support');
10+
?>
11+
--FILE--
12+
<?php
13+
// iso-8859-11 is supported by Oniguruma but not by mbfl
14+
mb_regex_encoding('iso-8859-11');
15+
mb_ereg_search_init('x');
16+
?>
17+
--EXPECTF--
18+
Fatal error: Uncaught ValueError: mb_regex_encoding(): Argument #1 ($encoding) must be a valid encoding, "iso-8859-11" given in %s:%d
19+
Stack trace:
20+
#0 %s(%d): mb_regex_encoding('iso-8859-11')
21+
#1 {main}
22+
thrown in %s on line %d

ext/mbstring/php_mbregex.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,13 @@ int php_mb_regex_set_mbctype(const char *encname)
409409
if (mbctype == ONIG_ENCODING_UNDEF) {
410410
return FAILURE;
411411
}
412+
const mbfl_encoding *mbfl_enc = mbfl_name2encoding(encname);
413+
if (mbfl_enc == NULL) {
414+
/* Encoding supported by Oniguruma but not by mbfl */
415+
return FAILURE;
416+
}
412417
MBREX(current_mbctype) = mbctype;
413-
MBREX(current_mbctype_mbfl_encoding) = mbfl_name2encoding(encname);
418+
MBREX(current_mbctype_mbfl_encoding) = mbfl_enc;
414419
return SUCCESS;
415420
}
416421
/* }}} */

0 commit comments

Comments
 (0)