]> The Tcpdump Group git mirrors - libpcap/commitdiff
optimizer: add a sanity check to make sure the program isn't empty.
authorGuy Harris <[email protected]>
Fri, 29 May 2020 16:57:03 +0000 (09:57 -0700)
committerGuy Harris <[email protected]>
Fri, 29 May 2020 16:57:25 +0000 (09:57 -0700)
That "should never happen", but this makes sure that, if it happens, the
compilation fails before it ever divides by the program size.

This should address Coverity CID 1463864.

optimize.c

index 778bcb1bc5fa5cd465d6dc109bc47b0915476951..4fb7b0d29bc056c09d7e49950811034c4c8bbfd1 100644 (file)
@@ -2533,6 +2533,12 @@ opt_init(opt_state_t *opt_state, struct icode *ic)
        opt_state->n_blocks = 0;
        number_blks_r(opt_state, ic, ic->root);
 
+       /*
+        * This "should not happen".
+        */
+       if (opt_state->n_blocks == 0)
+               opt_error(opt_state, "filter has no instructions; please report this as a libpcap issue");
+
        opt_state->n_edges = 2 * opt_state->n_blocks;
        if ((opt_state->n_edges / 2) != opt_state->n_blocks) {
                /*