]> git.puffer.fish Git - mirror/frr.git/commitdiff
zebra: guard against junk in nexthop->rmap_src
authorDavid Lamparter <equinox@opensourcerouting.org>
Wed, 22 Jan 2025 10:17:21 +0000 (11:17 +0100)
committerDavid Lamparter <equinox@opensourcerouting.org>
Tue, 11 Feb 2025 08:50:25 +0000 (09:50 +0100)
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 <equinox@opensourcerouting.org>
(cherry picked from commit b666ee510eb480da50476b1bbc84bdf8365df95c)

zebra/zebra_routemap.c

index aa37d88890cb2f3f03fc83977dfeab6a31797dc3..acab4787baee1f76f1e5bfd4d5b66325c291f620 100644 (file)
@@ -1439,10 +1439,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;