Front page | perl.perl5.porters |
Postings from May 2004
Re: [perl #28938] Bug Report
Thread Previous
From:
Dave Mitchell
Date:
May 3, 2004 11:12
Subject:
Re: [perl #28938] Bug Report
Message ID:
20040503181658.GF1895@iabyn.com
On Wed, Apr 28, 2004 at 03:02:54PM +0100, Steve Hay wrote:
> H.Merijn Brand wrote:
>
> >On Mon 19 Apr 2004 05:18, Keyvan Mohajer (via RT) <perlbug-followup@perl.org> wrote:
> >
> >
> >>The following code generates a "Segmentation fault" in Perl 5.8 but not in
> >>Perl 5.6. Could you please help me?
> >>
> >>##############################################################
> >>#!/usr/bin/perl
> >>
> >>$line=',,,,,,,,,,,,,,';
> >>$title_index=13;
> >>@temp_array=split(/,/,$line);
> >>$new_mark=0;
> >>$temp_array[$title_index]="$temp_array[$title_index]\,$new_mark";
> >>@new_array=[@temp_array];
> >>@new_array=[@temp_array];
> >>##############################################################
Split optimises splitting to an array variable by temporarily switching
the stack to be the actual AV itself. When popping trailing "" elements
off the "stack" (as per the normal split behaviour), the popped slots in
the AV aren't filled with &PL_sv_undef, as would happen with a real array.
Later accesses to these elements finds garbage and freed elements etc.
Fixed in bleedperl by the following change.
Dave.
--
This email is confidential, and now that you have read it you are legally
obliged to shoot yourself. Or shoot a lawyer, if you prefer. If you have
received this email in error, place it in its original wrapping and return
for a full refund. By opening this email, you accept that Elvis lives.
Change 22774 by davem@davem-percy on 2004/05/03 17:44:44
[perl #28938] split could leave an array without &PL_sv_undef
in the unused elements
Affected files ...
... //depot/perl/pp.c#414 edit
... //depot/perl/t/op/split.t#34 edit
Differences ...
==== //depot/perl/pp.c#414 (text) ====
@@ -4636,7 +4636,7 @@
if (TOPs && !make_mortal)
sv_2mortal(TOPs);
iters--;
- SP--;
+ *SP-- = &PL_sv_undef;
}
}
==== //depot/perl/t/op/split.t#34 (xtext) ====
@@ -6,7 +6,7 @@
require './test.pl';
}
-plan tests => 54;
+plan tests => 55;
$FS = ':';
@@ -289,3 +289,16 @@
$n = @a = split /,/,$p;
is ($n, 0, '#21765 - pmreplroot hack used to return undef for 0 iters');
}
+
+{
+ # [perl #28938]
+ # assigning off the end of the array after a split could leave garbage
+ # in the inner elements
+
+ my $x;
+ @a = split /,/, ',,,,,';
+ $a[3]=1;
+ $x = \$a[2];
+ is (ref $x, 'SCALAR', '#28938 - garbage after extend');
+}
+
Thread Previous