31 lines
724 B
Markdown
31 lines
724 B
Markdown
# UNDF: UNDF-2026-000000479
|
||
# nomad-0004: checkstore.shim.Difference — O(current × ids)
|
||
|
||
## CWE
|
||
CWE-407: Inefficient Algorithmic Complexity
|
||
|
||
## Severity
|
||
MEDIUM
|
||
|
||
## Location
|
||
`client/serviceregistration/checks/checkstore/shim.go:152-155`
|
||
|
||
## Description
|
||
`Difference` iterates over all stored check IDs for an allocation and for
|
||
each calls `slices.Contains(ids, id)` — a linear scan over the input slice.
|
||
|
||
```go
|
||
for id := range s.current[allocID] {
|
||
if !slices.Contains(ids, id) { // O(|ids|)
|
||
remove = append(remove, id)
|
||
}
|
||
}
|
||
```
|
||
|
||
With C stored checks and I input IDs: O(C × I).
|
||
|
||
## Fix
|
||
Build a `map[structs.CheckID]struct{}` from `ids` before the loop.
|
||
|
||
## Speedup
|
||
~Ix speedup where I = len(ids).
|