ingydotnet / inline-c-pm

10 stars 19 forks source link

t/08taint.t fails if Inline module is not in Perl's default @INC #96

Closed djerius closed 2 years ago

djerius commented 4 years ago

I'm installing Inline and Inline::C into a directory which is not in the system Perl's default @INC. During testing of Inline::C, PERL5LIB is set appropriately and all tests pass, except for t/08taint.t.

In taint mode, Perl ignores PERL5LIB, and thus only the default @INC is searched, which finds (in my case) an older, incompatible version of Inline shipped with the system.

Installing a custom version of Perl isn't an option. At the moment, the only solution that I can think of is to have Makefile.PL generate Perl code which amends @INC appropriately, and which is then loaded by t/08taint.t.

mohawk2 commented 3 years ago

@djerius I think this is fixed in 0.81_001! Could you try it?

dmacks commented 3 years ago

This looks like it would be a viable approach, but it still fails for me on OS X 10.13 (Apple's perl-5.18.2) with a ton of additional modules including Inline-0.86 in PERL5LIB dirs. Looks like derive_minus_I() isn't including PERL5LIB paths.

$ perl -MInline -e 'print $INC{"Inline.pm"},",",$Inline::VERSION, "\n", $ENV{PERL5LIB}, "\n", join (",",Inline->derive_minus_I()), "\n"'
/sw/lib/perl5/5.18.2/Inline.pm,0.86
/sw/lib/perl5
/sw/lib/perl5/5.18.2/darwin-thread-multi-2level,/System/Library/Perl/Extras/5.18/darwin-thread-multi-2level,/System/Library/Perl/Extras/5.18

Only the [perlversion]/[arch] subdir of PERL5LIB is being propagated.

mohawk2 commented 3 years ago

@dmacks I think you're saying that derive_minus_I doesn't work right in all circumstances. Can you help by showing your perl -V, and even better figuring out where derive_minus_I is going wrong?

dmacks commented 3 years ago

perl -V:

Summary of my perl5 (revision 5 version 18 subversion 2) configuration:

  Platform:
    osname=darwin, osvers=17.0, archname=darwin-thread-multi-2level
    uname='darwin osx230.apple.com 17.0 darwin kernel version 16.1.0: mon oct 9 13:05:29 pdt 2017; root:xnu-3789.21.4.1.7~1development_x86_64 x86_64 '
    config_args='-ds -e -Dprefix=/usr -Dccflags=-g  -pipe  -Dldflags= -Dman3ext=3pm -Duseithreads -Duseshrplib -Dinc_version_list=none -Dcc=cc'
    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 ='-arch x86_64 -arch i386 -g -pipe -fno-common -DPERL_DARWIN -fno-strict-aliasing -fstack-protector',
    optimize='-Os',
    cppflags='-g -pipe -fno-common -DPERL_DARWIN -fno-strict-aliasing -fstack-protector'
    ccversion='', gccversion='4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)', 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 ='-arch x86_64 -arch i386 -fstack-protector'
    libpth=/usr/lib /usr/local/lib
    libs= 
    perllibs=
    libc=, so=dylib, useshrplib=true, libperl=libperl.dylib
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-arch x86_64 -arch i386 -bundle -undefined dynamic_lookup -fstack-protector'

Characteristics of this binary (from libperl): 
  Compile-time options: HAS_TIMES MULTIPLICITY PERLIO_LAYERS
                        PERL_DONT_CREATE_GVSV
                        PERL_HASH_FUNC_ONE_AT_A_TIME_HARD
                        PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP
                        PERL_PRESERVE_IVUV PERL_SAWAMPERSAND USE_64_BIT_ALL
                        USE_64_BIT_INT USE_ITHREADS USE_LARGE_FILES
                        USE_LOCALE USE_LOCALE_COLLATE USE_LOCALE_CTYPE
                        USE_LOCALE_NUMERIC USE_PERLIO USE_PERL_ATOF
                        USE_REENTRANT_API
  Locally applied patches:
    /Library/Perl/Updates/<version> comes before system perl directories
    installprivlib and installarchlib points to the Updates directory
  Built under darwin
  Compiled at Jan 18 2020 07:01:36
  %ENV:
    PERL5LIB="/sw/lib/perl5:/sw/lib/perl5/darwin"
  @INC:
    /sw/lib/perl5/5.18.2/darwin-thread-multi-2level
    /sw/lib/perl5/5.18.2
    /sw/lib/perl5/darwin-thread-multi-2level
    /sw/lib/perl5
    /sw/lib/perl5/darwin
    /Library/Perl/5.18/darwin-thread-multi-2level
    /Library/Perl/5.18
    /Network/Library/Perl/5.18/darwin-thread-multi-2level
    /Network/Library/Perl/5.18
    /Library/Perl/Updates/5.18.2
    /System/Library/Perl/5.18/darwin-thread-multi-2level
    /System/Library/Perl/5.18
    /System/Library/Perl/Extras/5.18/darwin-thread-multi-2level
    /System/Library/Perl/Extras/5.18
    .
dmacks commented 3 years ago

Probing inside Inline::derive_minus_I(), here is what I find. @INC matches the above perl -V output and @libexclude is:

'/System/Library/Perl/5.18/darwin-thread-multi-2level',
'/System/Library/Perl/5.18',
'/Library/Perl/5.18/darwin-thread-multi-2level',
'/Library/Perl/5.18',
'/Network/Library/Perl/5.18/darwin-thread-multi-2level',
'/Network/Library/Perl/5.18',
'/sw/lib/perl5',
'/sw/lib/perl5/5.18.2',
'/sw/lib/perl5/darwin-thread-multi-2level',
'/sw/lib/perl5/darwin',
'/sw/lib/perl5/darwin/5.18.2',
'/sw/lib/perl5/darwin/darwin-thread-multi-2level'

@libinclude gets initially defined as:

'/sw/lib/perl5/5.18.2/darwin-thread-multi-2level',
'/Library/Perl/Updates/5.18.2',
'/System/Library/Perl/Extras/5.18/darwin-thread-multi-2level',
'/System/Library/Perl/Extras/5.18'

so it only has the perlversion-dependent directories, and sometimes only the architecture-dependent subdirectory thereof.

One detail that looks suspicious is that the list of %Config entries to check: qw(archlibexp privlibexp sitearchexp sitelibexp vendorarchexp vendorlibexp)), does not include "extrasarch" or "extralib", which is where the two /System/Library/Perl/Extras/5.18 paths come from. There is also an "extras", but it is blank on my platform.

