Skip to content

Commit

Permalink
[perl #121366] avoid using an invalid SvPVX() in Perl_sv_pvn_force_flags
Browse files Browse the repository at this point in the history
This would cause valgrind to complain about:

  vec($Foo, 0, 1) = 1; # for example

when $Foo was undef, since SvPVX()[1] isn't initialized until the SV is
at least a SVt_PV.

[1] well, sv_u.svu_rv, but sv_u is a union, so the same memory is
initialized.  This isn't technically legal from a C point of view,
but pointer types are compatible enough with each other for it to not
be an issue.
  • Loading branch information
tonycoz committed Mar 26, 2014
1 parent a8509e9 commit e141190
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion sv.c
Expand Up @@ -9502,7 +9502,8 @@ Perl_sv_pvn_force_flags(pTHX_ SV *const sv, STRLEN *const lp, const I32 flags)
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 */
Expand Down

0 comments on commit e141190

Please sign in to comment.