From 1dfef69b3a0643e5cf8879e1476b0163c3e8a9b2 Mon Sep 17 00:00:00 2001 From: Ricardo Signes Date: Sat, 5 Jan 2013 20:30:48 -0500 Subject: [PATCH] croak on an attempt to run a directory as a script How many times have I meant to run "perl -I lib myprog" but instead run "perl lib myprog" only to exit 0 because that's what perl does when you try to run a directory as a script (at least on unix)? Many. perl should croak when instructed to execute a directory. [perl #61362] suggests it already does so on Win32. Now it does it everywhere. Tests not yet written. --- perl.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/perl.c b/perl.c index c7e1d54..d4f13df 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), + strerror(EISDIR)); + return rsfp; } -- 2.7.4