From: Frank Seitz on
Hi!

#!/usr/bin/perl

use strict;
use warnings;

my $stderr;
close STDERR;
open STDERR,'>',\$stderr or die;
warn "a\n";
$stderr =~ s/./xx/g;

# eof

$ ./test.pl
Segmentation fault

What is the problem?

$ perl -v
This is perl, v5.10.1 (*) built for i686-linux

Frank
--
Dipl.-Inform. Frank Seitz
Anwendungen f�r Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel

Blog: http://www.fseitz.de/blog
XING-Profil: http://www.xing.com/profile/Frank_Seitz2
From: Ben Morrow on

Quoth Frank Seitz <devnull4711(a)web.de>:
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> my $stderr;
> close STDERR;
> open STDERR,'>',\$stderr or die;
> warn "a\n";
> $stderr =~ s/./xx/g;
>
> # eof
>
> $ ./test.pl
> Segmentation fault
>
> What is the problem?
>
> $ perl -v
> This is perl, v5.10.1 (*) built for i686-linux

It's a bug in perl, but it appears to have been fixed in blead. The fix
will be in 5.10.0, and probably in 5.10.2 if there ever is one
(currently it's looking unlikely).

Ben

From: C.DeRykus on
On Mar 4, 4:22 pm, Frank Seitz <devnull4...(a)web.de> wrote:
> Hi!
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> my $stderr;
> close STDERR;
> open STDERR,'>',\$stderr or die;
> warn "a\n";
> $stderr =~ s/./xx/g;
>
> # eof
>
> $ ./test.pl
> Segmentation fault
>
> What is the problem?
>
> $ perl -v
> This is perl, v5.10.1 (*) built for i686-linux
>

A bug? The trailing \n appears to be problematic.

Possible workaround:

$stderr =~ s/[^\n]/xx/g;

This is perl, v5.10.1 (*) built for MSWin32-x86-multi-thread

--
Charles DeRykus
From: sln on
On Fri, 05 Mar 2010 01:22:02 +0100, Frank Seitz <devnull4711(a)web.de> wrote:

>Hi!
>
>#!/usr/bin/perl
>
>use strict;
>use warnings;
>
>my $stderr;
>close STDERR;
>open STDERR,'>',\$stderr or die;
>warn "a\n";
>$stderr =~ s/./xx/g;
>
># eof
>
>$ ./test.pl
>Segmentation fault
>
>What is the problem?
>
>$ perl -v
>This is perl, v5.10.1 (*) built for i686-linux
>
>Frank

If $stderr =~ s/./xx/sg; it seems to work.
But, obviously some independent FILE buffering going on here,
and its out of sync with the scalar buffer.
Notice, even after $stderr is cleared of 'ab', ' b'
shows back up after a FILE write:

---------------------
use strict;
use warnings;

my $stderr;
close STDERR;
open STDERR,'>',\$stderr or die;

print STDERR "ab";
print "length \$stderr = ",length($stderr), " '$stderr'\n";
print "tell (STDERR) = ", tell(STDERR),"\n";

print "\n";
$stderr = '';
print "length \$stderr = ",length($stderr), " '$stderr'\n";

print "\n";
print STDERR "ZSSS";
print "length \$stderr = ",length($stderr), " '$stderr'\n";
print "tell (STDERR) = ", tell(STDERR),"\n";

__END__


length $stderr = 2 'ab'
tell (STDERR) = 2

length $stderr = 0 ''

length $stderr = 6 ' bZSSS'
tell (STDERR) = 6

-sln
From: Ben Morrow on

Quoth "C.DeRykus" <derykus(a)gmail.com>:
> On Mar 4, 4:22�pm, Frank Seitz <devnull4...(a)web.de> wrote:
> >
> > #!/usr/bin/perl
> >
> > use strict;
> > use warnings;
> >
> > my $stderr;
> > close STDERR;
> > open STDERR,'>',\$stderr or die;
> > warn "a\n";
> > $stderr =~ s/./xx/g;
> >
> > # eof
> >
> > $ ./test.pl
> > Segmentation fault
> >
> > What is the problem?
> >
> > $ perl -v
> > This is perl, v5.10.1 (*) built for i686-linux
> >
>
> A bug? The trailing \n appears to be problematic.
>
> Possible workaround:
>
> $stderr =~ s/[^\n]/xx/g;
>
> This is perl, v5.10.1 (*) built for MSWin32-x86-multi-thread

With 5.10.1 for i386-freebsd I can reproduce the bug without the
newline, but only if I use a one-liner:

~% perl ioscseg
~% perl -e"$(<ioscseg)"
Segmentation fault (core dumped)
~%

The crash appears to be in the same place as before, so I presume it's
just somewhat allocation-dependant.

Ben