Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: 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


In reply to warning: perl bug in 5.6.x, Win32 (use warnings and STDERR) by dada

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-25 22:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found