net/sockstats: prevent crash in setNetMon (#13985)

pull/13987/head
Andrea Gottardo 3 weeks ago committed by GitHub
parent 3477bfd234
commit 6985369479
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -279,7 +279,13 @@ func setNetMon(netMon *netmon.Monitor) {
if ifName == "" { if ifName == "" {
return 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() sockStats.mu.Lock()
defer sockStats.mu.Unlock() defer sockStats.mu.Unlock()
// Ignore changes to unknown interfaces -- it would require // Ignore changes to unknown interfaces -- it would require

Loading…
Cancel
Save