patch.txt

guy, 09/01/2010 08:42 AM

Download (1.18 KB)

 
1
--- pcap-bpf.c.orig	2010-09-01 01:37:34.000000000 -0700
2
+++ pcap-bpf.c	2010-09-01 01:38:48.000000000 -0700
3
@@ -846,14 +846,28 @@
4
 		 * processed so far.
5
 		 */
6
 		if (p->break_loop) {
7
+			p->bp = bp;
8
+			p->cc = ep - bp;
9
+			/*
10
+			 * ep is set based on the return value of read(),
11
+			 * but read() from a BPF device doesn't necessarily
12
+			 * return a value that's a multiple of the alignment
13
+			 * value for BPF_WORDALIGN().  However, whenever we
14
+			 * increment bp, we round up the increment value by
15
+			 * a value rounded up by BPF_WORDALIGN(), so we
16
+			 * could increment bp past ep after processing the
17
+			 * last packet in the buffer.
18
+			 *
19
+			 * We treat ep < bp as an indication that this
20
+			 * happened, and just set p->cc to 0.
21
+			 */
22
+			if (p->cc < 0)
23
+				p->cc = 0;
24
 			if (n == 0) {
25
 				p->break_loop = 0;
26
 				return (PCAP_ERROR_BREAK);
27
-			} else {
28
-				p->bp = bp;
29
-				p->cc = ep - bp;
30
+			} else
31
 				return (n);
32
-			}
33
 		}
34
 
35
 		caplen = bhp->bh_caplen;
36
@@ -905,6 +919,11 @@
37
 			if (++n >= cnt && cnt > 0) {
38
 				p->bp = bp;
39
 				p->cc = ep - bp;
40
+				/*
41
+				 * See comment above about p->cc < 0.
42
+				 */
43
+				if (p->cc < 0)
44
+					p->cc = 0;
45
 				return (n);
46
 			}
47
 		} else {