Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

warning: perl bug in 5.6.x, Win32 (use warnings and STDERR)

by dada (Chaplain)
on Mar 21, 2003 at 10:43 UTC ( #244826=perlmeditation: print w/replies, xml ) Need Help??

yesterday dree stumbled upon what seems a really nasty bug in perl 5.6.x on Win32, so I'm posting this hoping that it can avoid some headache to someone in the (near) future.

note that this seems to have been fixed in perl 5.8.0, so read this only if you have not upgraded (yet)!

the bug appears when you use warnings and close STDERR (which is not a meaningful thing to do, but nonetheless...) and it causes the readline operator (eg. <STDIN>) to only read the first line of a file.

AFFECTED PLATFORMS

first of all, these are the test reports I could gather so far:

OS Perl build Buggy
Windows 2000 Pro, XP Pro v5.6.0 built for MSWin32-x86-multi-thread YES
Windows 2000 Pro, XP Pro v5.6.1 built for MSWin32-x86-multi-thread YES
Windows 2000 Pro, XP Pro v5.6.1 built for cygwin-multi NO
Windows 2000 Pro v5.8.0 built for MSWin32-x86-multi-thread NO
Red Hat Linux release 7.0 (Guinness) v5.6.0 built for i386-linux NO
Red Hat Linux release 7.0 (Guinness) v5.8.0 built for i586-linux-thread-multi-ld NO

summing this up, the bug seems to show only on Win32 with Perl 5.6.0 and 5.6.1 (but not with Cygwin).

DESCRIPTION

this is the exploitation script (I called it dree.pl):
use warnings; close(STDERR); open(ME, "$0"); while (<ME>) { print; } close ME;
if you run it as it is, it will read (and thus print) only the first line of the file.

if you comment either the first line (use warnings) or the second line (close(STDERR)), the whole file is printed fine.

SUMMARY

if you mysteriously fail to read more than one line from a file, make sure that the following two conditions aren't both met:
  • use warnings
  • STDERR is closed

cheers,
Aldo

King of Laziness, Wizard of Impatience, Lord of Hubris

Replies are listed 'Best First'.
Re: warning: perl bug in 5.6.x, Win32 (use warnings and STDERR)
by crazyinsomniac (Prior) on Mar 21, 2003 at 11:28 UTC

      I tried to play with this a little more. It only prints the first line even if you remove the use warnings and run the script with perl -w or if you set the $^W.

      close(STDERR); open(ME, "$0"); $^W=1; while (<ME>) { print; } close ME;

      It fails even if you put the $^W=1; inside the loop, but you always have to close the STDERR before opening the file.

      Jenda
      Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
         -- Rick Osborne

Re: warning: perl bug in 5.6.x, Win32 (use warnings and STDERR)
by Mr. Muskrat (Canon) on Mar 21, 2003 at 17:33 UTC
    Windows 98 (FE) with AS v5.6.1 build 633 built for MSWin32-x86-multi-thread is also affected.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://244826]
Approved by Corion
Front-paged by diotalevi
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2022-05-19 03:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (71 votes). Check out past polls.

    Notices?