From af7d59dac2eee0e5a6f40022319243e7b9dec23c Mon Sep 17 00:00:00 2001 From: "Mohamed S. Mahmoud" <mmahmoud@redhat.com> Date: Tue, 1 Aug 2023 07:24:40 -0400 Subject: [PATCH] NETOBSERV-1223: check Maps to make sure not nil b4 iterating (#167) Signed-off-by: msherif1234 <mmahmoud@redhat.com> --- pkg/ebpf/tracer.go | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/pkg/ebpf/tracer.go b/pkg/ebpf/tracer.go index 4aa7b2dea..0db9308c2 100644 --- a/pkg/ebpf/tracer.go +++ b/pkg/ebpf/tracer.go @@ -406,12 +406,14 @@ func (m *FlowFetcher) lookupAndDeleteDNSMap(timeOut time.Duration) { var dnsKey BpfDnsFlowId var dnsVal uint64 - iterator := dnsMap.Iterate() - for iterator.Next(&dnsKey, &dnsVal) { - if time.Duration(uint64(monotonicTimeNow)-dnsVal) >= timeOut { - if err := dnsMap.Delete(dnsKey); err != nil { - log.WithError(err).WithField("dnsKey", dnsKey). - Warnf("couldn't delete DNS record entry") + if dnsMap != nil { + iterator := dnsMap.Iterate() + for iterator.Next(&dnsKey, &dnsVal) { + if time.Duration(uint64(monotonicTimeNow)-dnsVal) >= timeOut { + if err := dnsMap.Delete(dnsKey); err != nil { + log.WithError(err).WithField("dnsKey", dnsKey). + Warnf("couldn't delete DNS record entry") + } } } } @@ -425,12 +427,14 @@ func (m *FlowFetcher) lookupAndDeleteRTTMap(timeOut time.Duration) { var rttKey BpfFlowSeqId var rttVal uint64 - iterator := rttMap.Iterate() - for iterator.Next(&rttKey, &rttVal) { - if time.Duration(uint64(monotonicTimeNow)-rttVal) >= timeOut { - if err := rttMap.Delete(rttKey); err != nil { - log.WithError(err).WithField("rttKey", rttKey). - Warnf("couldn't delete RTT record entry") + if rttMap != nil { + iterator := rttMap.Iterate() + for iterator.Next(&rttKey, &rttVal) { + if time.Duration(uint64(monotonicTimeNow)-rttVal) >= timeOut { + if err := rttMap.Delete(rttKey); err != nil { + log.WithError(err).WithField("rttKey", rttKey). + Warnf("couldn't delete RTT record entry") + } } } } -- GitLab