aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorguy <guy>2007-12-05 23:37:26 +0000
committerguy <guy>2007-12-05 23:37:26 +0000
commit91326ea08c76f15a6366638f9e46607cf1580f84 (patch)
treea1e0c43240ec9900687af693192944187a52325a
parentbaa8f1a126249af1b2874c015feb200a49b49ed8 (diff)
Don't assume that p->fcode.bpf_insns remains unchanged while processing
a bufferfull of packets - it could get changed in a callback routine.
-rw-r--r--pcap-bpf.c11
-rw-r--r--pcap-dlpi.c6
-rw-r--r--pcap-dos.c5
-rw-r--r--pcap-nit.c5
-rw-r--r--pcap-pf.c11
-rw-r--r--pcap-snit.c5
6 files changed, 18 insertions, 25 deletions
diff --git a/pcap-bpf.c b/pcap-bpf.c
index ecbc3ed7..db451246 100644
--- a/pcap-bpf.c
+++ b/pcap-bpf.c
@@ -20,7 +20,7 @@
*/
#ifndef lint
static const char rcsid[] _U_ =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-bpf.c,v 1.99 2007-06-15 17:55:50 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-bpf.c,v 1.100 2007-12-05 23:37:26 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@@ -144,12 +144,10 @@ pcap_read_bpf(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
int n = 0;
register u_char *bp, *ep;
u_char *datap;
- struct bpf_insn *fcode;
#ifdef PCAP_FDDIPAD
register int pad;
#endif
- fcode = p->md.use_bpf ? NULL : p->fcode.bf_insns;
again:
/*
* Has "pcap_breakloop()" been called?
@@ -260,7 +258,8 @@ pcap_read_bpf(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
datap = bp + hdrlen;
/*
* Short-circuit evaluation: if using BPF filter
- * in kernel, no need to do it now.
+ * in kernel, no need to do it now - we already know
+ * the packet passed the filter.
*
#ifdef PCAP_FDDIPAD
* Note: the filter code was generated assuming
@@ -270,8 +269,8 @@ pcap_read_bpf(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
* skipping that padding.
#endif
*/
- if (fcode == NULL ||
- bpf_filter(fcode, datap, bhp->bh_datalen, caplen)) {
+ if (p->md.use_bpf ||
+ bpf_filter(p->fcode.bf_insns, datap, bhp->bh_datalen, caplen)) {
struct pcap_pkthdr pkthdr;
pkthdr.ts.tv_sec = bhp->bh_tstamp.tv_sec;
diff --git a/pcap-dlpi.c b/pcap-dlpi.c
index 1345525e..b867d04b 100644
--- a/pcap-dlpi.c
+++ b/pcap-dlpi.c
@@ -70,7 +70,7 @@
#ifndef lint
static const char rcsid[] _U_ =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-dlpi.c,v 1.116 2006-04-04 05:32:27 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-dlpi.c,v 1.117 2007-12-05 23:37:26 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@@ -245,7 +245,6 @@ pcap_read_dlpi(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
{
register int cc, n, caplen, origlen;
register u_char *bp, *ep, *pk;
- register struct bpf_insn *fcode;
#ifdef HAVE_SYS_BUFMOD_H
register struct sb_hdr *sbp;
#ifdef LBL_ALIGN
@@ -303,7 +302,6 @@ pcap_read_dlpi(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
bp = p->bp;
/* Loop through packets */
- fcode = p->fcode.bf_insns;
ep = bp + cc;
n = 0;
#ifdef HAVE_SYS_BUFMOD_H
@@ -346,7 +344,7 @@ pcap_read_dlpi(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
bp += caplen;
#endif
++p->md.stat.ps_recv;
- if (bpf_filter(fcode, pk, origlen, caplen)) {
+ if (bpf_filter(p->fcode.bf_insns, pk, origlen, caplen)) {
#ifdef HAVE_SYS_BUFMOD_H
pkthdr.ts.tv_sec = sbp->sbh_timestamp.tv_sec;
pkthdr.ts.tv_usec = sbp->sbh_timestamp.tv_usec;
diff --git a/pcap-dos.c b/pcap-dos.c
index 9e4df2b3..426a4fd9 100644
--- a/pcap-dos.c
+++ b/pcap-dos.c
@@ -5,7 +5,7 @@
* pcap-dos.c: Interface to PKTDRVR, NDIS2 and 32-bit pmode
* network drivers.
*
- * @(#) $Header: /tcpdump/master/libpcap/pcap-dos.c,v 1.2 2005-05-03 18:53:59 guy Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/libpcap/pcap-dos.c,v 1.3 2007-12-05 23:37:26 guy Exp $ (LBL)
*/
#include <stdio.h>
@@ -205,7 +205,6 @@ static int
pcap_read_one (pcap_t *p, pcap_handler callback, u_char *data)
{
struct pcap_pkthdr pcap;
- struct bpf_insn *fcode = p->fcode.bf_insns;
struct timeval now, expiry;
BYTE *rx_buf;
int rx_len = 0;
@@ -258,7 +257,7 @@ pcap_read_one (pcap_t *p, pcap_handler callback, u_char *data)
pcap.len = rx_len;
if (callback &&
- (!fcode || bpf_filter(fcode, rx_buf, pcap.len, pcap.caplen)))
+ (!p->fcode.bf_insns || bpf_filter(p->fcode.bf_insns, rx_buf, pcap.len, pcap.caplen)))
{
filter_count++;
diff --git a/pcap-nit.c b/pcap-nit.c
index 3ef52452..1e16ab44 100644
--- a/pcap-nit.c
+++ b/pcap-nit.c
@@ -20,7 +20,7 @@
*/
#ifndef lint
static const char rcsid[] _U_ =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-nit.c,v 1.58 2005-05-03 18:54:00 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-nit.c,v 1.59 2007-12-05 23:37:26 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@@ -99,7 +99,6 @@ static int
pcap_read_nit(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
{
register int cc, n;
- register struct bpf_insn *fcode = p->fcode.bf_insns;
register u_char *bp, *cp, *ep;
register struct nit_hdr *nh;
register int caplen;
@@ -175,7 +174,7 @@ pcap_read_nit(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
caplen = nh->nh_wirelen;
if (caplen > p->snapshot)
caplen = p->snapshot;
- if (bpf_filter(fcode, cp, nh->nh_wirelen, caplen)) {
+ if (bpf_filter(p->fcode.bf_insns, cp, nh->nh_wirelen, caplen)) {
struct pcap_pkthdr h;
h.ts = nh->nh_timestamp;
h.len = nh->nh_wirelen;
diff --git a/pcap-pf.c b/pcap-pf.c
index f73beaac..c85595fe 100644
--- a/pcap-pf.c
+++ b/pcap-pf.c
@@ -24,7 +24,7 @@
#ifndef lint
static const char rcsid[] _U_ =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-pf.c,v 1.94 2006-10-04 18:09:22 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-pf.c,v 1.95 2007-12-05 23:37:26 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@@ -88,7 +88,6 @@ static int
pcap_read_pf(pcap_t *pc, int cnt, pcap_handler callback, u_char *user)
{
register u_char *p, *bp;
- struct bpf_insn *fcode;
register int cc, n, buflen, inc;
register struct enstamp *sp;
#ifdef LBL_ALIGN
@@ -98,7 +97,6 @@ pcap_read_pf(pcap_t *pc, int cnt, pcap_handler callback, u_char *user)
register int pad;
#endif
- fcode = pc->md.use_bpf ? NULL : pc->fcode.bf_insns;
again:
cc = pc->cc;
if (cc == 0) {
@@ -187,7 +185,8 @@ pcap_read_pf(pcap_t *pc, int cnt, pcap_handler callback, u_char *user)
/*
* Short-circuit evaluation: if using BPF filter
- * in kernel, no need to do it now.
+ * in kernel, no need to do it now - we already know
+ * the packet passed the filter.
*
#ifdef PCAP_FDDIPAD
* Note: the filter code was generated assuming
@@ -197,8 +196,8 @@ pcap_read_pf(pcap_t *pc, int cnt, pcap_handler callback, u_char *user)
* skipping that padding.
#endif
*/
- if (fcode == NULL ||
- bpf_filter(fcode, p, sp->ens_count, buflen)) {
+ if (pc->md.use_bpf ||
+ bpf_filter(pc->fcode.bf_insns, p, sp->ens_count, buflen)) {
struct pcap_pkthdr h;
pc->md.TotAccepted++;
h.ts = sp->ens_tstamp;
diff --git a/pcap-snit.c b/pcap-snit.c
index 35004815..bb9e02e8 100644
--- a/pcap-snit.c
+++ b/pcap-snit.c
@@ -25,7 +25,7 @@
#ifndef lint
static const char rcsid[] _U_ =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-snit.c,v 1.73 2005-05-03 18:54:00 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-snit.c,v 1.74 2007-12-05 23:37:26 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@@ -113,7 +113,6 @@ static int
pcap_read_snit(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
{
register int cc, n;
- register struct bpf_insn *fcode = p->fcode.bf_insns;
register u_char *bp, *cp, *ep;
register struct nit_bufhdr *hdrp;
register struct nit_iftime *ntp;
@@ -187,7 +186,7 @@ pcap_read_snit(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
if (caplen > p->snapshot)
caplen = p->snapshot;
- if (bpf_filter(fcode, cp, nlp->nh_pktlen, caplen)) {
+ if (bpf_filter(p->fcode.bf_insns, cp, nlp->nh_pktlen, caplen)) {
struct pcap_pkthdr h;
h.ts = ntp->nh_timestamp;
h.len = nlp->nh_pktlen;