Skip to content

Commit d013d94

Browse files
committed
Fix GH-9248: Segmentation fault in mb_strimwidth()
We need to initialize the optional argument `trimmarker` with its default value. Closes GH-9273.
1 parent 8fee9a3 commit d013d94

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-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 incorrect double to long casting in latest clang. (zeriyoshi)
77
. Added support for defining constants in traits. (sj-i)
88

9+
- MBString:
10+
. Fixed bug GH-9248 (Segmentation fault in mb_strimwidth()). (cmb)
11+
912
- Random:
1013
. Fixed bug GH-9235 (non-existant $sequence parameter in stub for
1114
PcgOneseq128XslRr64::__construct()). (timwolla)

ext/mbstring/mbstring.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2502,7 +2502,7 @@ static zend_string* mb_trim_string(zend_string *input, zend_string *marker, cons
25022502
/* Trim the string to terminal width; optional, add a 'trim marker' if it was truncated */
25032503
PHP_FUNCTION(mb_strimwidth)
25042504
{
2505-
zend_string *str, *trimmarker, *encoding = NULL;
2505+
zend_string *str, *trimmarker = zend_empty_string, *encoding = NULL;
25062506
zend_long from, width;
25072507

25082508
ZEND_PARSE_PARAMETERS_START(3, 5)

ext/mbstring/tests/gh9248.phpt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
Bug GH-9248 (Segmentation fault in mb_strimwidth())
3+
--EXTENSIONS--
4+
mbstring
5+
--FILE--
6+
<?php
7+
var_dump(mb_strimwidth('The quick brown fox', 0, 8));
8+
?>
9+
--EXPECT--
10+
string(8) "The quic"

0 commit comments

Comments
 (0)