summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbrian <brian@openbsd.org>2001-11-23 17:12:20 +0000
committerbrian <brian@openbsd.org>2001-11-23 17:12:20 +0000
commit3df1af6198cd38a6ce1642f0fd2db6712e7b585c (patch)
treee35246f6f997027850dd82f34825c7bae08909d1
parentBe paranoid about non-zero netmasks being associated with INET addresses (diff)
downloadwireguard-openbsd-3df1af6198cd38a6ce1642f0fd2db6712e7b585c.tar.xz
wireguard-openbsd-3df1af6198cd38a6ce1642f0fd2db6712e7b585c.zip
When writing messages to the routing socket, round sockaddr sizes
up in the same way that we expect them to be when we read them. This is a no-op on i386 and probably on alphas, as we currently only support AF_INET and AF_INET6.
-rw-r--r--usr.sbin/ppp/ppp/route.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/usr.sbin/ppp/ppp/route.c b/usr.sbin/ppp/ppp/route.c
index 6bef97739f1..1c36189641c 100644
--- a/usr.sbin/ppp/ppp/route.c
+++ b/usr.sbin/ppp/ppp/route.c
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: route.c,v 1.20 2001/11/23 17:12:10 brian Exp $
+ * $OpenBSD: route.c,v 1.21 2001/11/23 17:12:20 brian Exp $
*/
#include <sys/param.h>
@@ -695,6 +695,19 @@ struct rtmsg {
char m_space[256];
};
+static size_t
+memcpy_roundup(char *cp, const void *data, size_t len)
+{
+ size_t padlen;
+
+ padlen = ROUNDUP(len);
+ memcpy(cp, data, len);
+ if (padlen > len)
+ memset(cp + len, '\0', padlen - len);
+
+ return padlen;
+}
+
int
rt_Set(struct bundle *bundle, int cmd, const struct ncprange *dst,
const struct ncpaddr *gw, int bang, int quiet)
@@ -737,8 +750,7 @@ rt_Set(struct bundle *bundle, int cmd, const struct ncprange *dst,
ncprange_getsa(dst, &sadst, &samask);
cp = rtmes.m_space;
- memcpy(cp, &sadst, sadst.ss_len);
- cp += sadst.ss_len;
+ cp += memcpy_roundup(cp, &sadst, sadst.ss_len);
if (cmd == RTM_ADD) {
if (gw == NULL) {
log_Printf(LogERROR, "rt_Set: Program error\n");
@@ -753,15 +765,13 @@ rt_Set(struct bundle *bundle, int cmd, const struct ncprange *dst,
close(s);
return result;
} else {
- memcpy(cp, &sagw, sagw.ss_len);
- cp += sagw.ss_len;
+ cp += memcpy_roundup(cp, &sagw, sagw.ss_len);
rtmes.m_rtm.rtm_addrs |= RTA_GATEWAY;
}
}
if (!ncprange_ishost(dst)) {
- memcpy(cp, &samask, samask.ss_len);
- cp += samask.ss_len;
+ cp += memcpy_roundup(cp, &samask, samask.ss_len);
rtmes.m_rtm.rtm_addrs |= RTA_NETMASK;
}
@@ -855,8 +865,7 @@ rt_Update(struct bundle *bundle, const struct sockaddr *dst,
if (dst) {
rtmes.m_rtm.rtm_addrs |= RTA_DST;
- memcpy(p, dst, dst->sa_len);
- p += dst->sa_len;
+ p += memcpy_roundup(p, dst, dst->sa_len);
}
#ifdef __FreeBSD__
@@ -876,12 +885,10 @@ rt_Update(struct bundle *bundle, const struct sockaddr *dst,
#endif
{
rtmes.m_rtm.rtm_addrs |= RTA_GATEWAY;
- memcpy(p, gw, gw->sa_len);
- p += gw->sa_len;
+ p += memcpy_roundup(p, gw, gw->sa_len);
if (mask) {
rtmes.m_rtm.rtm_addrs |= RTA_NETMASK;
- memcpy(p, mask, mask->sa_len);
- p += mask->sa_len;
+ p += memcpy_roundup(p, mask, mask->sa_len);
}
}