]> The Tcpdump Group git mirrors - libpcap/commitdiff
In userland, sign extend the offset for JA instructions.
authorGuy Harris <[email protected]>
Thu, 5 May 2011 05:28:53 +0000 (22:28 -0700)
committerGuy Harris <[email protected]>
Thu, 5 May 2011 05:28:53 +0000 (22:28 -0700)
We currently use that to implement "ip6 protochain", and "pc" might be
wider than "pc->k", in which case we need to arrange that "pc->k" be
sign-extended, by casting it to bpf_int32.

bpf/net/bpf_filter.c

index 22aff79362076d98528883e4b14332e2595eb357..0c4fb006165f2aa74cd24bde2d7d7ea6e7a6bb9c 100644 (file)
@@ -405,7 +405,18 @@ bpf_filter(pc, p, wirelen, buflen)
                        continue;
 
                case BPF_JMP|BPF_JA:
+#if defined(KERNEL) || defined(_KERNEL)
+                       /*
+                        * No backward jumps allowed.
+                        */
                        pc += pc->k;
+#else
+                       /*
+                        * XXX - we currently implement "ip6 protochain"
+                        * with backward jumps, so sign-extend pc->k.
+                        */
+                       pc += (bpf_int32)pc->k;
+#endif
                        continue;
 
                case BPF_JMP|BPF_JGT|BPF_K: