parser_run.t revision 1.1.1.3
1#!./perl
2
3# Parser tests that want test.pl, eg to use runperl() for tests to show
4# reads through invalid pointers.
5# Note that this should still be runnable under miniperl.
6
7BEGIN {
8    chdir 't' if -d 't';
9    require './test.pl';
10    set_up_inc( qw(. ../lib ) );
11}
12
13plan(7);
14
15# [perl #130814] can reallocate lineptr while looking ahead for
16# "Missing $ on loop variable" diagnostic.
17my $result = fresh_perl(
18    " foreach my\n\$" . ("v" x 0x2000),
19    { stderr => 1 },
20);
21is($result . "\n", <<EXPECT);
22Identifier too long at - line 2.
23EXPECT
24
25fresh_perl_is(<<'EOS', <<'EXPECT', {}, "check zero vars");
26print $001;
27EOS
28Numeric variables with more than one digit may not start with '0' at - line 1.
29EXPECT
30
31fresh_perl_is(<<EOS, <<'EXPECT', {}, "linestart before bufptr");
32\${ \xB6eeeeeeeeeeee
33'x
34EOS
35Unrecognized character \xB6; marked by <-- HERE after ${ <-- HERE near column 4 at - line 1.
36EXPECT
37
38fresh_perl_is(<<'EOS', <<'EXPECTED', {}, "use after free (#131836)");
39${sub#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
40EOS
41Missing right curly or square bracket at - line 1, at end of line
42syntax error at - line 1, at EOF
43Execution of - aborted due to compilation errors.
44EXPECTED
45
46SKIP:
47{
48    # [perl #131949] use after free
49    # detected by ASAN
50    # Win32 cmd.exe can't handle newlines well
51    skip("Need POSIXish", 1) if $^O eq "MSWin32";
52    my $out = runperl(prog => "\@{ 0\n\n}", stderr => 1, non_portable => 1);
53    is($out, "", "check for ASAN use after free");
54}
55
56fresh_perl_is('-C-', <<'EXPECTED', {}, "ambiguous unary operator check doesn't crash (#132433)");
57Warning: Use of "-C-" without parentheses is ambiguous at - line 1.
58syntax error at - line 1, at EOF
59Execution of - aborted due to compilation errors.
60EXPECTED
61
62{
63    my $work = tempfile;
64    open my $fh, ">", $work or die;
65    binmode $fh;
66    print $fh +("\n" x 50_000), "1;\n";
67    close $fh;
68    fresh_perl_is('require "./' . $work .'"; print "ok\n";', "ok\n",
69                  {}, "many blank lines doesn't crash");
70}
71
72__END__
73# ex: set ts=8 sts=4 sw=4 et:
74