From: Guy Harris Date: Tue, 30 Oct 2018 02:25:40 +0000 (-0700) Subject: finish_parse() has to catch bpf_error() exceptions, too. X-Git-Tag: libpcap-1.10-bp~740 X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/d9500279597993c5290c08ec095513e0de6ce8e3 finish_parse() has to catch bpf_error() exceptions, too. Do so, and return -1 on an error and 0 otherwise. Check the return value when it's called. --- diff --git a/gencode.c b/gencode.c index 5af22d5e..bacc713c 100644 --- a/gencode.c +++ b/gencode.c @@ -927,11 +927,18 @@ merge(struct block *b0, struct block *b1) *p = b1; } -void +int finish_parse(compiler_state_t *cstate, struct block *p) { struct block *ppi_dlt_check; + /* + * Catch errors reported by us and routines below us, and return -1 + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (-1); + /* * Insert before the statements of the first (root) block any * statements needed to load the lengths of any variable-length @@ -974,6 +981,7 @@ finish_parse(compiler_state_t *cstate, struct block *p) p->sense = !p->sense; backpatch(p, gen_retblk(cstate, 0)); cstate->ic.root = p->head; + return (0); } void diff --git a/gencode.h b/gencode.h index 9920de7d..cc21e043 100644 --- a/gencode.h +++ b/gencode.h @@ -370,7 +370,7 @@ int bpf_optimize(struct icode *, char *); void bpf_set_error(compiler_state_t *, const char *, ...) PCAP_PRINTFLIKE(2, 3); -void finish_parse(compiler_state_t *, struct block *); +int finish_parse(compiler_state_t *, struct block *); char *sdup(compiler_state_t *, const char *); struct bpf_insn *icode_to_fcode(struct icode *, struct block *, u_int *, diff --git a/grammar.y b/grammar.y index 2d938864..0db5a544 100644 --- a/grammar.y +++ b/grammar.y @@ -382,7 +382,7 @@ DIAG_OFF_BISON_BYACC %% prog: null expr { - finish_parse(cstate, $2.b); + CHECK_INT_VAL(finish_parse(cstate, $2.b)); } | null ;