Commit 08f67e9fcc for frr
commit 08f67e9fcca09afaa837e8e6523500ada87df5e1
Author: Floatato <2264667392@qq.com>
Date: Thu Dec 3 00:54:37 2026 +0800
ospfd: handle NULL local_nexthop in TI-LFA SPF copy and link removal
When ospf_spf_next() expands a network-LSA, the router-LSA link pointer
remains NULL. If that transit network is not directly attached to the
SPF root, ospf_nexthop_calculation() inherits the parent's nexthop and
adds the router vertex parent with local_nexthop set to NULL.
TI-LFA then dereferences that NULL local_nexthop in two places:
- ospf_spf_vertex_parent_copy() unconditionally memcpy'd
vertex_parent->local_nexthop while copying the SPF tree for P-space
generation.
- ospf_spf_remove_link() dereferenced
vertex_parent->local_nexthop->router.s_addr without checking for NULL
when cutting a protected link from a P-space, Q-space, or inner
label-stack SPF tree.
Allocate and copy local_nexthop only when non-NULL, and skip parents
whose local_nexthop is NULL in ospf_spf_remove_link().
Signed-off-by: Floatato <2264667392@qq.com>
diff --git a/ospfd/ospf_spf.c b/ospfd/ospf_spf.c
index b5407c1977..cd5c0899e6 100644
--- a/ospfd/ospf_spf.c
+++ b/ospfd/ospf_spf.c
@@ -343,18 +343,21 @@ static struct vertex_parent *
ospf_spf_vertex_parent_copy(struct vertex_parent *vertex_parent)
{
struct vertex_parent *vertex_parent_copy;
- struct vertex_nexthop *nexthop_copy, *local_nexthop_copy;
+ struct vertex_nexthop *nexthop_copy;
+ struct vertex_nexthop *local_nexthop_copy = NULL;
vertex_parent_copy = XCALLOC(MTYPE_OSPF_VERTEX_PARENT, sizeof(struct vertex_parent));
nexthop_copy = vertex_nexthop_new();
- local_nexthop_copy = vertex_nexthop_new();
memcpy(vertex_parent_copy, vertex_parent, sizeof(struct vertex_parent));
memcpy(nexthop_copy, vertex_parent->nexthop,
sizeof(struct vertex_nexthop));
- memcpy(local_nexthop_copy, vertex_parent->local_nexthop,
- sizeof(struct vertex_nexthop));
+ if (vertex_parent->local_nexthop) {
+ local_nexthop_copy = vertex_nexthop_new();
+ memcpy(local_nexthop_copy, vertex_parent->local_nexthop,
+ sizeof(struct vertex_nexthop));
+ }
vertex_parent_copy->nexthop = nexthop_copy;
vertex_parent_copy->local_nexthop = local_nexthop_copy;
@@ -475,6 +478,8 @@ static int ospf_spf_remove_link(struct vertex *vertex, struct list *vertex_list,
for (ALL_LIST_ELEMENTS_RO(vertex->children, node, child)) {
for (ALL_LIST_ELEMENTS_RO(child->parents, inner_node,
vertex_parent)) {
+ if (!vertex_parent->local_nexthop)
+ continue;
if ((vertex_parent->local_nexthop->router.s_addr
& link->link_data.s_addr)
== (link->link_id.s_addr