develooper Front page | perl.perl5.porters | Postings from May 2011

Re: [perl #91032] Invalid free in t/op/write.t

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
May 21, 2011 11:32
Subject:
Re: [perl #91032] Invalid free in t/op/write.t
Message ID:
20110521183215.GA23881@plum.flirble.org
On Sat, May 21, 2011 at 06:09:31PM +0100, Robin Barker wrote:
> On Sat, 2011-05-21 at 08:56 -0700, Karl Williamson via RT wrote:
> > Git bisect results:
> > 
> > 37ffbfcca347ea751c9514463873b90f8a496be0 is the first bad commit
> > commit 37ffbfcca347ea751c9514463873b90f8a496be0
> > Author: Nicholas Clark <nick@ccl4.org>
> > Date:   Mon May 2 12:37:30 2011 +0100
> 
> But this is just when the test in t/op/write.t was introduced.
> 
> The underlying failure is present in perl5.12.0
> 
> > env PERL_DESTRUCT_LEVEL=1 perl5.12.0 -e 'my $foo=[qw(foo)]; formline
> $foo'
> *** glibc detected *** perl5.12.0: free(): invalid next size (fast):
> 0x08ab3f90 ***
> ...
> Abort

Bisecting with this:

#!/bin/sh
git clean -dxf
touch .patchnum
touch .sha1
touch unpushed.h
# If you can use ccache, add -Dcc=ccache\ gcc -Dld=gcc to the Configure line
# if Encode is not needed for the test, you can speed up the bisect by
# excluding it from the runs with -Dnoextensions=Encode
sh Configure -des -Dusedevel -Uusethreads -Doptimize="-g" -Dcc=ccache\ gcc -Dld=gcc -Dnoextensions=IPC/SysV\ Encode\ DB_File
test -f config.sh || exit 125
# Correct makefile for newer GNU gcc
perl -ni -we 'print unless /<(?:built-in|command)/' makefile x2p/makefile
# if you just need miniperl, replace test_prep with miniperl
make -j3 miniperl
[ -x ./miniperl ] || exit 125
PERL_DESTRUCT_LEVEL=2 valgrind --error-exitcode=1 ./miniperl -Ilib -e 'my $foo=[qw(foo)]; formline $foo'
ret=$?
[ $ret -gt 127 ] && ret=127
git clean -dxf
exit $ret


It's this:

commit 815f25c6e302f84ecce02c74fa717a19d787f662
Author: Dave Mitchell <davem@fdisolutions.com>
Date:   Sat May 10 02:45:23 2003 +0100

    [perl #7391] Perl crashes with certain write() formats.
    Message-ID: <20030510004523.GC20871@fdgroup.com>
    
    p4raw-id: //depot/perl@19496

diff --git a/pp_ctl.c b/pp_ctl.c
index 91fc2ca..8665678 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -3573,11 +3573,20 @@ S_doparseform(pTHX_ SV *sv)
     U16 *linepc = 0;
     register I32 arg;
     bool ischop;
+    int maxops = 2; /* FF_LINEMARK + FF_END) */
 
     if (len == 0)
 	Perl_croak(aTHX_ "Null picture in formline");
 
-    New(804, fops, (send - s)*3+10, U16);    /* Almost certainly too long... */
+    /* estimate the buffer size needed */
+    for (base = s; s <= send; s++) {
+	if (*s == '\n' || *s == '@' || *s == '^')
+	    maxops += 10;
+    }
+    s = base;
+    base = Nullch;
+
+    New(804, fops, maxops, U16);
     fpc = fops;
 
     if (s < send) {
@@ -3740,6 +3749,7 @@ S_doparseform(pTHX_ SV *sv)
     }
     *fpc++ = FF_END;
 
+    assert (fpc <= fops + maxops); /* ensure our buffer estimate was valid */
     arg = fpc - fops;
     { /* need to jump to the next word */
         int z;



I'm certainly not going to get a chance to look at this for at least 36 hours
(and maybe not even then)

Nicholas Clark

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About