From: David Lamparter Date: Wed, 22 Jan 2025 10:17:21 +0000 (+0100) Subject: zebra: guard against junk in nexthop->rmap_src X-Git-Tag: docker/10.2.2~26^2~2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=abf1ef1324df929fe04d035ea77614b0c88f0020;p=mirror%2Ffrr.git zebra: guard against junk in nexthop->rmap_src rmap_src wasn't initialized, so for IPv4 the unused 12 bytes would contain whatever junk is on the stack on function entry. Also move the IPv4 parse before the IPv6 parse so if it's successful we can be sure the other bytes haven't been touched. Signed-off-by: David Lamparter (cherry picked from commit b666ee510eb480da50476b1bbc84bdf8365df95c) --- diff --git a/zebra/zebra_routemap.c b/zebra/zebra_routemap.c index 46afbcecfa..3acd53496d 100644 --- a/zebra/zebra_routemap.c +++ b/zebra/zebra_routemap.c @@ -964,10 +964,11 @@ route_set_src(void *rule, const struct prefix *prefix, void *object) /* set src compilation. */ static void *route_set_src_compile(const char *arg) { - union g_addr src, *psrc; + union g_addr src = {}, *psrc; - if ((inet_pton(AF_INET6, arg, &src.ipv6) == 1) - || (inet_pton(AF_INET, arg, &src.ipv4) == 1)) { + /* IPv4 first, to ensure no garbage in the 12 unused bytes */ + if ((inet_pton(AF_INET, arg, &src.ipv4) == 1) || + (inet_pton(AF_INET6, arg, &src.ipv6) == 1)) { psrc = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(union g_addr)); *psrc = src; return psrc;