Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[perl #61362] bug report: "perl -c foo" always reports "foo syntax OK" if foo is a directory

6 views
Skip to first unread message

Ben Crowell

unread,
Dec 14, 2008, 2:30:30 PM12/14/08
to bugs-bi...@netlabs.develooper.com
# New Ticket Created by Ben Crowell
# Please include the string: [perl #61362]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=61362 >


Hi,

I'd like to report a bug in perl, which is that if foo is a directory,
"perl -c foo" always responds with "foo syntax OK." (The most common
way this comes up is if you have a program foo that lives in a directory
called foo, so you intended "perl -c foo/foo," but accidentally did
"perl -c foo" instead.)

Regards,

Ben

-------------------------------
output of perl -V
-------------------------------
Summary of my perl5 (revision 5 version 10 subversion 0) configuration:
Platform:
osname=linux, osvers=2.6.24-15-server, archname=x86_64-linux-gnu-thread-multi
uname='linux crested 2.6.24-15-server #1 smp mon apr 7 17:10:32 utc 2008 x86_64 gnulinux '
config_args='-Dusethreads -Duselargefiles -Dccflags=-DDEBIAN -Dcccdlflags=-fPIC -Darchname=x86_64-linux-gnu -Dprefix=/usr -Dprivlib=/usr/share/perl/5.10 -Darchlib=/usr/lib/perl/5.10 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.10.0 -Dsitearch=/usr/local/lib/perl/5.10.0 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Dsiteman3dir=/usr/local/man/man3 -Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Ud_ualarm -Uusesfio -Uusenm -DDEBUGGING=-g -Doptimize=-O2 -Duseshrplib -Dlibperl=libperl.so.5.10.0 -Dd_dosuid -des'
hint=recommended, useposix=true, d_sigaction=define
useithreads=define, usemultiplicity=define
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=define, use64bitall=define, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-O2 -g',
cppflags='-D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include'
ccversion='', gccversion='4.3.1', gccosandvers=''
intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib /lib64 /usr/lib64
libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt
perllibs=-ldl -lm -lpthread -lc -lcrypt
libc=/lib/libc-2.8.90.so, so=so, useshrplib=true, libperl=libperl.so.5.10.0
gnulibc_version='2.8.90'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
cccdlflags='-fPIC', lddlflags='-shared -O2 -g -L/usr/local/lib'


Characteristics of this binary (from libperl):
Compile-time options: MULTIPLICITY PERL_DONT_CREATE_GVSV
PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP USE_64_BIT_ALL
USE_64_BIT_INT USE_ITHREADS USE_LARGE_FILES
USE_PERLIO USE_REENTRANT_API
Built under linux
Compiled at Jul 24 2008 09:03:56
@INC:
/etc/perl
/usr/local/lib/perl/5.10.0
/usr/local/share/perl/5.10.0
/usr/lib/perl5
/usr/share/perl5
/usr/lib/perl/5.10
/usr/share/perl/5.10
/usr/local/lib/site_perl
.

Dave Mitchell

unread,
Dec 15, 2008, 10:10:58 AM12/15/08
to Eric Brine, perl5-...@perl.org
On Sun, Dec 14, 2008 at 09:28:39PM -0500, Eric Brine wrote:
> FYI, it could be one of ActivePerl's patches, but Windows actually gets it
> right. Tested with both 5.8.8 and 5.10.0. (perl -v below)
>
> >perl -c foo
> Can't open perl script "foo": Permission denied

With bleed on linux, I get silent "success":

$ ./perl -c /tmp
/tmp syntax OK

An strace shows that it is ignoring a read error while trying to
read the directory:

open("/tmp", O_RDONLY|O_LARGEFILE) = 3
...
read(3, 0x851973c, 4096) = -1 EISDIR (Is a directory)
close(3) = 0
write(2, "/tmp syntax OK\n", 15) = 15


--
My Dad used to say 'always fight fire with fire', which is probably why
he got thrown out of the fire brigade.

Slaven Rezic

unread,
Dec 17, 2008, 2:48:37 AM12/17/08
to Dave Mitchell, Eric Brine, perl5-...@perl.org
Dave Mitchell <da...@iabyn.com> writes:

> On Sun, Dec 14, 2008 at 09:28:39PM -0500, Eric Brine wrote:
>> FYI, it could be one of ActivePerl's patches, but Windows actually gets it
>> right. Tested with both 5.8.8 and 5.10.0. (perl -v below)
>>
>> >perl -c foo
>> Can't open perl script "foo": Permission denied
>
> With bleed on linux, I get silent "success":
>
> $ ./perl -c /tmp
> /tmp syntax OK
>
> An strace shows that it is ignoring a read error while trying to
> read the directory:

On FreeBSD, it is actually possible to _execute_ a directory if it has
an appropriate filename. First create directory and file:

mkdir "/tmp/dirhack";
open my $fh, ">", qq{/tmp/dirhack/\n#!perl\nprint "Hello, world!\\n";\n__END__\n}
or die $!;
__END__

and then run

perl -x /tmp/dirhack

Regards,
Slaven

--
Slaven Rezic - slaven <at> rezic <dot> de
BBBike - route planner for cyclists in Berlin
WWW version: http://www.bbbike.de
Perl/Tk version for Unix and Windows: http://bbbike.sourceforge.net

Dominic Hargreaves via RT

unread,
Oct 2, 2012, 9:26:43 AM10/2/12
to perl5-...@perl.org
This isn't specific to '-c' so I have updated the subject accordingly.
This was also reported as

<http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=689412>

---
via perlbug: queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=61362

Ricardo SIGNES via RT

unread,
Jan 5, 2013, 8:53:14 PM1/5/13
to perl5-...@perl.org
I have written b1469bd to catch this. I haven't written any tests, but can. I have tested it by
hand. I thought it worth letting anybody who knows perl.c better than I do (read: anybody) have
a look before I spend more time on it.

James E Keenan via RT

unread,
Jan 6, 2013, 8:56:34 AM1/6/13
to perl5-...@perl.org
On Sat Jan 05 17:53:13 2013, rjbs wrote:
> I have written b1469bd to catch this. I haven't written any tests,
> but can. I have tested it by
> hand. I thought it worth letting anybody who knows perl.c better than
> I do (read: anybody) have
> a look before I spend more time on it.

$ git diff blead...origin/rjbs/cant-run-dir |cat
diff --git a/perl.c b/perl.c
index c7e1d54..892ca42 100644
--- a/perl.c
+++ b/perl.c
@@ -3649,6 +3649,7 @@ S_open_script(pTHX_ const char *scriptname, bool
dosearch, bool *suidscript)
int fdscript = -1;
PerlIO *rsfp = NULL;
dVAR;
+ Stat_t tmpstatbuf;

PERL_ARGS_ASSERT_OPEN_SCRIPT;

@@ -3758,6 +3759,13 @@ S_open_script(pTHX_ const char *scriptname, bool
dosearch, bool *suidscript)
/* ensure close-on-exec */
fcntl(PerlIO_fileno(rsfp), F_SETFD, 1);
#endif
+
+ if (PerlLIO_fstat(PerlIO_fileno(rsfp), &tmpstatbuf) >= 0
+ && S_ISDIR(tmpstatbuf.st_mode))
+ Perl_croak(aTHX_ "Can't open perl script \"%s\": %s\n",
+ CopFILE(PL_curcop),
+ "is a directory");
+
return rsfp;
}

Something about the output is amiss:

#####
$ mkdir frbulous

$ ./perl -c frbulous/
Can't open perl script "frbulous/": is a directory

$ ./perl frbulous
Can't open perl script "frbulous": is a directory
#####

Wouldn't this be better?

#####
$ ./perl frbulous
Can't open perl script "frbulous"; it is a directory
#####

Thank you very much.
Jim Keenan

(Dagfinn Ilmari Mannsåker)

unread,
Jan 6, 2013, 11:38:27 AM1/6/13
to perl5-...@perl.org
Ricardo Signes <perl...@rjbs.manxome.org> writes:

> * James E Keenan via RT <perlbug-...@perl.org> [2013-01-06T08:56:34]
>> $ ./perl frbulous
>> Can't open perl script "frbulous": is a directory
>> #####
>>
>> Wouldn't this be better?
>>
>> #####
>> $ ./perl frbulous
>> Can't open perl script "frbulous"; it is a directory
>
> The semicolon means we'd need a new perldiag entry, so no on that front. The
> missing "it" is probably the result of me reworking that line a pitiable number
> of times. I'll change it.

Wouldn'it be best to use the standard strerror(EISDIR), for consistency?

$ cat /
cat: /: Is a directory

--
"A disappointingly low fraction of the human race is,
at any given time, on fire." - Stig Sandbeck Mathisen

Ricardo SIGNES via RT

unread,
Jan 12, 2013, 9:38:28 PM1/12/13
to perl5-...@perl.org
Fixed in cdd06489088cf64a0e621b79cdf0c48eb55f2622 and previous 3 commits.
0 new messages