]> The Tcpdump Group git mirrors - libpcap/blobdiff - gencode.c
Catch shifts > 31 bits generated by the optimizer.
[libpcap] / gencode.c
index 15cb93473deb568d15f0aad75bbf10d2d6e9b7dd..95a3ef9579a27e409202a320c1420aa1a6b7fe2f 100644 (file)
--- a/gencode.c
+++ b/gencode.c
@@ -7466,7 +7466,13 @@ gen_arth(compiler_state_t *cstate, int code, struct arth *a0,
                if (a1->s->s.code == (BPF_LD|BPF_IMM) && a1->s->s.k == 0)
                        bpf_error(cstate, "modulus by zero");
        } else if (code == BPF_LSH || code == BPF_RSH) {
-               if (a1->s->s.code == (BPF_LD|BPF_IMM) && a1->s->s.k > 31)
+               /*
+                * XXX - we need to make up our minds as to what integers
+                * are signed and what integers are unsigned in BPF programs
+                * and in our IR.
+                */
+               if (a1->s->s.code == (BPF_LD|BPF_IMM) &&
+                   (a1->s->s.k < 0 || a1->s->s.k > 31))
                        bpf_error(cstate, "shift by more than 31 bits");
        }
        s0 = xfer_to_x(cstate, a1);