Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perl ignores errors when asked to invoke or syntax check a directory #9597

Closed
p5pRT opened this issue Dec 14, 2008 · 17 comments
Closed

perl ignores errors when asked to invoke or syntax check a directory #9597

p5pRT opened this issue Dec 14, 2008 · 17 comments

Comments

@p5pRT
Copy link

p5pRT commented Dec 14, 2008

Migrated from rt.perl.org#61362 (status was 'resolved')

Searchable as RT61362$

@p5pRT
Copy link
Author

p5pRT commented Dec 14, 2008

From perlbugcrowell08@lightandmatter.com

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
  .

@p5pRT
Copy link
Author

p5pRT commented Dec 15, 2008

From @ikegami

On Sun, Dec 14, 2008 at 2​:30 PM, via RT Ben Crowell <
perlbug-followup@​perl.org> wrote​:

# 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

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

This is perl, v5.8.8 built for MSWin32-x86-multi-thread
(with 12 registered patches, see perl -V for more detail)

Copyright 1987-2007, Larry Wall

Binary build 824 [287188] provided by ActiveState http​://www.ActiveState.com
Built Sep 3 2008 11​:14​:55

This is perl, v5.10.0 built for MSWin32-x86-multi-thread
(with 1 registered patch, see perl -V for more detail)

Copyright 1987-2007, Larry Wall

Binary build 1001 [283495] provided by ActiveState
http​://www.ActiveState.com
Built Dec 18 2007 08​:46​:15

@p5pRT
Copy link
Author

p5pRT commented Dec 15, 2008

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Dec 15, 2008

From @iabyn

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.

@p5pRT
Copy link
Author

p5pRT commented Dec 17, 2008

From @eserte

Dave Mitchell <davem@​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

@p5pRT
Copy link
Author

p5pRT commented Oct 2, 2012

From @jmdh

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>

@p5pRT
Copy link
Author

p5pRT commented Jan 6, 2013

From @rjbs

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.

@p5pRT
Copy link
Author

p5pRT commented Jan 6, 2013

From @jkeenan

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.

First attempt at a test, attached.

Thank you very much.
Jim Keenan

@p5pRT
Copy link
Author

p5pRT commented Jan 6, 2013

From @jkeenan

0001-Add-a-test-to-detect-error-when-attempting-to-syntax.patch
From 975cb0aa2e4cb19f7fe47ba3f9f3caaa2399973a Mon Sep 17 00:00:00 2001
From: James E Keenan <jkeenan@cpan.org>
Date: Sat, 5 Jan 2013 22:25:29 -0500
Subject: [PATCH] Add a test to detect error when attempting to syntax-check a directory.

Not yet working; todo_skip it.

For: RT #61362
---
 t/run/switches.t |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/t/run/switches.t b/t/run/switches.t
index 5c3b5ee..bb46e6a 100644
--- a/t/run/switches.t
+++ b/t/run/switches.t
@@ -11,7 +11,7 @@ BEGIN {
 
 BEGIN { require "./test.pl"; }
 
-plan(tests => 114);
+plan(tests => 115);
 
 use Config;
 
@@ -107,6 +107,18 @@ SWTEST
     );
 }
 
+TODO: {
+    todo_skip("RT #61362: perl ignores errors when asked to invoke or syntax check a directory");
+    my $tempdir = tempfile;
+    mkdir $tempdir, 0700 or die "Can't mkdir '$tempdir': $!";
+    like(
+        runperl( switches => [ '-c' ], args  => [ $tempdir ], stderr => 1),
+        qr/Can't open perl script.*$tempdir.*is a directory/s,
+        "RT \#61362: Cannot syntax-check a directory"
+    );
+    rmdir $tempdir or die "Can't rmdir '$tempdir': $!";
+}
+
 # Tests for -l
 
 $r = runperl(
-- 
1.6.3.2

@p5pRT
Copy link
Author

p5pRT commented Jan 6, 2013

From @jkeenan

On Sat Jan 05 19​:29​:55 2013, jkeenan wrote​:

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.

First attempt at a test, attached.

Thank you very much.
Jim Keenan

Second attempt at a patch. I don't think the test needed to be todo-ed.

@p5pRT
Copy link
Author

p5pRT commented Jan 6, 2013

From @jkeenan

0001-Add-a-test-to-detect-error-when-attempting-to-syntax.patch
From d0f59158e7938543e82e306c56f927866a506ed8 Mon Sep 17 00:00:00 2001
From: James E Keenan <jkeenan@cpan.org>
Date: Sat, 5 Jan 2013 22:25:29 -0500
Subject: [PATCH] Add a test to detect error when attempting to syntax-check a directory.

For: RT #61362
---
 t/run/switches.t |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/t/run/switches.t b/t/run/switches.t
index 5c3b5ee..d946106 100644
--- a/t/run/switches.t
+++ b/t/run/switches.t
@@ -11,7 +11,7 @@ BEGIN {
 
 BEGIN { require "./test.pl"; }
 
-plan(tests => 114);
+plan(tests => 115);
 
 use Config;
 
@@ -107,6 +107,17 @@ SWTEST
     );
 }
 
+{
+    my $tempdir = tempfile;
+    mkdir $tempdir, 0700 or die "Can't mkdir '$tempdir': $!";
+    like(
+        runperl( switches => [ '-c' ], args  => [ $tempdir ], stderr => 1),
+        qr/Can't open perl script.*$tempdir.*is a directory/s,
+        "RT \#61362: Cannot syntax-check a directory"
+    );
+    rmdir $tempdir or die "Can't rmdir '$tempdir': $!";
+}
+
 # Tests for -l
 
 $r = runperl(
-- 
1.6.3.2

@p5pRT
Copy link
Author

p5pRT commented Jan 6, 2013

From @jkeenan

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

Inline Patch
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

@p5pRT
Copy link
Author

p5pRT commented Jan 6, 2013

From @rjbs

* James E Keenan via RT <perlbug-followup@​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.

--
rjbs

@p5pRT
Copy link
Author

p5pRT commented Jan 6, 2013

From @ilmari

Ricardo Signes <perl.p5p@​rjbs.manxome.org> writes​:

* James E Keenan via RT <perlbug-followup@​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

@p5pRT
Copy link
Author

p5pRT commented Jan 13, 2013

From @rjbs

Fixed in cdd0648 and previous 3 commits.

@p5pRT
Copy link
Author

p5pRT commented Jan 13, 2013

From [Unknown Contact. See original ticket]

Fixed in cdd0648 and previous 3 commits.

@p5pRT
Copy link
Author

p5pRT commented Jan 13, 2013

@rjbs - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant