Skip to content

Commit b7259b7

Browse files
committed
Fix #72994: mbc_to_code() out of bounds read
We're backporting commit 999a355 to the still supported PHP 5.6.
1 parent d582241 commit b7259b7

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ PHP NEWS
66
. Fixed bug #67325 (imagetruecolortopalette: white is duplicated in palette).
77
(cmb)
88

9+
- Mbstring:
10+
. Fixed bug #72994 (mbc_to_code() out of bounds read). (Laruence, cmb)
11+
912
15 Sep 2016, PHP 5.6.26
1013

1114
- Core:

ext/mbstring/php_mbregex.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
811811
OnigUChar *pos;
812812
OnigUChar *string_lim;
813813
char *description = NULL;
814-
char pat_buf[2];
814+
char pat_buf[6];
815815

816816
const mbfl_encoding *enc;
817817

@@ -862,6 +862,10 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
862862
convert_to_long_ex(arg_pattern_zval);
863863
pat_buf[0] = (char)Z_LVAL_PP(arg_pattern_zval);
864864
pat_buf[1] = '\0';
865+
pat_buf[2] = '\0';
866+
pat_buf[3] = '\0';
867+
pat_buf[4] = '\0';
868+
pat_buf[5] = '\0';
865869

866870
arg_pattern = pat_buf;
867871
arg_pattern_len = 1;

ext/mbstring/tests/bug72994.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Bug #72994 (mbc_to_code() out of bounds read)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('mbstring')) die('skip mbstring extension not available');
6+
if (!function_exists('mbereg_replace')) die('skip mbereg_replace() not available');
7+
?>
8+
--FILE--
9+
<?php
10+
$var1 = mbereg_replace($var-232338951,NULL,NULL,NULL);
11+
var_dump($var1);
12+
?>
13+
===DONE===
14+
--EXPECTF--
15+
Notice: Undefined variable: var in %s on line %d
16+
string(0) ""
17+
===DONE===

0 commit comments

Comments
 (0)