diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2005-07-29 17:26:29 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2005-07-29 17:26:29 +0000 |
commit | 9cc8316d5183e6f86ed8714b7a5a190d9b26d73b (patch) | |
tree | 004cced236533ae90197723d5b79a44f279a91b3 /sbin/dhclient | |
parent | dd7208a2a83634e330093dbca7b961ce4e77645e (diff) |
Fix erroneous use of '=' instead of '+' that caused infinite loops
when skipping packets. Use BPF_WORDALIGN() to properly skip packets.
From Brooks Davis at FreeBSD.
ok deraadt@ henning@
Diffstat (limited to 'sbin/dhclient')
-rw-r--r-- | sbin/dhclient/bpf.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/sbin/dhclient/bpf.c b/sbin/dhclient/bpf.c index 131a88f743d..eedaeb4a057 100644 --- a/sbin/dhclient/bpf.c +++ b/sbin/dhclient/bpf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bpf.c,v 1.13 2004/05/05 14:28:58 deraadt Exp $ */ +/* $OpenBSD: bpf.c,v 1.14 2005/07/29 17:26:28 krw Exp $ */ /* BPF socket interface code, originally contributed by Archie Cobbs. */ @@ -285,7 +285,7 @@ receive_packet(struct interface_info *interface, unsigned char *buf, if (length <= 0) return (length); interface->rbuf_offset = 0; - interface->rbuf_len = length; + interface->rbuf_len = BPF_WORDALIGN(length); } /* @@ -319,7 +319,9 @@ receive_packet(struct interface_info *interface, unsigned char *buf, * do is drop it. */ if (hdr.bh_caplen != hdr.bh_datalen) { - interface->rbuf_offset += hdr.bh_hdrlen = hdr.bh_caplen; + interface->rbuf_offset = BPF_WORDALIGN( + interface->rbuf_offset + hdr.bh_hdrlen + + hdr.bh_caplen); continue; } @@ -336,7 +338,8 @@ receive_packet(struct interface_info *interface, unsigned char *buf, * this packet. */ if (offset < 0) { - interface->rbuf_offset += hdr.bh_caplen; + interface->rbuf_offset = BPF_WORDALIGN( + interface->rbuf_offset + hdr.bh_caplen); continue; } interface->rbuf_offset += offset; @@ -348,7 +351,8 @@ receive_packet(struct interface_info *interface, unsigned char *buf, /* If the IP or UDP checksum was bad, skip the packet... */ if (offset < 0) { - interface->rbuf_offset += hdr.bh_caplen; + interface->rbuf_offset = BPF_WORDALIGN( + interface->rbuf_offset + hdr.bh_caplen); continue; } interface->rbuf_offset += offset; @@ -360,14 +364,16 @@ receive_packet(struct interface_info *interface, unsigned char *buf, * life, though). */ if (hdr.bh_caplen > len) { - interface->rbuf_offset += hdr.bh_caplen; + interface->rbuf_offset = BPF_WORDALIGN( + interface->rbuf_offset + hdr.bh_caplen); continue; } /* Copy out the data in the packet... */ memcpy(buf, interface->rbuf + interface->rbuf_offset, hdr.bh_caplen); - interface->rbuf_offset += hdr.bh_caplen; + interface->rbuf_offset = BPF_WORDALIGN(interface->rbuf_offset + + hdr.bh_caplen); return (hdr.bh_caplen); } while (!length); return (0); |