Skip Menu |
Report information
Id: 125115
Status: resolved
Priority: 0/
Queue: perl5

Owner: Nobody
Requestors: knut.arne.bjorndal [at] easyconnect.no
Cc:
AdminCc:

Operating System: Linux
PatchStatus: (no value)
Severity: low
Type: core
Perl Version: 5.14.2
Fixed In: (no value)



From: Knut Arne Bjørndal <knut.arne.bjorndal [...] easyconnect.no>
Date: Wed, 06 May 2015 13:02:07 +0200
To: perlbug [...] perl.org
Subject: Dup to closed filehandle creates file named GLOB(0x...)
Download (untitled) / with headers
text/plain 14.7k

Message body is not shown because it is too large.

RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 389b
On Wed May 06 04:03:02 2015, knut.arne.bjorndal@easyconnect.no wrote: Show quoted text
> close STDOUT; > open( my $foo, ">&", \*STDOUT) or die $!; > > Expected result: die 'Bad file descriptor' > > What happened: A file named GLOB(0xe52b90) is created, and any output > written to $foo goes there. > > This has also been tested with 5.20.2 and 5.21.11 built with perlbrew.
Try the attached patch. Tony
Subject: 0001-perl-125115-don-t-create-file-GLOB-.-when-dupping-a-.patch
From 39bf7e431534e42c3210ad15d03142b15e3e3207 Mon Sep 17 00:00:00 2001 From: Tony Cook <tony@develop-help.com> Date: Thu, 7 May 2015 12:13:36 +1000 Subject: [PATCH] [perl #125115] don't create file GLOB(...) when dupping a closed handle This needs tests. --- doio.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/doio.c b/doio.c index 5f29a6b..2630252 100644 --- a/doio.c +++ b/doio.c @@ -438,8 +438,11 @@ Perl_do_open6(pTHX_ GV *gv, const char *oname, STRLEN len, else if (IoTYPE(thatio) == IoTYPE_SOCKET) IoTYPE(io) = IoTYPE_SOCKET; } - else - wanted_fd = -1; + else { + SETERRNO(EBADF, RMS_IFI); + fp = NULL; + goto say_false; + } } if (!num_svs) type = NULL; -- 1.7.10.4
To: perlbug-followup [...] perl.org
From: Knut Arne Bjørndal <knut.arne.bjorndal [...] easyconnect.no>
Date: Thu, 07 May 2015 10:55:20 +0200
Subject: Re: [perl #125115] Dup to closed filehandle creates file named GLOB(0x...)
Download (untitled) / with headers
text/plain 692b
On 07/05/15 04:14, Tony Cook via RT wrote: Show quoted text
> On Wed May 06 04:03:02 2015, knut.arne.bjorndal@easyconnect.no wrote:
>> close STDOUT; >> open( my $foo, ">&", \*STDOUT) or die $!; >> >> Expected result: die 'Bad file descriptor' >> >> What happened: A file named GLOB(0xe52b90) is created, and any output >> written to $foo goes there. >> >> This has also been tested with 5.20.2 and 5.21.11 built with perlbrew.
> > Try the attached patch.
Seems to work fine. I've tested both some isolated examples of this problem as well as a codebase that does a fair amount of IO redirection. -- Knut Arne Bjørndal, Tekniker Easy Connect AS - http://1890.no E-post: knut.arne.bjorndal@easyconnect.no
Download signature.asc
application/pgp-signature 198b

Message body not shown because it is not plain text.

RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 779b
On Thu May 07 09:02:04 2015, knut.arne.bjorndal@easyconnect.no wrote: Show quoted text
> On 07/05/15 04:14, Tony Cook via RT wrote:
> > On Wed May 06 04:03:02 2015, knut.arne.bjorndal@easyconnect.no wrote:
> >> close STDOUT; > >> open( my $foo, ">&", \*STDOUT) or die $!; > >> > >> Expected result: die 'Bad file descriptor' > >> > >> What happened: A file named GLOB(0xe52b90) is created, and any output > >> written to $foo goes there. > >> > >> This has also been tested with 5.20.2 and 5.21.11 built with perlbrew.
> > > > Try the attached patch.
> > Seems to work fine. I've tested both some isolated examples of this > problem as well as a codebase that does a fair amount of IO redirection. >
Thanks, I've attached a version with a test, which will go in once 5.22 is released. Tony
Subject: 0001-perl-125115-don-t-create-file-GLOB-.-when-dupping-a-.patch
From 6ca26df979d733f3c9eadca6141ee685955b9dad Mon Sep 17 00:00:00 2001 From: Tony Cook <tony@develop-help.com> Date: Tue, 26 May 2015 16:03:31 +1000 Subject: [PATCH] [perl #125115] don't create file GLOB(...) when dupping a closed handle --- doio.c | 7 +++++-- t/io/open.t | 10 +++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/doio.c b/doio.c index 5f29a6b..2630252 100644 --- a/doio.c +++ b/doio.c @@ -438,8 +438,11 @@ Perl_do_open6(pTHX_ GV *gv, const char *oname, STRLEN len, else if (IoTYPE(thatio) == IoTYPE_SOCKET) IoTYPE(io) = IoTYPE_SOCKET; } - else - wanted_fd = -1; + else { + SETERRNO(EBADF, RMS_IFI); + fp = NULL; + goto say_false; + } } if (!num_svs) type = NULL; diff --git a/t/io/open.t b/t/io/open.t index 3817bdd..cffef14 100644 --- a/t/io/open.t +++ b/t/io/open.t @@ -10,7 +10,7 @@ $| = 1; use warnings; use Config; -plan tests => 153; +plan tests => 156; my $Perl = which_perl(); @@ -476,6 +476,14 @@ pass("no crash when open autovivifies glob in freed package"); is((stat $temp)[9], $final_mtime, "nothing changes its mtime"); } +# [perl #125115] Dup to closed filehandle creates file named GLOB(0x...) +{ + ok(open(my $fh, "<", "TEST"), "open a handle"); + ok(close $fh, "and close it again"); + ok(!open(my $fh2, ">&", $fh), "should fail to dup the closed handle"); + # clean up if we failed + unlink "$fh"; +} package OverloadTest; use overload '""' => sub { ${$_[0]} }; -- 1.7.10.4
RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 192b
On Mon May 25 23:04:54 2015, tonyc wrote: Show quoted text
> Thanks, I've attached a version with a test, which will go in once > 5.22 is released.
Applied as 0c9375a5ca42fadd4d631bf07a8dd4d8f7814d34. Tony
Download (untitled) / with headers
text/plain 252b
Thank you for submitting this report. You have helped make Perl better. With the release of Perl 5.24.0 on May 9, 2016, this and 149 other issues have been resolved. Perl 5.24.0 may be downloaded via https://metacpan.org/release/RJBS/perl-5.24.0


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org