Skip to content

Commit

Permalink
net/sockstats: prevent crash in setNetMon (tailscale#13985)
Browse files Browse the repository at this point in the history
(cherry picked from commit 6985369)
  • Loading branch information
agottardo committed Nov 1, 2024
1 parent d2914f5 commit b73831b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion net/sockstats/sockstats_tsgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,13 @@ func setNetMon(netMon *netmon.Monitor) {
if ifName == "" {
return
}
ifIndex := state.Interface[ifName].Index
// DefaultRouteInterface and Interface are gathered at different points in time.
// Check for existence first, to avoid a nil pointer dereference.
iface, ok := state.Interface[ifName]
if !ok {
return
}
ifIndex := iface.Index
sockStats.mu.Lock()
defer sockStats.mu.Unlock()
// Ignore changes to unknown interfaces -- it would require
Expand Down

0 comments on commit b73831b

Please sign in to comment.