]> The Tcpdump Group git mirrors - libpcap/commitdiff
finish_parse() has to catch bpf_error() exceptions, too.
authorGuy Harris <[email protected]>
Tue, 30 Oct 2018 02:25:40 +0000 (19:25 -0700)
committerGuy Harris <[email protected]>
Tue, 30 Oct 2018 02:25:40 +0000 (19:25 -0700)
Do so, and return -1 on an error and 0 otherwise.  Check the return
value when it's called.

gencode.c
gencode.h
grammar.y

index 5af22d5e098a79f652da7f43cf8904f9325a030b..bacc713c40130cad5345da0e7dda4e881b4ecb6f 100644 (file)
--- 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
index 9920de7d2439c943cc42601911c61aabb1d82cff..cc21e04384a6de10754dbbdb2cca102fc1603fcf 100644 (file)
--- 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 *,
index 2d938864d2eb45e91277fa0ab58e485c6be93348..0db5a54456f48a97fd33fcdbda38e772ced711ef 100644 (file)
--- 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
        ;