Skip to content

Commit a2e0519

Browse files
committed
Fix bug #81280 refuse to allow unicode chars in prompts
1 parent 3a4d0d3 commit a2e0519

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ PHP NEWS
55
- Core:
66
. Fixed bug #81342 (New ampersand token parsing depends on new line after it).
77
(Nikita)
8+
. Fixed bug #81280 (Unicode characters in cli.prompt causes segfault).
9+
(krakjoe)
810

911
- Date:
1012
. Fixed bug #79580 (date_create_from_format misses leap year). (Derick)

ext/readline/readline_cli.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ static zend_string *cli_get_prompt(char *block, char prompt) /* {{{ */
135135
{
136136
smart_str retval = {0};
137137
char *prompt_spec = CLIR_G(prompt) ? CLIR_G(prompt) : DEFAULT_PROMPT;
138+
bool unicode_warned = false;
138139

139140
do {
140141
if (*prompt_spec == '\\') {
@@ -193,7 +194,16 @@ static zend_string *cli_get_prompt(char *block, char prompt) /* {{{ */
193194
prompt_spec = prompt_end;
194195
}
195196
} else {
196-
smart_str_appendc(&retval, *prompt_spec);
197+
if (!(*prompt_spec & 0x80)) {
198+
smart_str_appendc(&retval, *prompt_spec);
199+
} else {
200+
if (!unicode_warned) {
201+
zend_error(E_WARNING,
202+
"prompt contains unsupported unicode characters");
203+
unicode_warned = true;
204+
}
205+
smart_str_appendc(&retval, '?');
206+
}
197207
}
198208
} while (++prompt_spec && *prompt_spec);
199209
smart_str_0(&retval);

sapi/phpdbg/phpdbg_utils.c

+17
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,23 @@ PHPDBG_API const char *phpdbg_get_prompt(void) /* {{{ */
300300
return PHPDBG_G(prompt)[1];
301301
}
302302

303+
uint32_t pos = 0,
304+
end = strlen(PHPDBG_G(prompt)[0]);
305+
bool unicode_warned = false;
306+
307+
while (pos < end) {
308+
if (PHPDBG_G(prompt)[0][pos] & 0x80) {
309+
PHPDBG_G(prompt)[0][pos] = '?';
310+
311+
if (!unicode_warned) {
312+
zend_error(E_WARNING,
313+
"prompt contains unsupported unicode characters");
314+
unicode_warned = true;
315+
}
316+
}
317+
pos++;
318+
}
319+
303320
/* create cached prompt */
304321
#ifndef HAVE_LIBEDIT
305322
/* TODO: libedit doesn't seems to support coloured prompt */

0 commit comments

Comments
 (0)