]> The Tcpdump Group git mirrors - libpcap/commit
Don't longjmp out of the generated parser.
authorGuy Harris <[email protected]>
Thu, 25 Oct 2018 18:13:35 +0000 (11:13 -0700)
committerGuy Harris <[email protected]>
Thu, 25 Oct 2018 18:13:35 +0000 (11:13 -0700)
commit1c26c7de8a932fc5c1802246fa048bc00bca691e
treef48690c88bbb999ab30f989090fa7d8740326885
parentdf805a6807056e565f785da85ca62d765867c94f
Don't longjmp out of the generated parser.

The parser may have allocated memory and must exit normally in order to
free it.

Have the code for null do a setjmp and, if setjmp returns a non-zero
value, meaning somebody's done a longjmp, do YYABORT, so we cleanly
return from the parser, returning a value of 1.

Have pcap_compile() treat a non-zero return value from the parser as
meaning an error occurred; clean up and return -1.

This means that compiler_state_t must be defined in gencode.h, so that
the jmp_buf is available in grammar.y; have most of the state in a
private structure, opaque outside of gencode.c, pointed to by a pointer
in the compiler_state_t structure.

Have the private data for optimizer and for icode_to_fcode() have their
own jmp_bufs, and have the optimizer and icode_for_fcode() do their own
setjmp(), and clean up and return a value indicating an error if
setjmp() returns a non-zero value.  Have their callers check for the
error and, if an error occurred, clean up and return an error
indication.

Don't use bpf_error() except in the parser and code called by the
parser, as, if the parser isn't running, there's no place to which to
longjmp.

Credit to OSS-Fuzz for finding the memory leak.
gencode.c
gencode.h
grammar.y
optimize.c