state: fix routesChanged mutating input Hostinfo

routesChanged aliases newHI.RoutableIPs into a local variable then
sorts it in place, which mutates the caller's Hostinfo data. The
Hostinfo is subsequently stored on the node, so the mutation
propagates but the input contract is violated.

Clone the slice before sorting to avoid mutating the input.
This commit is contained in:
Kristoffer Dalby
2026-04-02 13:11:25 +00:00
committed by Kristoffer Dalby
parent 2a2d5c869a
commit 82bb4331f5

View File

@@ -2560,7 +2560,7 @@ func routesChanged(oldNode types.NodeView, newHI *tailcfg.Hostinfo) bool {
oldRoutes = oldNode.AsStruct().Hostinfo.RoutableIPs
}
newRoutes := newHI.RoutableIPs
newRoutes := slices.Clone(newHI.RoutableIPs)
if newRoutes == nil {
newRoutes = []netip.Prefix{}
}