Bug #81280 [Opn]: cli.prompt leads to segmentation fault

From: Date: Fri, 23 Jul 2021 13:51:40 +0000
Subject: Bug #81280 [Opn]: cli.prompt leads to segmentation fault
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-235310@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81280&edit=1

 ID:                 81280
 Updated by:         cmb@php.net
 Reported by:        easteregg at verfriemelt dot org
 Summary:            cli.prompt leads to segmentation fault
 Status:             Open
 Type:               Bug
 Package:            *General Issues
 Operating System:   Debian GNU/Linux 11 (bullseye)
 PHP Version:        8.0.8
 Block user comment: N
 Private report:     N

 New Comment:

FWIW, this works on Windows (except that setting the option via
command line causes a assertion violation, because isalnum expects
a number in range -1 to 255[1] while by default char gets promoted
to int as if from type signed char[2]).

And well, the documentation is meager; it does not even mention
the meaning of the escape characters[3].

[1] <https://github.com/php/php-src/blob/php-7.4.21/sapi/cli/php_cli.c#L1252>
[2] <https://docs.microsoft.com/en-us/cpp/cpp/char-wchar-t-char16-t-char32-t?view=msvc-160>
[3] <https://github.com/php/php-src/blob/php-7.4.21/ext/readline/readline_cli.c#L143-L181>


Previous Comments:
------------------------------------------------------------------------
[2021-07-23 08:31:01] easteregg at verfriemelt dot org

with -n it does not segfault but shows no prompt at all.

gdb trace:

Reading symbols from /usr/bin/php...
Reading symbols from /usr/lib/debug/.build-id/b5/86e7d17af20d6d58923a72e13bcd4d4c2c9295.debug...
(gdb) r
Starting program: /usr/bin/php -d cli.prompt=» -a
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Interactive mode enabled


Program received signal SIGSEGV, Segmentation fault.
0x00007ffff2fb66e5 in ?? () from /lib/x86_64-linux-gnu/libedit.so.2
(gdb) bt
#0  0x00007ffff2fb66e5 in ?? () from /lib/x86_64-linux-gnu/libedit.so.2
#1  0x00007ffff2fb78db in ?? () from /lib/x86_64-linux-gnu/libedit.so.2
#2  0x00007ffff2fb6e57 in ?? () from /lib/x86_64-linux-gnu/libedit.so.2
#3  0x00007ffff2fb7258 in el_wgets () from /lib/x86_64-linux-gnu/libedit.so.2
#4  0x00007ffff2fb1d63 in el_gets () from /lib/x86_64-linux-gnu/libedit.so.2
#5  0x00007ffff2fc5486 in readline () from /lib/x86_64-linux-gnu/libedit.so.2
#6  0x00007ffff31528e4 in readline_shell_run () at ./ext/readline/readline_cli.c:624
#7  0x00005555558a25dd in do_cli (argc=4, argv=0x555555a35ed0) at ./sapi/cli/php_cli.c:947
#8  0x000055555566767b in main (argc=4, argv=0x555555a35ed0) at ./sapi/cli/php_cli.c:1336
(gdb)

------------------------------------------------------------------------
[2021-07-23 08:01:22] patrickallaert@php.net

I can't reproduce this one, any chance to provide a gdb backtrace?

Does it happen too with the following?

$ php -n -d cli.prompt="»" -a

------------------------------------------------------------------------
[2021-07-23 06:18:07] easteregg at verfriemelt dot org

sorry, i forgot to mention, that this will only occur with unicode characters, hence the example
with "»"

------------------------------------------------------------------------
[2021-07-23 06:10:30] easteregg at verfriemelt dot org

Description:
------------
i wanted to improve my interactive shellprompt...



Test script:
---------------
echo cli.prompt="»" > test.ini
PHPRC=pwd/test.ini php -a

Expected result:
----------------
Interactive mode enabled

»

Actual result:
--------------
Interactive mode enabled

[1]    2825134 segmentation fault (core dumped)  php -a



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=81280&edit=1


Thread (10 messages)

« previous php.bugs (#235310) next »