From: Father Chrysostomos Date: Thu, 24 Nov 2011 04:26:51 +0000 (-0800) Subject: sysread should not ignore magic on its buffer X-Git-Tag: accepted/trunk/20130322.191538~1973 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e37d6bdb385bdcf32a72bdde366106ee4c503bfe;p=platform%2Fupstream%2Fperl.git sysread should not ignore magic on its buffer sysread uses SvPV_force, which has a bug in it. Even if the SV_GMAGIC flag is passed to sv_pvn_force_flags (which SvPV_force does), it ignores magic in any typeglob argument. --- diff --git a/sv.c b/sv.c index b8f0b10..31bda3b 100644 --- a/sv.c +++ b/sv.c @@ -9014,6 +9014,7 @@ Perl_sv_pvn_force_flags(pTHX_ SV *const sv, STRLEN *const lp, const I32 flags) PERL_ARGS_ASSERT_SV_PVN_FORCE_FLAGS; + if (flags & SV_GMAGIC) SvGETMAGIC(sv); if (SvTHINKFIRST(sv) && !SvROK(sv)) sv_force_normal_flags(sv, 0); @@ -9038,7 +9039,7 @@ Perl_sv_pvn_force_flags(pTHX_ SV *const sv, STRLEN *const lp, const I32 flags) /* diag_listed_as: Can't coerce %s to %s in %s */ Perl_croak(aTHX_ "Can't coerce %s to string in %s", sv_reftype(sv,0), OP_DESC(PL_op)); - s = sv_2pv_flags(sv, &len, flags); + s = sv_2pv_flags(sv, &len, flags &~ SV_GMAGIC); if (lp) *lp = len; diff --git a/t/op/gmagic.t b/t/op/gmagic.t index daebae4..c502052 100644 --- a/t/op/gmagic.t +++ b/t/op/gmagic.t @@ -61,6 +61,30 @@ $c = bless [], o::; chomp $c; expected_tie_calls(tied $c, 1, 2, 'chomping a ref'); +{ + my $outfile = tempfile(); + open my $h, ">$outfile" or die "$0 cannot close $outfile: $!"; + print $h "bar\n"; + close $h or die "$0 cannot close $outfile: $!"; + + $c = *foo; # 1 write + open $h, $outfile; + sysread $h, $c, 3, 7; # 1 read; 1 write + is $c, "*main::bar", 'what sysread wrote'; # 1 read + expected_tie_calls(tied $c, 2, 2, 'calling sysread with tied buf'); + close $h or die "$0 cannot close $outfile: $!"; + + # Do this again, with a utf8 handle + $c = *finish; # 1 write + open $h, "<:utf8", $outfile; + sysread $h, $c, 3, 7; # 1 read; 1 write + is $c, "*main::bar", 'what sysread wrote'; # 1 read + expected_tie_calls(tied $c, 2, 2, 'calling sysread with tied buf'); + close $h or die "$0 cannot close $outfile: $!"; + + unlink_all $outfile; +} + # autovivication of aelem, helem, of rv2sv combined with get-magic { my $true = 1;