summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorPatrick Wildt <patrick@cvs.openbsd.org>2018-03-31 17:09:57 +0000
committerPatrick Wildt <patrick@cvs.openbsd.org>2018-03-31 17:09:57 +0000
commitb63fa6bd8c645f3c75303cb93715a706d55b5479 (patch)
treeda491b1b61ebb9d1a7935869bd4963121efaf322 /sys
parentbbfb464cce68b6ce7ba5f4432c65e5e6c5ecb4db (diff)
Stop converting UDP and IP header values from network endianness to host
endianness for convenience reasons. Especially in code pathes like TFTP where the source port is read from the received UDP packet and used as destination port in a new UDP packet this can be very harmful. Luckily this issue has had no effect on our architectures since they never use any of the code paths that could be harmful. ok visa@
Diffstat (limited to 'sys')
-rw-r--r--sys/lib/libsa/netudp.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/sys/lib/libsa/netudp.c b/sys/lib/libsa/netudp.c
index 0199caaede5..fcf6351d6c4 100644
--- a/sys/lib/libsa/netudp.c
+++ b/sys/lib/libsa/netudp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: netudp.c,v 1.3 2015/07/16 16:12:15 mpi Exp $ */
+/* $OpenBSD: netudp.c,v 1.4 2018/03/31 17:09:56 patrick Exp $ */
/* $NetBSD: net.c,v 1.14 1996/10/13 02:29:02 christos Exp $ */
/*
@@ -183,11 +183,11 @@ readudp(struct iodesc *d, void *pkt, size_t len, time_t tleft)
#endif
return -1;
}
- ip->ip_len = ntohs(ip->ip_len);
- if (n < ip->ip_len) {
+ if (n < ntohs(ip->ip_len)) {
#ifdef NET_DEBUG
if (debug)
- printf("readudp: bad length %d < %d.\n", n, ip->ip_len);
+ printf("readudp: bad length %d < %d.\n",
+ n, ntohs(ip->ip_len));
#endif
return -1;
}
@@ -204,7 +204,7 @@ readudp(struct iodesc *d, void *pkt, size_t len, time_t tleft)
/* If there were ip options, make them go away */
if (hlen != sizeof(*ip)) {
bcopy(((u_char *)ip) + hlen, uh, len - hlen);
- ip->ip_len = sizeof(*ip);
+ ip->ip_len = htons(sizeof(*ip));
n -= hlen - sizeof(*ip);
}
if (uh->uh_dport != d->myport) {
@@ -238,14 +238,11 @@ readudp(struct iodesc *d, void *pkt, size_t len, time_t tleft)
}
*ip = tip;
}
- uh->uh_dport = ntohs(uh->uh_dport);
- uh->uh_sport = ntohs(uh->uh_sport);
- uh->uh_ulen = ntohs(uh->uh_ulen);
- if (uh->uh_ulen < sizeof(*uh)) {
+ if (ntohs(uh->uh_ulen) < sizeof(*uh)) {
#ifdef NET_DEBUG
if (debug)
printf("readudp: bad udp len %d < %d\n",
- uh->uh_ulen, sizeof(*uh));
+ ntohs(uh->uh_ulen), sizeof(*uh));
#endif
return -1;
}