Discussion:
[ast-developers] null pointer dereference in sh_assignok() function
Tomas Klacko
2014-01-08 20:01:29 UTC
Permalink
Hi,

I have a ksh script which causes null pointer
dereference in the sh_assignok() function a few
minutes after it is started. The script
is a bit elaborate and not mine.

Simply ignoring the NULL pointer seems to work:

<patch>
--- /dev/null Fri Nov 29 06:35:21 2013
+++ new/components/ksh93/patches/17851169.patch Fri Nov 29 06:35:20 2013
@@ -0,0 +1,30 @@
--- a/src/cmd/ksh93/sh/subshell.c
+++ b/src/cmd/ksh93/sh/subshell.c
@@ -234,15 +234,22 @@ Namval_t *sh_assignok(register Namval_t *np,int add)
{
register Namval_t *mp;
register struct Link *lp;
- register struct subshell *sp = (struct subshell*)subshell_data;
- Shell_t *shp = sp->shp;
- Dt_t *dp= shp->var_tree;
+ register struct subshell *sp;
+ Shell_t *shp;
+ Dt_t *dp;
Namval_t *mpnext;
Namarr_t *ap;
int save;
+
+ sp = (struct subshell*)subshell_data;
+
/* don't bother with this */
- if(!sp->shpwd || np==SH_LEVELNOD || np==L_ARGNOD ||
np==SH_SUBSCRNOD || np==SH_NAMENOD)
+ if(!sp || !sp->shpwd || np==SH_LEVELNOD || np==L_ARGNOD ||
np==SH_SUBSCRNOD || np==SH_NAMENOD)
return(np);
+
+ shp = sp->shp;
+ dp = shp->var_tree;
+
if((ap=nv_arrayptr(np)) && (mp=nv_opensub(np)))
{
shp->last_root = ap->table;

</patch>

Is the fix ok?

Tomas Klacko

Loading...