Commit 55e44ee2ff3 for php
commit 55e44ee2ff328dbb1f897d8bdc230ae820aa0170
Author: Weilin Du <weilindu@php.net>
Date: Sun Oct 11 15:00:09 2026 +0000
ext/readline: Fix non-ASCII completion append characters in readline_info() (#24263)
The first byte of completion_append_character could become negative when
plain char is signed. Subsequent readline_info() calls would then use an
invalid index into the one-character string table and could crash.
Read the byte as unsigned char to keep the value within the valid range.
Add a regression test covering ASCII, non-ASCII, and empty strings.
Closes #24263
diff --git a/NEWS b/NEWS
index f54a52230b4..7d58f7fa5db 100644
--- a/NEWS
+++ b/NEWS
@@ -49,6 +49,10 @@ PHP NEWS
- Phpdbg:
. Fix wrong command names. (ndossche, Weilin Du)
+- Readline:
+ . Fixed a crash in readline_info() when completion_append_character
+ contains a non-ASCII byte. (Weilin Du)
+
- SOAP:
. Fixed use of uninitialized func in do_request() on OOM bailout.
(David Carlier)
diff --git a/ext/readline/readline.c b/ext/readline/readline.c
index 838c74da86c..f9287af2eff 100644
--- a/ext/readline/readline.c
+++ b/ext/readline/readline.c
@@ -248,7 +248,7 @@ PHP_FUNCTION(readline_info)
if (!try_convert_to_string(value)) {
RETURN_THROWS();
}
- rl_completion_append_character = (int)Z_STRVAL_P(value)[0];
+ rl_completion_append_character = (unsigned char)Z_STRVAL_P(value)[0];
}
RETVAL_INTERNED_STR(
oldval == 0 ? ZSTR_EMPTY_ALLOC() : ZSTR_CHAR(oldval));
diff --git a/ext/readline/tests/readline_info_completion_append_character.phpt b/ext/readline/tests/readline_info_completion_append_character.phpt
new file mode 100644
index 00000000000..88a0cf00338
--- /dev/null
+++ b/ext/readline/tests/readline_info_completion_append_character.phpt
@@ -0,0 +1,27 @@
+--TEST--
+readline_info(): completion_append_character supports non-ASCII bytes
+--EXTENSIONS--
+readline
+--SKIPIF--
+<?php
+if (READLINE_LIB !== 'readline') die('skip readline only');
+?>
+--FILE--
+<?php
+readline_info('completion_append_character', '');
+foreach (["\x7f", "\x80", "\xfftail", ''] as $value) {
+ $old = readline_info('completion_append_character', $value);
+ $current = readline_info('completion_append_character');
+ $info = readline_info();
+ printf("old=%s current=%s info=%s\n",
+ bin2hex($old),
+ bin2hex($current),
+ bin2hex($info['completion_append_character'])
+ );
+}
+?>
+--EXPECT--
+old= current=7f info=7f
+old=7f current=80 info=80
+old=80 current=ff info=ff
+old=ff current= info=