Bug/problem in ksh88b and/or SUN OS

Marnix van Ammers mavanamm at pttesac.UUCP
Wed Oct 18 09:08:41 AEST 1989


My ksh88b was dumping core on my SUN 3/50.  It would happen
whenever the first command I executed was a particular function in
my $FPATH.  I traced it down to the first echo command in my function.
When I recompiled ksh88b with ECHOPRINT set to 1 in the OPTIONS file,
the core dumps stopped.

I found out that when the core dump happened, the call to
path_absolute() at line 1084 of sh/name.c returned a NULL pointer
and that NULL pointer was then passed to strcmp() at line 1086.
The strcmp() function in SUN OS 4.0.3 apparently cannot take a NULL
argument (maybe this is really something SUN ought to fix?).

I could not figure out why path_absolute was returning a NULL
pointer.  When I used the dbxtool debugger I'd end up getting
a "Trace/BPT trap(coredump)" before getting to where my normal core
dump was occurring.  I don't know what a "Trace/BPT trap(coredump)"
(BPT == Break Point Trap ??) is but it seems to be a feature or
problem with the debugger (I'm new at this dbx stuff, so forgive me).

I was able to at least fix the problem by not passing a NULL pointer
to strcmp().

Here are the diffs to my fix (to sh/name.c):
1085a1086,1104
> 
> /* Core dumping fix
> 
>    By: Marnix A. van Ammers
>        Oct 12, 1989
>        {att|pacbell}!pttesac!mavanamm
>    
>    Following fix added to avoid core dump by eq() when cp is NULL.
>    (Happens when path_absolute() in echo_mode() returns NULL.)
>    That situation happened when the first command to use echo was in my
>    function gp() and OPTIONS had ECHOPRINT=0 and there is a
>    /bin/echo as in the case of my Sun 3/50 running SUNOS 4.0.3 */
> 
> 		if(cp == NULL)
> 			echo_arg = (char *) e_minus;
> 		else
> 
> /* end of core dumping fix. */
> 

For your information, here's my autoload function gp (I've since
changed this function, but this is the version that caused
ksh88b to dump core in my SUN):
#################################################################
function getpaths {
  if [ "$1" = -x ];then
    set -x;shift
  fi
  # getpaths($PATH) -- Return list of paths in $1
  typeset PATH="$1"
  typeset This_Path Front_Part Paths

  while [ -n "${PATH}" ];do  # While there's something in $PATH
    Front_Part="${PATH%%:*}" # Remove 1st ':' and all to the right of it
    if [ -z "$Front_Part" ];then # Front part was null -- special case
      This_Path="."
      Front_Part=":"
    else
      This_Path="$Front_Part"
    fi
    Paths="$Paths $This_Path"
    PATH="${PATH#${Front_Part}}"
    if [ "${PATH}" != ":" ];then # If this isn't the last (trailing) ':' 
      PATH="${PATH#:}"           # then remove the leading ':'
    fi
  done
  echo "$Paths"
}

# gp = getpath .  Finds a *command* and does an ls -l on it
# For instance "gp sh" should find sh, rsh, ksh, rksh
function gp {
  if [ "$1" = -x ];then
    set -x;shift
  fi
  typeset F Files PATHS P

  print "Searching for executables \"*$1*\" in \$PATH" >&2
  PATHS=`getpaths "$PATH"`
  for P in $PATHS;do
    for F in $P/*$1*;do
      if [ -f "$F" -a -x "$F" ];then
        Files="$Files $F"
      fi
    done
  done
  if [ -n "$Files" ];then
    ls -ld $Files
  fi
}
#################################################################

I don't seem to have the real problem in hand, but I did just want
to report this to the net in case anyone has an idea what's really
going on.

--
Marnix



More information about the Comp.unix.wizards mailing list