Commit da73d4f165 for frr
commit da73d4f165a84d2fbbcdbee119ce634275d54b1e
Author: Dave Seddon <dave.seddon.ca@gmail.com>
Date: Sat Nov 28 21:21:24 2026 -0800
pimd: bound and terminate nexthop lookup opaque data
zclient_read_nexthop() copied the opaque data of zebra's
ZEBRA_NEXTHOP_LOOKUP reply into a ZAPI_MESSAGE_OPAQUE_LENGTH stack
buffer without checking its length, and for BGP routes parsed it with
strtoll() without making sure it is NUL terminated.
zebra limits opaque data to ZAPI_MESSAGE_OPAQUE_LENGTH and bgpd's
opaque starts with a NUL-terminated AS path, so this is not reachable
from zebra and bgpd today.
Fail the lookup when the length is larger than the buffer, and NUL
terminate the copy.
Fixes: 29c925c79bd9 ("pimd,pim6d,zebra: add opaque data on route lookup")
Signed-off-by: Dave Seddon <dave.seddon.ca@gmail.com>
diff --git a/pimd/pim_zlookup.c b/pimd/pim_zlookup.c
index 998871b555..250b1df822 100644
--- a/pimd/pim_zlookup.c
+++ b/pimd/pim_zlookup.c
@@ -154,7 +154,7 @@ static int zclient_read_nexthop(struct zclient_next_hop_args *args)
int i, err;
uint32_t opaque_data_length;
long long first_asn;
- char opaque_data[ZAPI_MESSAGE_OPAQUE_LENGTH];
+ char opaque_data[ZAPI_MESSAGE_OPAQUE_LENGTH + 1];
if (PIM_DEBUG_PIM_NHT_DETAIL)
zlog_debug("%s: addr=%pPAs(%s)", __func__, &args->address, args->pim->vrf->name);
@@ -202,8 +202,15 @@ static int zclient_read_nexthop(struct zclient_next_hop_args *args)
args->route_type = stream_getl(s);
opaque_data_length = stream_getl(s);
+ if (opaque_data_length > ZAPI_MESSAGE_OPAQUE_LENGTH) {
+ flog_err(EC_LIB_ZAPI_MISSMATCH, "%s: bad opaque data length %u", __func__,
+ opaque_data_length);
+ zclient_lookup_failed(args->zlookup);
+ return -1;
+ }
if (opaque_data_length > 0)
stream_get(opaque_data, s, opaque_data_length);
+ opaque_data[opaque_data_length] = '\0';
nexthop_num = stream_getw(s);