summaryrefslogtreecommitdiffstats
path: root/usr.sbin/arp/arp.c
diff options
context:
space:
mode:
authorbluhm <bluhm@openbsd.org>2019-08-29 19:11:15 +0000
committerbluhm <bluhm@openbsd.org>2019-08-29 19:11:15 +0000
commit13c7533756af4304e1094916411fdf9e3e5c954d (patch)
tree2f4048cc13b281e84800e8a32463f467b8034803 /usr.sbin/arp/arp.c
parentIn the HTML formatter, assert(3) that no HTML nesting violation occurs. (diff)
downloadwireguard-openbsd-13c7533756af4304e1094916411fdf9e3e5c954d.tar.xz
wireguard-openbsd-13c7533756af4304e1094916411fdf9e3e5c954d.zip
The IFP address in arp(8) used some bytes from a location depending
on sizeof(long) as sockaddr_dl. We were lucky and it worked. Use the correct size and the algorithm from route(8) for arp(8). OK mpi@
Diffstat (limited to 'usr.sbin/arp/arp.c')
-rw-r--r--usr.sbin/arp/arp.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/usr.sbin/arp/arp.c b/usr.sbin/arp/arp.c
index 02c3874039b..21524c1e1cd 100644
--- a/usr.sbin/arp/arp.c
+++ b/usr.sbin/arp/arp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: arp.c,v 1.84 2019/08/27 20:50:36 kn Exp $ */
+/* $OpenBSD: arp.c,v 1.85 2019/08/29 19:11:15 bluhm Exp $ */
/* $NetBSD: arp.c,v 1.12 1995/04/24 13:25:18 cgd Exp $ */
/*
@@ -91,8 +91,9 @@ static int rdomain;
extern int h_errno;
/* ROUNDUP() is nasty, but it is identical to what's in the kernel. */
-#define ROUNDUP(a) \
+#define ROUNDUP(a) \
((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
+#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
/* which function we're supposed to do */
#define F_GET 1
@@ -282,7 +283,7 @@ parse_host(const char *host, struct in_addr *in)
struct sockaddr_in so_mask = { 8, 0, 0, { 0xffffffff } };
struct sockaddr_inarp blank_sin = { sizeof(blank_sin), AF_INET }, sin_m;
struct sockaddr_dl blank_sdl = { sizeof(blank_sdl), AF_LINK }, sdl_m;
-struct sockaddr_dl ifp_m = { sizeof(&ifp_m), AF_LINK };
+struct sockaddr_dl ifp_m = { sizeof(ifp_m), AF_LINK };
time_t expire_time;
int flags, export_only, doing_proxy, found_entry;
struct {
@@ -672,10 +673,11 @@ rtmsg(int cmd)
rtm->rtm_addrs |= (RTA_DST | RTA_IFP);
}
-#define NEXTADDR(w, s) \
- if (rtm->rtm_addrs & (w)) { \
- memcpy(cp, &s, sizeof(s)); \
- cp += ROUNDUP(sizeof(s)); \
+#define NEXTADDR(w, s) \
+ if (rtm->rtm_addrs & (w)) { \
+ l = ROUNDUP(((struct sockaddr *)&(s))->sa_len); \
+ memcpy(cp, &(s), l); \
+ cp += l; \
}
NEXTADDR(RTA_DST, sin_m);
@@ -732,7 +734,7 @@ rtget(struct sockaddr_inarp **sinp, struct sockaddr_dl **sdlp)
default:
break;
}
- cp += ROUNDUP(sa->sa_len);
+ ADVANCE(cp, sa);
}
}
}