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

(cherry picked from commit 6985369479)
This commit is contained in:
Andrea Gottardo authored and Andrea Gottardo committed 2024-11-01 11:16:26 -07:00
1 parent d2914f5ef2
commit b73831b2b5
1 file changed
+7 -1
+7 -1
View File
@@ -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