Skip to content

Commit 395863b

Browse files
committed
Fixed bug #72164 (Null Pointer Dereference - mb_ereg_replace)
1 parent c15b613 commit 395863b

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ PHP NEWS
2727
. Fixed bug #72069 (Behavior \JsonSerializable different from json_encode).
2828
(Laruence)
2929

30+
- Mbstring:
31+
. Fixed bug #72164 (Null Pointer Dereference - mb_ereg_replace). (Laruence)
32+
3033
- OCI8:
3134
. Fixed bug #71600 (oci_fetch_all segfaults when selecting more than eight
3235
columns). (Tian Yang)

ext/mbstring/php_mbregex.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -935,20 +935,28 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
935935

936936
if (eval) {
937937
zval v;
938+
zend_string *eval_str;
938939
/* null terminate buffer */
939940
smart_str_0(&eval_buf);
941+
942+
if (eval_buf.s) {
943+
eval_str = eval_buf.s;
944+
} else {
945+
eval_str = ZSTR_EMPTY_ALLOC();
946+
}
947+
940948
/* do eval */
941-
if (zend_eval_stringl(ZSTR_VAL(eval_buf.s), ZSTR_LEN(eval_buf.s), &v, description) == FAILURE) {
949+
if (zend_eval_stringl(ZSTR_VAL(eval_str), ZSTR_LEN(eval_str), &v, description) == FAILURE) {
942950
efree(description);
943-
php_error_docref(NULL,E_ERROR, "Failed evaluating code: %s%s", PHP_EOL, ZSTR_VAL(eval_buf.s));
951+
php_error_docref(NULL,E_ERROR, "Failed evaluating code: %s%s", PHP_EOL, ZSTR_VAL(eval_str));
944952
/* zend_error() does not return in this case */
945953
}
946954

947955
/* result of eval */
948956
convert_to_string(&v);
949957
smart_str_appendl(&out_buf, Z_STRVAL(v), Z_STRLEN(v));
950958
/* Clean up */
951-
ZSTR_LEN(eval_buf.s) = 0;
959+
smart_str_free(&eval_buf);
952960
zval_dtor(&v);
953961
} else if (is_callable) {
954962
zval args[1];
@@ -971,9 +979,7 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
971979
!Z_ISUNDEF(retval)) {
972980
convert_to_string_ex(&retval);
973981
smart_str_appendl(&out_buf, Z_STRVAL(retval), Z_STRLEN(retval));
974-
if (eval_buf.s) {
975-
ZSTR_LEN(eval_buf.s) = 0;
976-
}
982+
smart_str_free(&eval_buf);
977983
zval_ptr_dtor(&retval);
978984
} else {
979985
efree(description);

ext/mbstring/tests/bug72164.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Bug #72164 (Null Pointer Dereference - mb_ereg_replace)
3+
--SKIPIF--
4+
<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
5+
--FILE--
6+
<?php
7+
$var0 = "e";
8+
$var2 = "";
9+
$var3 = NULL;
10+
$var8 = mbereg_replace($var2,$var3,$var3,$var0);
11+
var_dump($var8);
12+
?>
13+
--EXPECT--
14+
string(0) ""

0 commit comments

Comments
 (0)