Skip to content

Commit 78d98e5

Browse files
committed
Fix GH-11567: mb_str_pad causes access violation
When not providing a pad string, *and* not having other defaulted arguments, the function would crash on a NULL pad zend_string*. Despite testing with an empty pad string, the issue wasn't found because when using named arguments the pad string *is* filled in.
1 parent 9fe33c8 commit 78d98e5

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

ext/mbstring/mbstring.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -5529,7 +5529,7 @@ PHP_FUNCTION(mb_chr)
55295529

55305530
PHP_FUNCTION(mb_str_pad)
55315531
{
5532-
zend_string *input, *encoding_str = NULL, *pad = NULL;
5532+
zend_string *input, *encoding_str = NULL, *pad = ZSTR_CHAR(' ');
55335533
zend_long pad_to_length;
55345534
zend_long pad_type_val = PHP_STR_PAD_RIGHT;
55355535

ext/mbstring/tests/mb_str_pad.phpt

+11
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ var_dump(mb_str_pad('▶▶', 1, ' ', STR_PAD_BOTH));
4646
var_dump(mb_str_pad('▶▶', 0, ' ', STR_PAD_BOTH));
4747
var_dump(mb_str_pad('▶▶', -1, ' ', STR_PAD_BOTH));
4848

49+
echo "--- No pad string ---\n";
50+
var_dump(mb_str_pad('▶▶', 4));
51+
var_dump(mb_str_pad('▶▶', 3));
52+
var_dump(mb_str_pad('▶▶', 2));
53+
var_dump(mb_str_pad('▶▶', 1));
54+
4955
echo "--- Empty input string ---\n";
5056
var_dump(mb_str_pad('', 2, ' ', STR_PAD_BOTH));
5157
var_dump(mb_str_pad('', 1, ' ', STR_PAD_BOTH));
@@ -98,6 +104,11 @@ string(6) "▶▶"
98104
string(6) "▶▶"
99105
string(6) "▶▶"
100106
string(6) "▶▶"
107+
--- No pad string ---
108+
string(8) "▶▶ "
109+
string(7) "▶▶ "
110+
string(6) "▶▶"
111+
string(6) "▶▶"
101112
--- Empty input string ---
102113
string(2) " "
103114
string(1) " "

0 commit comments

Comments
 (0)