[comp.lang.perl] PERL dumps core on s/// the third time????

harald.alvestrand@elab-runit.sintef.no (03/04/91)

May all the net.gods rise up and strike me...here is a bug I found
in hoary old perl version 3.0, patch level 37:

Given the following stuff, PERL will core dump on a Sun-4/490 running
SunOS 4.0.3, if the command line is

 perl bug.perl bug.translate bug.sum

It attempts to EVAL several s-expressions. Everything seems critical.
The bug in the original program was the check for comment lines,
but still, PERL should not core dump on me, should it????

BTW: it coredumps on perl -d and "c", but does NOT coredump when I single-step
through the whole program. Sounds rather random.

The stuff below is SHAR....

                   Harald Tveit Alvestrand
Harald.Alvestrand@elab-runit.sintef.no
C=no;PRMD=uninett;O=sintef;OU=elab-runit;S=alvestrand;G=harald
+47 7 59 70 94


#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  bug.perl bug.sum bug.translate
# Wrapped by hta@aun on Mon Mar  4 13:50:29 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'bug.perl' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'bug.perl'\"
else
echo shar: Extracting \"'bug.perl'\" \(985 characters\)
sed "s/^X//" >'bug.perl' <<'END_OF_FILE'
X#!/local/bin/perl
X
X# This is the program....
Xif ($#ARGV < 0) { die "Usage: $0 renamefile minmsg\n"; }
X$deffile = shift(@ARGV);
X
Xopen(   DEFINITION, $deffile) || die "Could not open $deffile\n";
Xwhile (<DEFINITION>) {
X   chop;
X   if (/[^#]*\//) { # Respect the hash, and only parse lines with slash before
X        s/\s*\#.*$//;   # Remove end-of-line comments
X        ($pattern, $to) = split('/');
X         push(@patterns, $pattern);
X         push(@tos, $to);
X   }
X}
Xclose DEFINITION;
X
Xwhile (<>) {
X   @splitline = split(" ");
X   $dom = $splitline[0];
X   $dom =~ tr/A-Z/a-z/;
X   $dom = &simplify($dom);
X}
X   
Xsub simplify {
X   local($dom)  = @_;
X   # Try each of the patterns listed, in order
X   loop: for $index (0..$#patterns) {
X      $expr = "\$dom =~ s/$patterns[$index]/$tos[$index]/";
X      print "$expr\n";
X      $status = eval $expr;
X      if ($@) {
X         die "Eval of $expr failed, status $@\n";
X      }
X      print "OK\n";
X      if ($status) { last loop; }
X   }
X   $dom;
X}
END_OF_FILE
if test 985 -ne `wc -c <'bug.perl'`; then
    echo shar: \"'bug.perl'\" unpacked with wrong size!
fi
chmod +x 'bug.perl'
# end of 'bug.perl'
fi
if test -f 'bug.sum' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'bug.sum'\"
else
echo shar: Extracting \"'bug.sum'\" \(90 characters\)
sed "s/^X//" >'bug.sum' <<'END_OF_FILE'
XLIST-REDISTRIBUTION@SINTEF.NO 4 6914 0 0 0 0
XC=NO;O=UIB;OU=IFI;S=TUFTEDAL 0 0 1 372 1 372
END_OF_FILE
if test 90 -ne `wc -c <'bug.sum'`; then
    echo shar: \"'bug.sum'\" unpacked with wrong size!
fi
# end of 'bug.sum'
fi
if test -f 'bug.translate' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'bug.translate'\"
else
echo shar: Extracting \"'bug.translate'\" \(101 characters\)
sed "s/^X//" >'bug.translate' <<'END_OF_FILE'
X# Oversettelsesfil for opptelling av O/R navn
X^c=no;o=([^;]*);.*/Inet-NO $1
X.*@.*/Gamle EAN adresser
END_OF_FILE
if test 101 -ne `wc -c <'bug.translate'`; then
    echo shar: \"'bug.translate'\" unpacked with wrong size!
fi
# end of 'bug.translate'
fi
echo shar: End of shell archive.
exit 0

tale@rpi.edu (David C Lawrence) (03/05/91)

In <1991Mar4.130949.6450@ugle.unit.no> harald.alvestrand@elab-runit.sintef.no:

   BTW: it coredumps on perl -d and "c", but does NOT coredump when I
   single-step through the whole program. Sounds rather random.

The problem I was having with Tom's man and ndbm on Ultrix DS3100s was
not evident under perl -d or perl -D.  Something was sufficiently
different then not to tickle the bug.  Boy, I hate when that happens.
--
    (setq mail '("tale@rpi.edu" "uupsi!rpi!tale" "tale@rpitsmts.bitnet"))

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (03/05/91)

In article <1991Mar4.130949.6450@ugle.unit.no> harald.alvestrand@elab-runit.sintef.no writes:
: Given the following stuff, PERL will core dump on a Sun-4/490 running
: SunOS 4.0.3, if the command line is
: 
:  perl bug.perl bug.translate bug.sum
: 
: It attempts to EVAL several s-expressions. Everything seems critical.
: The bug in the original program was the check for comment lines,
: but still, PERL should not core dump on me, should it????

Your problem is that some of the elements of your pattern array are null,
so you're doing s//something/, which makes it look for the previously
used regular expression, which, unfortunately, has already been freed
because it was in an eval.  Your fix is to throw away pattern lines
that are null after you strip comments.

In 4.0, the using s/// or m// will refer back to the previous pattern
that wasn't in an eval.  This would still have caused misbehavior in
your program, but it wouldn't have core dumped.

Larry

allbery@NCoast.ORG (Brandon S. Allbery KB8JRR) (03/10/91)

As quoted from <L*7-=SC@rpi.edu> by tale@rpi.edu (David C Lawrence):
+---------------
| In <1991Mar4.130949.6450@ugle.unit.no> harald.alvestrand@elab-runit.sintef.no:
|    BTW: it coredumps on perl -d and "c", but does NOT coredump when I
|    single-step through the whole program. Sounds rather random.
| 
| The problem I was having with Tom's man and ndbm on Ultrix DS3100s was
| not evident under perl -d or perl -D.  Something was sufficiently
| different then not to tickle the bug.  Boy, I hate when that happens.
+---------------

Ah, yes:  Heisenbugs.  :-)

++Brandon
-- 
Me: Brandon S. Allbery			    Ham: KB8JRR on 40m, 10m when time
Internet: allbery@NCoast.ORG		      permits; also 2m, 220, 440, 1200
America OnLine: KB8JRR // Delphi: ALLBERY   AMPR: kb8jrr.AmPR.ORG [44.70.4.88]
uunet!usenet.ins.cwru.edu!ncoast!allbery          KB8JRR @ WA8BXN.OH

rbj@uunet.UU.NET (Root Boy Jim) (03/12/91)

In article <1991Mar9.164643.1141@NCoast.ORG> allbery@ncoast.ORG (Brandon S. Allbery KB8JRR) writes:
>
>Ah, yes:  Heisenbugs.  :-)

Sign in an inn: Heisenberg may have slept here.

>++Brandon

Please adapt your signature for the appropriate group.
Here, it should read ++$Brandon :-)
-- 
		[rbj@uunet 1] stty sane
		unknown mode: sane

allbery@NCoast.ORG (Brandon S. Allbery KB8JRR) (03/16/91)

As quoted from <125279@uunet.UU.NET> by rbj@uunet.UU.NET (Root Boy Jim):
+---------------
| Please adapt your signature for the appropriate group.
| Here, it should read ++$Brandon :-)
+---------------

Well, aside fromt he fact that it isn't an lvalue, it's close to legal Perl as
is:  remember magical autoincrement.  :-)

++$just_another_perl_hacker'Brandon;
-- 
Me: Brandon S. Allbery			    Ham: KB8JRR on 40m, 10m when time
Internet: allbery@NCoast.ORG		      permits; also 2m, 220, 440, 1200
America OnLine: KB8JRR // Delphi: ALLBERY   AMPR: kb8jrr.AmPR.ORG [44.70.4.88]
uunet!usenet.ins.cwru.edu!ncoast!allbery          KB8JRR @ WA8BXN.OH