diff options
author | Father Chrysostomos <sprout@cpan.org> | 2012-05-24 23:13:37 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2012-06-07 08:18:52 -0700 |
commit | f90b723246c15bceccd726b73c412184c27eca7d (patch) | |
tree | 232ebb7140be05ec5b66e575c6975dd6e5341ed2 /doio.c | |
parent | 1e00d6e92a9b49086ba010b4c50b9362ce8f2caa (diff) | |
download | perl-f90b723246c15bceccd726b73c412184c27eca7d.tar.gz |
Make open(... "<&", $fileno) respect magic
A magical variable is never SvPOK, but only SvPOKp. The code for
checking whether a duplicatee is a numeric file descriptor was only
checking SvPOK. So a regular variable containing a fileno-as-a-string
would work, such as the $a below, as would a stringified magical vari-
able ("$1"), but not $1 itself.
$ echo foo | perl -le '$a = "0"; open a, "<&", $a; warn <a>'
foo
$ echo foo | perl -le '"0" =~ /(.)/; open a, "<&", $1; warn <a>'
Can't use an undefined value as filehandle reference at -e line 1.
$ echo foo | perl -le '"0" =~ /(.)/; open a, "<&", "$1"; warn <a>'
foo
SvPOK variables are also SvPOKp, so checking only the latter suffices.
Diffstat (limited to 'doio.c')
-rw-r--r-- | doio.c | 5 |
1 files changed, 4 insertions, 1 deletions
@@ -320,7 +320,10 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, } while (isSPACE(*type)) type++; - if (num_svs && (SvIOK(*svp) || (SvPOK(*svp) && looks_like_number(*svp)))) { + if (num_svs && ( + SvIOK(*svp) + || (SvPOKp(*svp) && looks_like_number(*svp)) + )) { fd = SvUV(*svp); num_svs = 0; } |