From 10cea94582148cd5bcccfa2723247332e1743303 Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Wed, 1 Sep 2010 03:00:38 +0200 Subject: [PATCH] [perl #77492] open $fh, ">", \*glob causes SEGV PerlIO_layer_from_ref must not treat a real glob as a scalar. This function was not updated when SVt_PVGV was moved before SVt_PVLV. --- perlio.c | 2 +- t/io/open.t | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/perlio.c b/perlio.c index 5df704e..c83b2bb 100644 --- a/perlio.c +++ b/perlio.c @@ -1449,7 +1449,7 @@ PerlIO_layer_from_ref(pTHX_ SV *sv) /* * For any scalar type load the handler which is bundled with perl */ - if (SvTYPE(sv) < SVt_PVAV) { + if (SvTYPE(sv) < SVt_PVAV && !isGV_with_GP(sv)) { PerlIO_funcs *f = PerlIO_find_layer(aTHX_ STR_WITH_LEN("scalar"), 1); /* This isn't supposed to happen, since PerlIO::scalar is core, * but could happen anyway in smaller installs or with PAR */ diff --git a/t/io/open.t b/t/io/open.t index 443aab3..01bfaca 100644 --- a/t/io/open.t +++ b/t/io/open.t @@ -10,7 +10,7 @@ $| = 1; use warnings; use Config; -plan tests => 109; +plan tests => 110; my $Perl = which_perl(); @@ -324,3 +324,16 @@ like($@, qr/Modification of a read-only value attempted/, "readonly fh"); ok( open(my $f, '-|', $p), 'open -| magic'); } + +# [perl #77492] Crash when stringifying a glob, a reference to which has +# been opened and written to. +fresh_perl_is( + ' + open my $fh, ">", \*STDOUT; + print $fh "hello"; + "".*STDOUT; + print "ok"; + unlink \*STDOUT; + ', + 'ok', { stderr => 1 }, + '[perl #77492]: open $fh, ">", \*glob causes SEGV'); -- 1.8.3.1