summaryrefslogtreecommitdiffstats
path: root/t/bug-rt-78272.t
blob: 670782b13a3a09ecb56756cab0d7db2f7abdadef (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use strict;
use warnings;
use Test::More tests => 1;
use Test::Exception;

subtest 'Bug RT-78272: Arbitrary code execution from $ENV' => sub {

    # https://rt.cpan.org/Public/Bug/Display.html?id=78272
    my $e = $ENV{PACKAGE_STASH_IMPLEMENTATION} = "PP; exit 1";
    throws_ok {
        require Package::Stash;
    }
    qr/^Could not load Package::Stash::$e/,
      'Arbitrary code in $ENV throws exception';

    throws_ok {
        delete $INC{'Package/Stash.pm'};
        require Package::Stash;
    }
    qr/^Could not load Package::Stash::$e/,
      'Sanity check: forcing package reload throws the exception again';

    lives_ok {
        $ENV{PACKAGE_STASH_IMPLEMENTATION} = "PP";
        delete $INC{'Package/Stash.pm'};
        require Package::Stash;
        new_ok(
            'Package::Stash' => ['Foo'],
            'Loaded and able to create instances'
        );
    }
    'Valid $ENV value loads correctly';
};