Debian Codegraph @

t/sl_taint.t

raw
1 #!perl -T
2 # Copyright 2022 Jeffrey Kegler
3 # This file is part of Marpa::R2. Marpa::R2 is free software: you can
4 # redistribute it and/or modify it under the terms of the GNU Lesser
5 # General Public License as published by the Free Software Foundation,
6 # either version 3 of the License, or (at your option) any later version.
7 #
8 # Marpa::R2 is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser
14 # General Public License along with Marpa::R2. If not, see
15 # http://www.gnu.org/licenses/.
16
17 # Test of scannerless parsing for tainted grammars
18
19 use 5.010001;
20 use strict;
21 use warnings;
22
23 use Test::More tests => 1;
24 use English qw( -no_match_vars );
25 use lib 'inc';
26 use Marpa::R2::Test;
27 use Marpa::R2;
28
29 # $^X is always tainted
30 my $tainted_grammar = q{:start ::= A A ~ 'a' # } . $^X;
31
32 # Make sure we fail with tainted data
33 # -T flag was set on first line for this script
34 my $eval_ok = eval {
35 Marpa::R2::Scanless::G->new( { source => \$tainted_grammar } );
36 1;
37 };
38 if ($eval_ok) {
39 Test::More::fail("Tainted grammar accepted -- that should not happen");
40 }
41 else {
42 my $eval_error = $EVAL_ERROR;
43 Test::More::like(
44 $eval_error,
45 qr/Attempt \s+ to \s+ use \s+ a \s+ tainted \s+ input \s+ string \s+ with \s+ Marpa::R2
46 \s+ Marpa::R2 \s+ is \s+ insecure \s+ for \s+ use \s+ with \s+ tainted \s+ data/xms,
47 "Tainted grammar detected and rejected"
48 );
49 } ## end else [ if ($eval_ok) ]
50
51 # vim: expandtab shiftwidth=4: