Skip Menu |

This queue is for tickets about the FileHandle-Fmode CPAN distribution.

Report information
The Basics
Id: 79983
Status: resolved
Priority: 0/
Queue: FileHandle-Fmode

People
Owner: Nobody in particular
Requestors: djerius [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.11
Fixed in: (no value)



Subject: is_arg_ok modifies the global $_, which causes action at a distance errors
The is_arg_ok function has the following code:

    eval{$_ = fileno($_[0]);};

which modifies the global $_, resulting in strange and mysterious errors elsewhere.

Attached is a patch which fixes this, and also reduces the number of times that fileno is called.


Subject: FileHandle-Fmode-0.11.patch
# This is a patch for FileHandle-Fmode-0.11.orig to update it to FileHandle-Fmode-0.11 # # To apply this patch: # STEP 1: Chdir to the source directory. # STEP 2: Run the 'applypatch' program with this patch file as input. # # If you do not have 'applypatch', it is part of the 'makepatch' package # that you can fetch from the Comprehensive Perl Archive Network: # http://www.perl.com/CPAN/authors/Johan_Vromans/makepatch-x.y.tar.gz # In the above URL, 'x' should be 2 or higher. # # To apply this patch without the use of 'applypatch': # STEP 1: Chdir to the source directory. # STEP 2: Run the 'patch' program with this file as input. # #### End of Preamble #### #### Patch data follows #### diff -c 'FileHandle-Fmode-0.11.orig/Fmode.pm' 'FileHandle-Fmode-0.11/Fmode.pm' Index: ./Fmode.pm *** ./Fmode.pm Fri Sep 26 08:43:20 2008 --- ./Fmode.pm Wed Oct 3 12:03:04 2012 *************** *** 21,30 **** my $is_win32 = $^O =~ /mswin32/i ? 1 : 0; sub is_arg_ok { ! eval{$_ = fileno($_[0]);}; if($@) {return 0} ! if(defined(fileno($_[0]))) { ! if(fileno($_[0]) == -1) { if($] < 5.007) {return 0} return 1; } --- 21,30 ---- my $is_win32 = $^O =~ /mswin32/i ? 1 : 0; sub is_arg_ok { ! my $fileno = eval{fileno($_[0])}; if($@) {return 0} ! if(defined($fileno)) { ! if( $fileno == -1) { if($] < 5.007) {return 0} return 1; } *************** *** 34,41 **** } sub is_RO { ! if(!defined(fileno($_[0]))) {die "Not an open filehandle"} ! if(fileno($_[0]) == -1) { if($] < 5.007) {die "Illegal fileno() return"} if(perliol_readable($_[0]) && !perliol_writable($_[0])) {return 1} return 0; --- 34,42 ---- } sub is_RO { ! my $fileno = fileno($_[0]); ! if(!defined( $fileno)) {die "Not an open filehandle"} ! if( $fileno == -1) { if($] < 5.007) {die "Illegal fileno() return"} if(perliol_readable($_[0]) && !perliol_writable($_[0])) {return 1} return 0; *************** *** 50,57 **** } sub is_WO { ! if(!defined(fileno($_[0]))) {die "Not an open filehandle"} ! if(fileno($_[0]) == -1) { if($] < 5.007) {die "Illegal fileno() return"} if(!perliol_readable($_[0]) && perliol_writable($_[0])) {return 1} return 0; --- 51,59 ---- } sub is_WO { ! my $fileno = fileno($_[0]); ! if(!defined( $fileno)) {die "Not an open filehandle"} ! if( $fileno == -1) { if($] < 5.007) {die "Illegal fileno() return"} if(!perliol_readable($_[0]) && perliol_writable($_[0])) {return 1} return 0; *************** *** 76,83 **** } sub is_RW { ! if(!defined(fileno($_[0]))) {die "Not an open filehandle"} ! if(fileno($_[0]) == -1) { if($] < 5.007) {die "Illegal fileno() return"} if(perliol_readable($_[0]) && perliol_writable($_[0])) {return 1} return 0; --- 78,86 ---- } sub is_RW { ! my $fileno = fileno($_[0]); ! if(!defined($fileno)) {die "Not an open filehandle"} ! if($fileno == -1) { if($] < 5.007) {die "Illegal fileno() return"} if(perliol_readable($_[0]) && perliol_writable($_[0])) {return 1} return 0; *************** *** 92,99 **** } sub is_A { ! if(!defined(fileno($_[0]))) {die "Not an open filehandle"} ! if(fileno($_[0]) == -1) { if($] < 5.007) {die "Illegal fileno() return"} return is_appendable($_[0]); } --- 95,103 ---- } sub is_A { ! my $fileno = fileno($_[0]); ! if(!defined($fileno)) {die "Not an open filehandle"} ! if($fileno == -1) { if($] < 5.007) {die "Illegal fileno() return"} return is_appendable($_[0]); } #### End of Patch data #### #### ApplyPatch data follows #### # Data version : 1.0 # Date generated : Wed Oct 3 12:03:42 2012 # Generated by : makepatch 2.04 # Recurse directories : Yes # Excluded files : (\A|/).*\~\Z # (\A|/).*\.a\Z # (\A|/).*\.bak\Z # (\A|/).*\.BAK\Z # (\A|/).*\.elc\Z # (\A|/).*\.exe\Z # (\A|/).*\.gz\Z # (\A|/).*\.ln\Z # (\A|/).*\.o\Z # (\A|/).*\.obj\Z # (\A|/).*\.olb\Z # (\A|/).*\.old\Z # (\A|/).*\.orig\Z # (\A|/).*\.rej\Z # (\A|/).*\.so\Z # (\A|/).*\.Z\Z # (\A|/)\.del\-.*\Z # (\A|/)\.make\.state\Z # (\A|/)\.nse_depinfo\Z # (\A|/)core\Z # (\A|/)tags\Z # (\A|/)TAGS\Z # p 'Fmode.pm' 6294 1349280184 0100644 #### End of ApplyPatch data #### #### End of Patch kit [created: Wed Oct 3 12:03:42 2012] #### #### Patch checksum: 141 4372 17867 #### #### Checksum: 159 5081 11101 ####
On Wed Oct 03 12:05:27 2012, DJERIUS wrote: Show quoted text
> The is_arg_ok function has the following code: > > eval{$_ = fileno($_[0]);}; > > which modifies the global $_, resulting in strange and mysterious > errors > elsewhere. > > Attached is a patch which fixes this, and also reduces the number of > times that > fileno is called.
(Is there anything cooler than being able to initiate "action at a distance" ? ;-) Looks to be a definite improvement - and released it as 0.12 to cpan. I spent a couple of hours trying to apply the patch programmatically (on Cygwin, Linux, and native Win32) ... to no avail. This is not unusual when downloading stuff thru Windows. In the end, I just made the adjustments manually - which means you might want to check that I *did* get it right in 0.12. Thanks Diab !! Cheers, Rob
Subject: Re: [rt.cpan.org #79983] is_arg_ok modifies the global $_, which causes action at a distance errors
Date: Fri, 05 Oct 2012 09:52:19 -0400
To: bug-FileHandle-Fmode [...] rt.cpan.org
From: Diab Jerius <dj [...] head.cfa.harvard.edu>
On Fri, 2012-10-05 at 06:24 -0400, Sisyphus via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=79983 > > > On Wed Oct 03 12:05:27 2012, DJERIUS wrote:
> > The is_arg_ok function has the following code: > > > > eval{$_ = fileno($_[0]);}; > > > > which modifies the global $_, resulting in strange and mysterious > > errors > > elsewhere. > > > > Attached is a patch which fixes this, and also reduces the number of > > times that > > fileno is called.
> > (Is there anything cooler than being able to initiate "action at a > distance" ? ;-)
Yes (well, unless you're on the receiving end. One of the those darkly lit corners of Perl...) Show quoted text
> > Looks to be a definite improvement - and released it as 0.12 to cpan. > > I spent a couple of hours trying to apply the patch programmatically (on > Cygwin, Linux, and native Win32) ... to no avail.
Does applypatch (from CPAN's makepatch distributino) do it right? One of the reasons that I generate patches using makepatch is in the hopes that it is more platform agnostic (that, and it can create, delete, and retain file permissions). Show quoted text
> This is not unusual when downloading stuff thru Windows. > In the end, I just made the adjustments manually - which means you might > want to check that I *did* get it right in 0.12.
Will do, Thanks for the quick reply. Diab
On Fri Oct 05 06:24:10 2012, SISYPHUS wrote:
Show quoted text
>
> In the end, I just made the adjustments manually - which means you might
> want to check that I *did* get it right in 0.12.
>

Everything looks fine.

On Fri Oct 05 09:52:35 2012, dj@head.cfa.harvard.edu wrote: Show quoted text
> Does applypatch (from CPAN's makepatch distributino) do it right?
I think it's ok. The problem is in getting the checksum, bytecount and linecount figures to match up. This can be a bit tricky when you download everything using Windows. I finally got it to apply ok by transferring the FH-F-0.11 source tarball to Linux (in binmode) and then unpacking it on the Linux box. Then transfer the patch from Windows to Linux (in binmode). Works fine, then. It's probably do-able on the Windows box by using dos2unix and/or unix2dos on Fmode.pm and/or FileHandle-Fmode-0.11.patch, but I haven't managed to get it right, yet. (Haven't really had time to set about performing the task in an orderly fashion on Windows ... but I'll try to get it sorted out when I *do* have the time.) Cheers, Rob
Rob, I forgot to reply; all seems ok. Diab