Discussion:
[ast-developers] Long PS1 string causes segfault
Tomas Klacko
2014-01-06 18:52:04 UTC
Permalink
Hi,

This causes segfault:

user at host:~$ ksh
:/home/user 1 $ set -o emacs
:/home/user 2 $ . ./ps1.env
__ warn [GTS]prompt:/home/tklacko # Segmentation Fault (core dumped)
user at host:~$


The ps1.env contents:

e="$(echo "\033")"
a="$(echo "\007")"

TERM_FG="$e]10;#FFFFd7$a"
TERM_BG="$e]11;#121212$a"
TERM_TITLE="$e]0;xterm title$a"
BG_RED="$e[41m"
FG_WHITE="$e[37m"
BOLD="$e[1m"
UNDERLINE="$e[4m"
RESETCOL="$e[0m"
BG256_BLACK="$e[48;5;233m"
FG256_OLDLACE="$e[38;5;230m"

PS1="$TERM_FG$TERM_BG$TERM_TITLE$BG_RED$FG_WHITE$BOLD${UNDERLINE}__$RESETCOL$BG_RED
$RESETCOL$BG256_BLACK$FG256_OLDLACE$FG_WHITE$BG_RED warn
$BG256_BLACK$FG256_OLDLACE$BOLD[GTS]prompt$RESETCOL$BG256_BLACK$FG256_OLDLACE:$PWD$FG256_OLDLACE
# "


I found this to be the fix:

--- a/src/cmd/ksh93/edit/edit.c
+++ b/src/cmd/ksh93/edit/edit.c
@@ -651,7 +651,8 @@ void ed_setup(register Edit_t *ep, int fd,
int reedit)
{
int skip=0;
ep->e_crlf = 0;
- *pp++ = c;
+ if (pp < ppmax)
+ *pp++ = c;
for(n=1; c = *last++; n++)
{
if(pp < ppmax)

It prevents the ed_setup() function from writing past the ep->e_prompt.
ep->e_prompt is set to the local char prompt[PRSIZE] variable in
ed_emacsread().

Is the fix acceptable?

Tomas Klacko
David Korn
2014-01-06 21:01:20 UTC
Permalink
Yes, the fix is acceptable and it will be in the next ksh93 update. Also,
I increased PRISIZE from 160 to 256.
Post by Tomas Klacko
Hi,
user at host:~$ ksh
:/home/user 1 $ set -o emacs
:/home/user 2 $ . ./ps1.env
__ warn [GTS]prompt:/home/tklacko # Segmentation Fault (core dumped)
user at host:~$
e="$(echo "\033")"
a="$(echo "\007")"
TERM_FG="$e]10;#FFFFd7$a"
TERM_BG="$e]11;#121212$a"
TERM_TITLE="$e]0;xterm title$a"
BG_RED="$e[41m"
FG_WHITE="$e[37m"
BOLD="$e[1m"
UNDERLINE="$e[4m"
RESETCOL="$e[0m"
BG256_BLACK="$e[48;5;233m"
FG256_OLDLACE="$e[38;5;230m"
PS1="$TERM_FG$TERM_BG$TERM_TITLE$BG_RED$FG_WHITE$BOLD${UNDERLINE}__$RESETCOL$BG_RED
$RESETCOL$BG256_BLACK$FG256_OLDLACE$FG_WHITE$BG_RED warn
$BG256_BLACK$FG256_OLDLACE$BOLD[GTS]prompt$RESETCOL$
BG256_BLACK$FG256_OLDLACE:$PWD$FG256_OLDLACE # "
--- a/src/cmd/ksh93/edit/edit.c
+++ b/src/cmd/ksh93/edit/edit.c
@@ -651,7 +651,8 @@ void ed_setup(register Edit_t *ep, int fd, int
reedit)
{
int skip=0;
ep->e_crlf = 0;
- *pp++ = c;
+ if (pp < ppmax)
+ *pp++ = c;
for(n=1; c = *last++; n++)
{
if(pp < ppmax)
It prevents the ed_setup() function from writing past the ep->e_prompt.
ep->e_prompt is set to the local char prompt[PRSIZE] variable in
ed_emacsread().
Is the fix acceptable?
Tomas Klacko
_______________________________________________
ast-developers mailing list
ast-developers at lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-developers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.research.att.com/pipermail/ast-developers/attachments/20140106/d617d3a8/attachment.html>
Loading...