Discussion:
[ast-developers] Setting KSH_VERSION makes ksh to core dump
Tomas Klacko
11 years ago
Permalink
Hi,

Setting the KSH_VERSION variable to some value before running ksh
from other shell makes the ksh to core dump:

user at host:~$ env | grep SHELL
SHELL=/bin/bash
XTERM_SHELL=/bin/bash
user at host:~$ export KSH_VERSION=abcd
user at host:~$ ksh
Segmentation Fault (core dumped)
user at host:~$

For KSH_VERSION=abcd, ksh does (at the end of the nv_putval() function)
memmove(cp,sp,dot);):

np->nvalue.cp="abcd"

the code then later uses:

np->nvalue.nrp->np

which contains "abcd" as pointer value.

What should be the fix here?

Tomas Klacko
ольга крыжановская
11 years ago
Permalink
No fix. KSH_VERSION is a read only variable, always defined to be
nameref for .sh.version, which itself is set at shell startup time to
the version of the ksh shell. Setting it is not allowed, nor useful,
by definition.

Olga
...
--
, _ _ ,
{ \/`o;====- Olga Kryzhanovska -====;o`\/ }
.----'-/`-/ olga.kryzhanovska at gmail.com \-`\-'----.
`'-..-| / http://twitter.com/fleyta \ |-..-'`
/\/\ Solaris/BSD//C/C++ programmer /\/\
`--` `--`
Tomas Klacko
11 years ago
Permalink
Post by ольга крыжановская
No fix. KSH_VERSION is a read only variable, always defined to be
nameref for .sh.version, which itself is set at shell startup time to
the version of the ksh shell. Setting it is not allowed, nor useful,
by definition.
Olga
Would it be possible then for the ksh to check for such variables
being passed to it from the environment and to ignore them
(instead of crashing)?

Tomas Klacko
...
David Korn
11 years ago
Permalink
Yes, I will look into making this change for the next ksh93 update.
...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.research.att.com/pipermail/ast-developers/attachments/20140106/c1e19f76/attachment.html>
Tomas Klacko
11 years ago
Permalink
Post by David Korn
Yes, I will look into making this change for the next ksh93 update.
Thank you. Is there an estimate on the release date?

In the meantime would this be sufficient to ignore
the KSH_VERSION passed in from the environment?

1 --- a/src/cmd/ksh93/sh/init.c
2 +++ b/src/cmd/ksh93/sh/init.c
3 @@ -1903,6 +1903,13 @@ static Dt_t *inittree(Shell_t *shp,const
struct shtable2 *name_vals)
4 return(treep);
5 }
6
7 +static int is_read_only(const char* cp, const char* dp)
8 +{
9 + if(strncmp(cp, "KSH_VERSION", dp-cp)==0)
10 + return(1);
11 + return(0);
12 +}
13 +
14 /*
15 * read in the process environment and set up name-value pairs
16 * skip over items that are not name-value pairs
17 @@ -1930,6 +1937,8 @@ static void env_init(Shell_t *shp)
18 dp = strchr(cp,'=');
19 if(!dp)
20 continue;
21 + if(is_read_only(cp, dp))
22 + continue;
23 *dp++ = 0;
24 if(mp = dtmatch(shp->var_base,cp))
25 {
26

Should there be something else ignored besides KSH_VERSION?

Tomas Klacko
...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.research.att.com/pipermail/ast-developers/attachments/20140109/9c8d4821/attachment.html>