I do not see documentation of this function, but from the way it is used in Inline::C::makefile_pl(), I think the goal is to return a list of the paths in @INC that are present as a result of PERL5LIB rather than being compiled into perl itself? So if PERL5LIB were blanked, these are the paths that would be missing?

mohawk2 commented 3 years ago

the goal is to return a list of the paths in @INC that are present as a result of PERL5LIB rather than being compiled into perl itself? So if PERL5LIB were blanked, these are the paths that would be missing?

The goal is to add -I flags to a spawned Perl execution so that together with the existing PERL5LIB, the @INC will end up the same as in current process. I'm not clear yet on where your PERL5LIB is coming from, but that shouldn't affect this.

The %Config entries that I think you're saying should be there would add to the list of exclusions, and it seems like the problem we're having is either too few things included, or too many excluded. If I'm right, that shouldn't affect this either.

Could I ask you to experiment with either adding to the "include", or subtracting from the "exclude" (possibly with additional %Config entries) until the @INC is the same, and either posting the results here or making a PR?

djerius commented 3 years ago

@djerius I think this is fixed in 0.81_001! Could you try it?

Sorry for the silence. I've tried to recreate the environment in which 0.81 failed, but so far I'm unable to do so.

mohawk2 commented 2 years ago

I believe this issue is fixed in Inline::C 0.82. Please reopen if this is not the case!