Commit 9a313d45 authored by POTTIER Francois's avatar POTTIER Francois
Browse files

New test test/dynamic/misc/variants, which in the current version of Menhir...

New test test/dynamic/misc/variants, which in the current version of Menhir causes a segmentation fault. This illustrates issue #37.
parent cd964f02
# [make test] runs the tests in this directory only.
.PHONY: test
test:
@ dune runtest
(ocamllex (modules lexer))
(menhir (modules parser))
(test
(name test)
)
rule read =
parse
| "T" { Parser.T }
| _ { failwith ("Unexpected char: " ^ Lexing.lexeme lexbuf) }
| eof { Parser.EOF }
%token T
%token EOF
(* This parser is tricky. The semantic action returns [> `T of int], but the
start symbol is declared to have type [> `A of string], so the real type of
the start symbol is [> `A of string | `T of int]. *)
(* Versions of Menhir prior to 2020/05/25 would mistakenly assume that the
start symbol has type [> `A of string]. This could be exploited by the
user to cause a segmentation fault. *)
(* This issue was reported by Joe. *)
%start < [> `A of string ] > main
%%
main:
| T EOF { `T 0 }
let () =
let lexbuf = Lexing.from_string "T" in
match Parser.main Lexer.read lexbuf with
| `A s ->
Printf.printf "A %s\n" s
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment