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

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

Thread Previous
From:
Brian Fraser
Date:
March 25, 2014 09:04
Subject:
Re: [perl #121366] valgrind errors in t/op/vec.t
Message ID:
CA+nL+nagYWHFq3oyUZ9HVugAEMsnecMwP2j=v_FDtkFDrEgNjA@mail.gmail.com
On Mon, Mar 24, 2014 at 5:15 AM, Tony Cook via RT
<perlbug-followup@perl.org> 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 */
>
> Tony
>
> ---
> via perlbug:  queue: perl5 status: new
> https://rt.perl.org/Ticket/Display.html?id=121366

Thanks for picking up this, Tony! I haven't been able to get valgrind
or gdb to work on my Mac, so I've been stuck being useless for a
while.

Thread Previous


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