lamprecht has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I'm seeing the following on WinXP running strawberry-perl:

C:\Dokumente und Einstellungen\perl\Desktop>md t C:\Dokumente und Einstellungen\perl\Desktop>echo print "hi\n"; > t/t.p +l C:\Dokumente und Einstellungen\perl\Desktop>perl -e"do'.\t\t.pl'" hi C:\Dokumente und Einstellungen\perl\Desktop>perl -e"do'./t\t.pl'" hi C:\Dokumente und Einstellungen\perl\Desktop>perl -T -e"do'./t\t.pl'" hi C:\Dokumente und Einstellungen\perl\Desktop>perl -T -e"do'.\t\t.pl'" C:\Dokumente und Einstellungen\perl\Desktop>perl -V Summary of my perl5 (revision 5 version 8 subversion 8) configuration: Platform: osname=MSWin32, osvers=5.1, archname=MSWin32-x86-multi-thread uname='' config_args='undef' hint=recommended, useposix=true, d_sigaction=undef usethreads=define use5005threads=undef useithreads=define usemulti +plicity=de fine useperlio=define d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='gcc', ccflags =' -s -O2 -DWIN32 -DHAVE_DES_FCRYPT -DPERL_IMPL +ICIT_CONTE XT -DPERL_IMPLICIT_SYS -fno-strict-aliasing -DPERL_MSVCRT_READFIX', optimize='-s -O2', cppflags='-DWIN32' ccversion='', gccversion='3.4.5', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='long lo +ng', lseek size=8 alignbytes=8, prototype=define Linker and Libraries: ld='g++', ldflags ='-s -L"c:\strawberry-perl\perl\lib\CORE" -L"c:\ +strawberry -perl\mingw\lib"' libpth=c:\strawberry-perl\mingw\lib libs= -lmsvcrt -lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool - +lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lm +pr -lwinmm -lversion -lodbc32 -lodbccp32 perllibs= -lmsvcrt -lmoldname -lkernel32 -luser32 -lgdi32 -lwinspo +ol -lcomdl g32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 + -lmpr -lw inmm -lversion -lodbc32 -lodbccp32 libc=-lmsvcrt, so=dll, useshrplib=yes, libperl=libperl58.a gnulibc_version='' Dynamic Linking: dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' ' cccdlflags=' ', lddlflags='-mdll -s -L"c:\strawberry-perl\perl\lib +\CORE" -L" c:\strawberry-perl\mingw\lib"' Characteristics of this binary (from libperl): Compile-time options: MULTIPLICITY PERL_IMPLICIT_CONTEXT PERL_IMPLICIT_SYS PERL_MALLOC_WRAP PL_OP_SLAB_ALLOC USE_ITHREADS USE_LARGE_FILES USE_PERLIO Built under MSWin32 Compiled at Aug 27 2006 17:17:50 @INC: C:/strawberry-perl/perl/lib C:/strawberry-perl/perl/site/lib .

Is this behavior expected?

Shouldn't perl -T -e"do'./t\t.pl'" and perl -T -e"do'.\t\t.pl'" do the same thing (and print 'hi').

I came across this examining a false positive(failing) test in Scalar-List-Utils which uses an expression like above. http://rt.cpan.org/Public/Bug/Display.html?id=25430

Thank you for any insight.

Replies are listed 'Best First'.
Re: do'.\dir\file' under -T on Windows
by ikegami (Patriarch) on Feb 25, 2009 at 15:06 UTC

    Shouldn't perl -T -e"do'./t\t.pl'" and perl -T -e"do'.\t\t.pl'" do the same thing

    Yes. "/" and "\" are equivalent in Windows paths.

    I can replicate the problem with ActivePerl 5.6.0, 5.6.1, 5.8.0, 5.8.8, 5.10.0.

    Seems the logic for whether @INC should be used or not is broken. Under -T, @INC doesn't contain ".", and do'.\t\t.pl' is using @INC instead of the cd.

    (and print 'hi').

    Seems so. 5.8.8 on linux:

    $ perl -le'@INC=(); do "t/t.pl"' $ perl -le'@INC=(); do "./t/t.pl"' hi $ perl -T -le'@INC=(); do "t/t.pl"' $ perl -T -le'@INC=(); do "./t/t.pl"' hi

    Update: Added comparison to linux and explanation of problem.

      Maybe perl is emulating one of the classic *NIX security fixes (removing the current working directory from the path) in @INC when run in taint checking mode...

      Just a thought ...

      A user level that continues to overstate my experience :-))

        If a taint check for relative paths were to be added, it would throw an exception rather than setting $! to file not found.

        Note that this taint check would be a departure from the current model which allows the current directory to be used.

        $ cat script.pl #!/usr/bin/perl print "unsafe?\n"; $ perl -T -e'$ENV{PATH}=""; system "script.pl";' unsafe?
        $ cat Mod.pm print "unsafe?\n"; 1; $ perl -T -e'@INC = "."; require Mod;' unsafe?

        Sounds like a pretty good idea to me, though. It would break stuff, but nothing that can't be fixed.

        That's fine. The problem isn't that "." isn't present in @INC, it's that @INC is used at all.

        The documented behaviour is to use @INC, but that's clearly not what other systems do when the path can't be a module path, or even on Windows when "/" is used as the separator. I'm not sure how "looks like a module path" is defined, but it's obviously buggy.

Re: do'.\dir\file' under -T on Windows
by Anonymous Monk on Feb 25, 2009 at 15:23 UTC
    No, its not expected, but some insight
    C:\>perl -T -e"do'.\t\t.pl' or die sprintf '(%d)(%s)(%d)(%s)($@)(%s)', +int($!),$!,int($^E),$^E,$@" (2)(No such file or directory)(3)(The system cannot find the path spec +ified)($@)() at -e line 1.
    D:\>perl -Te" require 'New.pm'" Can't locate New.pm in @INC (@INC contains:... D:\>perl -Te" require 'New.pl'" Can't locate New.pl in @INC (@INC contains:... D:\>perl -Te" require './New.pm'" hi D:\>perl -Te" require './New.pl'" hi D:\>perl -Te" require '.\New.pl'" Can't locate .\New.pl in @INC (@INC contains:... D:\>perl -Te" require '.\New.pm'" Can't locate .\New.pm in @INC (@INC contains:...