develooper Front page | perl.perl5.porters | Postings from March 2014

[perl #121366] valgrind errors in t/op/vec.t

Thread Previous | Thread Next
From:
Shlomi Fish via RT
Date:
March 25, 2014 08:24
Subject:
[perl #121366] valgrind errors in t/op/vec.t
Message ID:
rt-4.0.18-32301-1395735872-1947.121366-15-0@perl.org
On Sun Mar 23 21:15:44 2014, tonyc wrote:
> On Mon Mar 03 11:28:21 2014, khw wrote:
> > A bisect yields this:
> >
> > 032061d233a4bb16c1677ef64615bdb15de5b8a1 is the first bad commit
> >  commit 032061d233a4bb16c1677ef64615bdb15de5b8a1
> >  Author: Brian Fraser <fraserbn@gmail.com>
> >  Date:   Sat May 26 17:35:26 2012 -0300
> 
> This is happening when using vec() to modify an undef sv, eg:
> 
> $ valgrind -q ./perl -e 'vec($Foo, 0, 1) = 1'
> ==814== Conditional jump or move depends on uninitialised value(s)
> ==814==    at 0x5190C7: Perl_sv_pvn_force_flags (sv.c:9505)
> ==814==    by 0x580C9B: Perl_do_vecset (doop.c:927)
> ==814==    by 0x4D30AD: Perl_magic_setvec (mg.c:2305)
> ==814==    by 0x4CE522: Perl_mg_set (mg.c:279)
> ==814==    by 0x4EB417: Perl_pp_sassign (pp_hot.c:223)
> ==814==    by 0x4C42C9: Perl_runops_debug (dump.c:2425)
> ==814==    by 0x44BEC4: perl_run (perl.c:2449)
> ==814==    by 0x422934: main (perlmain.c:112)
>  ==814==
> 
> The error is on this line:
> 
> >>> if (s != SvPVX_const(sv)) {     /* Almost, but not quite,
> >>> sv_setpvn() */
> if (SvROK(sv))
>     sv_unref(sv);
> 
> where we examine sv->sv_u.svu_pv when it hasn't been initialized yet.
> 
> The following change prevents the error and passes all tests
> (DEBUGGING):
> 
> diff --git a/sv.c b/sv.c
> index dcb1d5e..4742c7d 100644
> --- a/sv.c
> +++ b/sv.c
>  @@ -9502,7 +9502,8 @@ Perl_sv_pvn_force_flags(pTHX_ SV *const sv,
> STRLEN *const
>         if (lp)
>             *lp = len;
> 
> -       if (s != SvPVX_const(sv)) {     /* Almost, but not quite,
> sv_setpvn() */
> +       if (SvTYPE(sv) < SVt_PV ||
> +            s != SvPVX_const(sv)) {    /* Almost, but not quite,
> sv_setpvn() */
>             if (SvROK(sv))
>                 sv_unref(sv);
>             SvUPGRADE(sv, SVt_PV);              /* Never FALSE */
> 

I wanted to test your patch but could not because it didn't apply cleanly using "patch -p1 < …". The problem seems to be that it is all whitespace, while the sources use a mixture of tabs and spaces. I can apply it manually and provide a new patch, but shouldn't the patch be attached?

Regards,

-- Shlomi Fish


---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=121366

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