Skip to content

Commit 1dc7f42

Browse files
Merge pull request #88 from step-security/int
Add mutex for maps
2 parents 17b9b28 + 63ff285 commit 1dc7f42

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

eventhandler.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ func (eventHandler *EventHandler) GetToolChain(ppid, exe string) *Tool {
170170
tool := Tool{Name: filepath.Base(exe), SHA256: checksum}
171171

172172
// In some cases the process has already exited, so get from map first
173+
eventHandler.procMutex.Lock()
173174
parentProcess, found := eventHandler.ProcessMap[ppid]
175+
eventHandler.procMutex.Unlock()
174176

175177
if found {
176178
tool.Parent = eventHandler.GetToolChain(parentProcess.PPid, parentProcess.Exe)

netmon.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"sync"
56
"time"
67

78
"github.com/florianl/go-nflog/v2"
@@ -17,6 +18,7 @@ type NetworkMonitor struct {
1718
Repo string
1819
ApiClient *ApiClient
1920
Status string
21+
netMutex sync.RWMutex
2022
}
2123

2224
var ipAddresses = make(map[string]int)
@@ -84,6 +86,7 @@ func (netMonitor *NetworkMonitor) handlePacket(attrs nflog.Attribute) {
8486
if ipv4Layer := packet.Layer(layers.LayerTypeIPv4); ipv4Layer != nil {
8587
// Get actual TCP data from this layer
8688
ipv4, _ := ipv4Layer.(*layers.IPv4)
89+
netMonitor.netMutex.Lock()
8790
_, found := ipAddresses[ipv4.DstIP.String()]
8891
if !found {
8992
ipAddresses[ipv4.DstIP.String()] = 1
@@ -93,7 +96,7 @@ func (netMonitor *NetworkMonitor) handlePacket(attrs nflog.Attribute) {
9396
ipv4.DstIP.String(), port, netMonitor.Status, timestamp, Tool{Name: Unknown, SHA256: Unknown})
9497
}
9598
}
96-
99+
netMonitor.netMutex.Unlock()
97100
}
98101

99102
}

0 commit comments

Comments
 (0)