Subject: | segv on fd dup-ed as read instead of write |
Date: | Sat, 07 Mar 2009 10:52:25 +1100 |
To: | bug-Term-Size [...] rt.cpan.org |
From: | Kevin Ryde <user42 [...] zip.com.au> |
With Term::Size 0.207 and debian i386 perl 5.10.0, the following program
gets a segv in Term::Size::chars.
use strict;
use warnings;
use Term::Size;
open my $fh, '<', '/dev/null' or die;
my $fd = fileno($fh);
open my $dup, '>&', $fd or die;
print Term::Size::chars($dup);
It looks like the typemap stuff for "FILE*" gives NULL if you pass a
handle like $dup which is a dup-for-write of an fd which was readonly.
Calling fileno() on NULL of course then bombs.
Obviously this is not something you'd do deliberately, but if it happens
by accident, as it did for me, it'd be good if it didn't seg fault.
I imagine going natively to PerlIO* per my ticket 38594 would help avoid
this sort of FILE* coercion strangeness.