Skip to content

Commit f5d2a30

Browse files
committed
Validate subject encoding in mb_split and mb_ereg_match
We were already validating the subject encoding in most functions, but not these two.
1 parent 2e59426 commit f5d2a30

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

ext/mbstring/php_mbregex.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,11 @@ PHP_FUNCTION(mb_split)
12591259
count--;
12601260
}
12611261

1262+
if (!php_mb_check_encoding(string, string_len,
1263+
_php_mb_regex_mbctype2name(MBREX(current_mbctype)))) {
1264+
RETURN_FALSE;
1265+
}
1266+
12621267
/* create regex pattern buffer */
12631268
if ((re = php_mbregex_compile_pattern(arg_pattern, arg_pattern_len, MBREX(regex_default_options), MBREX(current_mbctype), MBREX(regex_default_syntax))) == NULL) {
12641269
RETURN_FALSE;
@@ -1348,6 +1353,11 @@ PHP_FUNCTION(mb_ereg_match)
13481353
}
13491354
}
13501355

1356+
if (!php_mb_check_encoding(string, string_len,
1357+
_php_mb_regex_mbctype2name(MBREX(current_mbctype)))) {
1358+
RETURN_FALSE;
1359+
}
1360+
13511361
if ((re = php_mbregex_compile_pattern(arg_pattern, arg_pattern_len, option, MBREX(current_mbctype), syntax)) == NULL) {
13521362
RETURN_FALSE;
13531363
}

ext/mbstring/tests/bug77367.phpt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,5 @@ if (!function_exists('mb_split')) die('mb_split() not available');
1010
mb_regex_encoding('UTF-8');
1111
var_dump(mb_split("\\w", "\xfc"));
1212
?>
13-
===DONE===
1413
--EXPECT--
15-
array(2) {
16-
[0]=>
17-
string(0) ""
18-
[1]=>
19-
string(0) ""
20-
}
21-
===DONE===
14+
bool(false)

ext/mbstring/tests/bug77418.phpt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Bug #77371 (Heap overflow in utf32be_mbc_to_code)
2+
Bug #77418 (Heap overflow in utf32be_mbc_to_code)
33
--SKIPIF--
44
<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
55
--FILE--
@@ -8,7 +8,4 @@ mb_regex_encoding("UTF-32");
88
var_dump(mb_split("\x00\x00\x00\x5c\x00\x00\x00B","000000000000000000000000000000"));
99
?>
1010
--EXPECT--
11-
array(1) {
12-
[0]=>
13-
string(30) "000000000000000000000000000000"
14-
}
11+
bool(false)

0 commit comments

Comments
 (0)