nayakgi / perl-compiler

Automatically exported from code.google.com/p/perl-compiler
Other
0 stars 0 forks source link

overload cvrefs overwritten by empty PV #273

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
This runs and passes as it should.
$>perlcc -r -e 'package Foo; use overload; sub import { overload::constant 
"integer" => sub { return shift }}; package main; my $result = eval "5+6"; 
print "$result\n"'
11

But mess with %INC and call use and you get:
$>perlcc -r -e 'package Foo; use overload; sub import { overload::constant 
"integer" => sub { return shift }}; package main; BEGIN { $INC{"Foo.pm"} = 
"/lib/Foo.pm" }; use Foo; my $result = eval "5+6"; print "$result\n"'

Attempt to free unreferenced scalar: SV 0x84f50f8.

I'm struggling to reduce this one further.

Original issue reported on code.google.com by todd.e.rinaldo on 23 Jan 2014 at 10:19

GoogleCodeExporter commented 9 years ago

Original comment by todd.e.rinaldo on 31 Jan 2014 at 12:39

GoogleCodeExporter commented 9 years ago

Original comment by todd.e.rinaldo on 31 Jan 2014 at 12:40

GoogleCodeExporter commented 9 years ago

Original comment by reini.urban on 31 Jan 2014 at 8:44

GoogleCodeExporter commented 9 years ago
SV 0x84f50f8 is the integer hash value (with h magic) for the magically 
attached hintseval hash (H magic).

H{integer} = \&Foo::__ANON__

#0  Perl_sv_free (sv=0xb82e00) at sv.c:6439
#1  0x000000000066a61a in Perl_sv_clear (orig_sv=0xb48e28 <sv_list+168>) at 
sv.c:6281
#2  0x000000000066b63e in Perl_sv_free2 (sv=0xb48e28 <sv_list+168>) at sv.c:6474
#3  0x00000000005fb454 in Perl_hv_free_ent (hv=0xb48d98 <sv_list+24>, 
entry=0xb703b0) at hv.c:1468
#4  0x00000000005fe0d5 in S_hfreeentries (hv=0xb48d98 <sv_list+24>) at hv.c:1786
#5  0x00000000005fe68d in Perl_hv_undef_flags (hv=0xb48d98 <sv_list+24>, 
flags=2) at hv.c:1873
#6  0x000000000066935d in Perl_sv_clear (orig_sv=0xb48d98 <sv_list+24>) at 
sv.c:6125
#7  0x000000000066b63e in Perl_sv_free2 (sv=0xb48d98 <sv_list+24>) at sv.c:6474
#8  0x00000000004c8bdc in Perl_op_clear (o=0xb222b0 <svop_list+48>) at op.c:631
#9  0x00000000004c8858 in Perl_op_free (o=0xb222b0 <svop_list+48>) at op.c:528
#10 0x00000000004c87eb in Perl_op_free (o=0xaf6ff0 <unop_list+48>) at op.c:508
#11 0x00000000004c87eb in Perl_op_free (o=0xb0d0a0 <binop_list>) at op.c:508
#12 0x00000000004c87eb in Perl_op_free (o=0xb1a760 <listop_list>) at op.c:508
#13 0x00000000004f15c3 in perl_destruct (my_perl=0xb64010) at perl.c:751
#14 0x00000000004c7918 in my_perl_destruct ()
#15 0x00000000004c7fc5 in main ()

The problem is a wrong pv slot for the rv (sv_list[7])

    SvRV_set(&sv_list[7], (SV*)&sv_list[2]);
    //sv_list[7].sv_u.svu_pv = savepvn("", 0); //error
    hek1 = share_hek("integer", 7, 0);
    sv_list[8].sv_u.svu_pv = HEK_KEY(hek1);
    sv_magic((SV*)&sv_list[7], (SV*)0, 'h', (char *)&sv_list[8], -2);

Original comment by reini.urban on 31 Jan 2014 at 9:02

GoogleCodeExporter commented 9 years ago
Fixed with 1.43_07 branch overload-i273
but this caused some regressions: #159, #232, #24, ...

commit 01e3367c91e1345f61e5fb1a691915cbd027cfea
Author: Reini Urban <rurban@cpanel.net>
Date:   Fri Jan 31 15:09:23 2014 -0600

    1.43_07:  Fix PVMG PV overwriting the RV, overload sub (#273)

    A PVMG RV (ref) to a an attached overload sub was overwritten by an
    empty PV. This also caused a "Attempt to free unreferenced scalar: SV"
    Added t/issue273.t

Original comment by reini.urban on 31 Jan 2014 at 9:14

GoogleCodeExporter commented 9 years ago

Original comment by reini.urban on 31 Jan 2014 at 9:15

GoogleCodeExporter commented 9 years ago
Fixed the regressions with commit 3ce6b0947c54683879e00cedb88a89705812e2c6
Author: Reini Urban <rurban@cpanel.net>
Date:   Fri Jan 31 15:23:40 2014 -0600

    #273: fix various regressions

    #159, 259, ...
    set $static on an ROK slot in any save_pv_or_rv, so that the RV is not
    overwritten by the PV

Original comment by reini.urban on 31 Jan 2014 at 9:25

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
With 5.20 we get now a Perl_croak_no_modify caused by   
    SvREADONLY_on((HV*)&sv_list[88]);
        sv_magic((SV*)(HV*)&sv_list[88], (SV*)0, 'H', 0, 0);
over the OVERLOAD %arg lexical hash (a readonly padop)
which needs to be reversed.

Original comment by reini.urban on 4 Jun 2014 at 8:19

GoogleCodeExporter commented 9 years ago
5.20 READONLY magic hashes fixed by 

commit 806c0a96d076a2875e1a4c1449410063406fd921
Author: Reini Urban <rurban@cpanel.net>
Date:   Wed Jun 4 15:25:19 2014 -0500

    C: fix READONLY hashes >5.20 #273

    need to call SvREADONLY_on after sv_magic, otherwise we get
    a Perl_croak_no_modify().
    This scenario only appears since 5.20 with restricted hashes being more
    aggressively READONLY.

Original comment by reini.urban on 4 Jun 2014 at 8:27