From 7e3e30aa9c64739b9bd70fdbaf910d27e336e7ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=C3=A4schle?= Date: Sat, 12 Dec 2020 14:20:38 +0100 Subject: [PATCH] ci: add a parser fuzzer step too (#7288) --- .github/workflows/ci.yml | 29 +++++++++++++++++++++++++++++ vlib/v/parser/parse_type.v | 2 +- vlib/v/scanner/scanner.v | 3 +++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9051663184..82b30f976e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -622,3 +622,32 @@ jobs: ./v test-parser examples/vmod.v ./v test-parser examples/regex_example.v ./v test-parser examples/2048/2048.v + + parser-silent-fuzzing: + name: Parser silent mode fuzzing + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - uses: actions/checkout@v2 + - name: Build local v + run: make -j4 + - name: Install zzuf + run: sudo apt install -qq zzuf + - name: Run test-parser + run: | + zzuf -R '\x00-\x20\x7f-\xff' -r0.01 < examples/hello_world.v > examples/hello_world_fuzz.v + ./v test-parser examples/hello_world_fuzz.v + zzuf -R '\x00-\x20\x7f-\xff' -r0.01 < examples/hanoi.v > examples/hanoi_fuzz.v + ./v test-parser examples/hanoi_fuzz.v + zzuf -R '\x00-\x20\x7f-\xff' -r0.01 < examples/fibonacci.v > examples/fibonacci_fuzz.v + ./v test-parser examples/fibonacci.v + zzuf -R '\x00-\x20\x7f-\xff' -r0.01 < examples/cli.v > examples/cli_fuzz.v + ./v test-parser examples/cli_fuzz.v + zzuf -R '\x00-\x20\x7f-\xff' -r0.01 < examples/json.v > examples/json_fuzz.v + ./v test-parser examples/json.v + zzuf -R '\x00-\x20\x7f-\xff' -r0.01 < examples/vmod.v > examples/vmod_fuzz.v + ./v test-parser examples/vmod.v + zzuf -R '\x00-\x20\x7f-\xff' -r0.01 < examples/regex_example.v > examples/regex_example_fuzz.v + ./v test-parser examples/regex_example_fuzz.v + zzuf -R '\x00-\x20\x7f-\xff' -r0.01 < examples/2048/2048.v > examples/2048/2048_fuzz.v + ./v test-parser examples/2048/2048_fuzz.v diff --git a/vlib/v/parser/parse_type.v b/vlib/v/parser/parse_type.v index 2c887c3558..c9acbd4626 100644 --- a/vlib/v/parser/parse_type.v +++ b/vlib/v/parser/parse_type.v @@ -380,7 +380,7 @@ pub fn (mut p Parser) parse_generic_struct_inst_type(name string) table.Type { bs_cname += '_T_' mut generic_types := []table.Type{} mut is_instance := false - for { + for p.tok.kind != .eof { gt := p.parse_type() if !gt.has_flag(.generic) { is_instance = true diff --git a/vlib/v/scanner/scanner.v b/vlib/v/scanner/scanner.v index 939c5d0066..19c27107e8 100644 --- a/vlib/v/scanner/scanner.v +++ b/vlib/v/scanner/scanner.v @@ -233,6 +233,9 @@ fn (mut s Scanner) ident_hex_number() string { mut first_wrong_digit_pos := 0 mut first_wrong_digit := `\0` start_pos := s.pos + if s.pos + 2 >= s.text.len { + return '0x' + } s.pos += 2 // skip '0x' if s.text[s.pos] == num_sep { s.error('separator `_` is only valid between digits in a numeric literal')