summaryrefslogtreecommitdiff
path: root/sys/net/pf.c
diff options
context:
space:
mode:
authorAlexander Bluhm <bluhm@cvs.openbsd.org>2017-05-23 09:09:04 +0000
committerAlexander Bluhm <bluhm@cvs.openbsd.org>2017-05-23 09:09:04 +0000
commit05fe903bebd47592468eedb697b30db836c4e9a1 (patch)
tree36a2171f8b7aba4d5624a67f5f5c586299a058c7 /sys/net/pf.c
parent1da3f0878c5a208d7293eee857ea711007b8e4e0 (diff)
Move the common length check in pf_pull_hdr() after the address
family switch. This makes the specific calculation more obvious. OK claudio@
Diffstat (limited to 'sys/net/pf.c')
-rw-r--r--sys/net/pf.c24
1 files changed, 10 insertions, 14 deletions
diff --git a/sys/net/pf.c b/sys/net/pf.c
index d9b346aad39..2ad769c4d4a 100644
--- a/sys/net/pf.c
+++ b/sys/net/pf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pf.c,v 1.1026 2017/05/20 22:56:43 sashan Exp $ */
+/* $OpenBSD: pf.c,v 1.1027 2017/05/23 09:09:03 bluhm Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
@@ -5611,6 +5611,8 @@ void *
pf_pull_hdr(struct mbuf *m, int off, void *p, int len,
u_short *actionp, u_short *reasonp, sa_family_t af)
{
+ int iplen = 0;
+
switch (af) {
case AF_INET: {
struct ip *h = mtod(m, struct ip *);
@@ -5625,29 +5627,23 @@ pf_pull_hdr(struct mbuf *m, int off, void *p, int len,
}
return (NULL);
}
- if (m->m_pkthdr.len < off + len ||
- ntohs(h->ip_len) < off + len) {
- ACTION_SET(actionp, PF_DROP);
- REASON_SET(reasonp, PFRES_SHORT);
- return (NULL);
- }
+ iplen = ntohs(h->ip_len);
break;
}
#ifdef INET6
case AF_INET6: {
struct ip6_hdr *h = mtod(m, struct ip6_hdr *);
- if (m->m_pkthdr.len < off + len ||
- (ntohs(h->ip6_plen) + sizeof(struct ip6_hdr)) <
- (unsigned)(off + len)) {
- ACTION_SET(actionp, PF_DROP);
- REASON_SET(reasonp, PFRES_SHORT);
- return (NULL);
- }
+ iplen = ntohs(h->ip6_plen) + sizeof(struct ip6_hdr);
break;
}
#endif /* INET6 */
}
+ if (m->m_pkthdr.len < off + len || iplen < off + len) {
+ ACTION_SET(actionp, PF_DROP);
+ REASON_SET(reasonp, PFRES_SHORT);
+ return (NULL);
+ }
m_copydata(m, off, len, p);
return (p);
}