Skip to content

Commit 532fcd1

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: ext/readline: Fix non-ASCII pending input in readline_info() (#25285)
2 parents 3139a42 + a93d24c commit 532fcd1

3 files changed

Lines changed: 33 additions & 1 deletion

File tree

‎NEWS‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ PHP NEWS
3131
. Fixed bug GH-25267 (NULL dereference in to_xml_any() with integer key).
3232
(lazerg)
3333

34+
- Readline:
35+
. Fixed incorrect handling of non-ASCII pending_input bytes in readline_info(),
36+
which could cause readline() to return false prematurely. (Weilin Du)
37+
3438
- Streams:
3539
. Fixed bug GH-22063 (Stream filter chain UAF on self-removal during
3640
callback). (Ilia Alshanetsky)

‎ext/readline/readline.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ PHP_FUNCTION(readline_info)
229229
if (!try_convert_to_string(value)) {
230230
RETURN_THROWS();
231231
}
232-
rl_pending_input = Z_STRVAL_P(value)[0];
232+
rl_pending_input = (unsigned char)Z_STRVAL_P(value)[0];
233233
}
234234
RETVAL_LONG(oldval);
235235
} else if (zend_string_equals_literal_ci(what, "prompt")) {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
readline_info(): pending_input supports non-ASCII bytes
3+
--EXTENSIONS--
4+
readline
5+
--SKIPIF--
6+
<?php
7+
if (READLINE_LIB !== 'readline') die('skip readline only');
8+
?>
9+
--FILE--
10+
<?php
11+
readline_info('pending_input', '');
12+
foreach (["\x7f", "\x80", "\xfe", "\xfftail", ''] as $value) {
13+
$old = readline_info('pending_input', $value);
14+
$current = readline_info('pending_input');
15+
$info = readline_info();
16+
printf("old=%d current=%d info=%d\n",
17+
$old,
18+
$current,
19+
$info['pending_input']
20+
);
21+
}
22+
?>
23+
--EXPECT--
24+
old=0 current=127 info=127
25+
old=127 current=128 info=128
26+
old=128 current=254 info=254
27+
old=254 current=255 info=255
28+
old=255 current=0 info=0

0 commit comments

Comments
 (0)