xref: /openbsd-src/gnu/usr.bin/perl/t/comp/parser_run.t (revision a0747c9f67a4ae71ccb71e62a28d1ea19e06a63c)
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 m0\n\$" . ("v" x 0x2000),
19    { stderr => 1 },
20);
21is($result . "\n", <<EXPECT);
22syntax error at - line 3, near "foreach m0
23"
24Identifier too long at - line 3.
25EXPECT
26
27fresh_perl_is(<<'EOS', <<'EXPECT', {}, "check zero vars");
28print $001;
29EOS
30Numeric variables with more than one digit may not start with '0' at - line 1.
31EXPECT
32
33fresh_perl_is(<<EOS, <<'EXPECT', {}, "linestart before bufptr");
34\${ \xB6eeeeeeeeeeee
35'x
36EOS
37Unrecognized character \xB6; marked by <-- HERE after ${ <-- HERE near column 4 at - line 1.
38EXPECT
39
40fresh_perl_is(<<'EOS', <<'EXPECTED', {}, "use after free (#131836)");
41${sub#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
42EOS
43Missing right curly or square bracket at - line 1, at end of line
44syntax error at - line 1, at EOF
45Execution of - aborted due to compilation errors.
46EXPECTED
47
48SKIP:
49{
50    # [perl #131949] use after free
51    # detected by ASAN
52    # Win32 cmd.exe can't handle newlines well
53    skip("Need POSIXish", 1) if $^O eq "MSWin32";
54    my $out = runperl(prog => "\@{ 0\n\n}", stderr => 1, non_portable => 1);
55    is($out, "", "check for ASAN use after free");
56}
57
58fresh_perl_is('-C-', <<'EXPECTED', {}, "ambiguous unary operator check doesn't crash (#132433)");
59Warning: Use of "-C-" without parentheses is ambiguous at - line 1.
60syntax error at - line 1, at EOF
61Execution of - aborted due to compilation errors.
62EXPECTED
63
64{
65    my $work = tempfile;
66    open my $fh, ">", $work or die;
67    binmode $fh;
68    print $fh +("\n" x 50_000), "1;\n";
69    close $fh;
70    fresh_perl_is('require "./' . $work .'"; print "ok\n";', "ok\n",
71                  {}, "many blank lines doesn't crash");
72}
73
74__END__
75# ex: set ts=8 sts=4 sw=4 et:
76