Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: 3.1.4 segfault in restore_params



The core dump is obviously a null pointer dereference, so the following is
a minimal fix, but I wonder how the null value got into the restorelist in
the first place?  (Circumstances below the patch.)

Index: Src/exec.c
--- exec.c	1998/09/18 17:06:53	1.2
+++ exec.c	1998/10/09 15:22:54
@@ -1971,8 +1971,8 @@
 		}
 	    } else
 		paramtab->addnode(paramtab, pm->nam, pm);
-	    if (pm->flags & PM_EXPORTED)
-		pm->env = addenv(pm->nam, getsparam(pm->nam));
+	    if ((pm->flags & PM_EXPORTED) && ((s = getsparam(pm->nam))))
+		pm->env = addenv(pm->nam, s);
 	}
     }
 }



I have a little function called "cvs":
----------
#! /usr/local/bin/zsh -f
cvsroot
case $1 in
diff|log|status)
    command cvs -n $* ;;
*)
    command cvs $* ;;
esac
----------

It calls a function called "cvsroot" to determine the correct value for
the CVSROOT environment variable:
----------
#!/usr/local/bin/zsh -f
if [[ ! -d CVS ]]
then
    return 1
    exit 1
fi
if [[ -z "$CVSROOT" || ! -d "$CVSROOT"/CVSROOT ]]
then
    if [[ -f CVS/Root ]]
    then
	CVSROOT=$(<CVS/Root)
    else
	CVSROOT=$(<CVS/Repository)
	while [[ ! -d $CVSROOT/CVSROOT && $CVSROOT != $CVSROOT:h ]]
	do
	    CVSROOT=$CVSROOT:h
	done
    fi
    if [[ ! -d "$CVSROOT"/CVSROOT ]]
    then
	unset CVSROOT
    fi
fi
if [[ -n "$CVSROOT" ]]
then
    if [[ $- != *f* ]]
    then
	export CVSROOT
    else
	echo setenv CVSROOT $CVSROOT
    fi
fi
----------

(Yes, I know the above isn't necessary with some recent versions of cvs.)

I was using this repeatedly from inside 3.1.4 for the first time yesterday,
and after 5 or 6 calls -- I'm not exactly sure how many worked fine -- it
completed the cvs command and then, apparently on exit from the function,
zsh segfaulted.

It's possible that I was in a directory with no CVS subdirectory and that
I'd therefore prefixed the command with CVSROOT=..., but I don't think so.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



Messages sorted by: Reverse Date, Date, Thread, Author