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

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

Thread Previous | Thread Next
From:
Tony Cook via RT
Date:
March 24, 2014 04:15
Subject:
[perl #121366] valgrind errors in t/op/vec.t
Message ID:
rt-4.0.18-8700-1395634544-1625.121366-15-0@perl.org
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

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