develooper Front page | perl.perl5.porters | Postings from September 2016

[perl #129183] perl -S erroneously allows \ escapes in PATH

Thread Next
From:
Father Chrysostomos
Date:
September 3, 2016 05:28
Subject:
[perl #129183] perl -S erroneously allows \ escapes in PATH
Message ID:
rt-4.0.24-29978-1472880485-91.129183-75-0@perl.org
# New Ticket Created by  Father Chrysostomos 
# Please include the string:  [perl #129183]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=129183 >


On Unix, entries in PATH are separated by : and may validly contain backslashes.  ‘perl -S’ erroneously 

To demonstrate:

$ mkdir ~/'\'
$ cat > ~/'\'/foo
#!/usr/bin/perl
print "Hahaha!\n";
^D
$ chmod +x ~/'\'/foo
$ PATH=~/'\':$PATH foo
Hahaha!
$ PATH=~/'\':$PATH perl -S foo
Can't find foo on PATH.
$ echo $PATH
/Users/sprout/\:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/bin

perl is reading the initial ‘/Users/sprout/\:/usr/bin’ as one PATH entry, which is wrong.

The Perl_find_script function in util.c uses delimcpy to find the colon.  delimcpy allows the terminator to be escaped, which is inappropriate for this call site.

-- 

Father Chrysostomos


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About