From c191236e3c50491c4c54ddf2c60552c7db3568c8 Mon Sep 17 00:00:00 2001 From: tobhe Date: Fri, 26 Feb 2021 20:22:11 +0000 Subject: [PATCH] Fix and improve handling of address families in vroute_getcloneroute(). ok patrick@ --- sbin/iked/vroute.c | 36 +++++++++--------------------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/sbin/iked/vroute.c b/sbin/iked/vroute.c index 47496c053ef..e4e47f3eccc 100644 --- a/sbin/iked/vroute.c +++ b/sbin/iked/vroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vroute.c,v 1.2 2021/02/21 14:21:37 tobhe Exp $ */ +/* $OpenBSD: vroute.c,v 1.3 2021/02/26 20:22:11 tobhe Exp $ */ /* * Copyright (c) 2021 Tobias Heider @@ -285,19 +285,13 @@ vroute_getcloneroute(struct iked *env, struct imsg *imsg) struct sockaddr_storage addr; uint8_t *ptr; size_t left; - uint8_t af, rdomain; + uint8_t rdomain; int flags; int addrs; ptr = (uint8_t *)imsg->data; left = IMSG_DATA_SIZE(imsg); - if (left < sizeof(af)) - return (-1); - af = *ptr; - ptr += sizeof(af); - left -= sizeof(af); - if (left < sizeof(rdomain)) return (-1); rdomain = *ptr; @@ -308,26 +302,14 @@ vroute_getcloneroute(struct iked *env, struct imsg *imsg) bzero(&mask, sizeof(mask)); bzero(&addr, sizeof(addr)); - switch(af) { - case AF_INET: - if (left < sizeof(struct sockaddr_in)) - return (-1); - dst = (struct sockaddr *)ptr;; - memcpy(&dest, ptr, sizeof(struct sockaddr_in));; - ptr += sizeof(struct sockaddr_in); - left -= sizeof(struct sockaddr_in); - break; - case AF_INET6: - if (left < sizeof(struct sockaddr_in6)) - return (-1); - dst = (struct sockaddr *)ptr;; - memcpy(&dest, ptr, sizeof(struct sockaddr_in6));; - ptr += sizeof(struct sockaddr_in6); - left -= sizeof(struct sockaddr_in6); - break; - default: + if (left < sizeof(struct sockaddr)) return (-1); - } + dst = (struct sockaddr *)ptr; + if (left < dst->sa_len) + return (-1); + memcpy(&dest, ptr, dst->sa_len); + ptr += dst->sa_len; + left -= dst->sa_len; /* Get route to peer */ flags = RTF_UP | RTF_GATEWAY | RTF_HOST | RTF_STATIC; -- 2.20.1