mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-04-28 03:20:11 +00:00
Tighten integer and allocation bounds for CodeQL
This commit is contained in:
parent
9155480bbd
commit
177ae5f6da
5 changed files with 63 additions and 22 deletions
|
|
@ -182,6 +182,25 @@ type PatrolRunHistoryStore struct {
|
||||||
onSaveError func(err error)
|
onSaveError func(err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func clampHistoryCount(value, minValue, maxValue int) int {
|
||||||
|
if value < minValue {
|
||||||
|
return minValue
|
||||||
|
}
|
||||||
|
if value > maxValue {
|
||||||
|
return maxValue
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
func normalizeHistoryRequestCount(requested, storeMax, available int) int {
|
||||||
|
if requested <= 0 {
|
||||||
|
requested = MaxPatrolRunHistory
|
||||||
|
}
|
||||||
|
requested = clampHistoryCount(requested, 0, MaxPatrolRunHistory)
|
||||||
|
requested = clampHistoryCount(requested, 0, storeMax)
|
||||||
|
return clampHistoryCount(requested, 0, available)
|
||||||
|
}
|
||||||
|
|
||||||
// NewPatrolRunHistoryStore creates a new patrol run history store
|
// NewPatrolRunHistoryStore creates a new patrol run history store
|
||||||
func NewPatrolRunHistoryStore(maxRuns int) *PatrolRunHistoryStore {
|
func NewPatrolRunHistoryStore(maxRuns int) *PatrolRunHistoryStore {
|
||||||
if maxRuns <= 0 {
|
if maxRuns <= 0 {
|
||||||
|
|
@ -258,12 +277,7 @@ func (s *PatrolRunHistoryStore) GetRecent(n int) []PatrolRunRecord {
|
||||||
s.mu.RLock()
|
s.mu.RLock()
|
||||||
defer s.mu.RUnlock()
|
defer s.mu.RUnlock()
|
||||||
|
|
||||||
if n <= 0 || n > s.maxRuns {
|
n = normalizeHistoryRequestCount(n, s.maxRuns, len(s.runs))
|
||||||
n = s.maxRuns
|
|
||||||
}
|
|
||||||
if n > len(s.runs) {
|
|
||||||
n = len(s.runs)
|
|
||||||
}
|
|
||||||
|
|
||||||
result := make([]PatrolRunRecord, n)
|
result := make([]PatrolRunRecord, n)
|
||||||
copy(result, s.runs[:n])
|
copy(result, s.runs[:n])
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,25 @@ type OperationWindow struct {
|
||||||
ExpectedMetrics []string `json:"expected_metrics"` // Metrics expected to be affected
|
ExpectedMetrics []string `json:"expected_metrics"` // Metrics expected to be affected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func clampCorrelationCount(value, minValue, maxValue int) int {
|
||||||
|
if value < minValue {
|
||||||
|
return minValue
|
||||||
|
}
|
||||||
|
if value > maxValue {
|
||||||
|
return maxValue
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
func normalizeCorrelationLimit(requested, configMax, available int) int {
|
||||||
|
if requested <= 0 {
|
||||||
|
requested = DefaultEventCorrelatorConfig().MaxCorrelations
|
||||||
|
}
|
||||||
|
requested = clampCorrelationCount(requested, 0, DefaultEventCorrelatorConfig().MaxCorrelations)
|
||||||
|
requested = clampCorrelationCount(requested, 0, configMax)
|
||||||
|
return clampCorrelationCount(requested, 0, available)
|
||||||
|
}
|
||||||
|
|
||||||
// EventCorrelatorConfig configures the event correlator
|
// EventCorrelatorConfig configures the event correlator
|
||||||
type EventCorrelatorConfig struct {
|
type EventCorrelatorConfig struct {
|
||||||
DataDir string
|
DataDir string
|
||||||
|
|
@ -403,12 +422,7 @@ func (c *EventCorrelator) GetCorrelations(limit int) []EventCorrelation {
|
||||||
c.mu.RLock()
|
c.mu.RLock()
|
||||||
defer c.mu.RUnlock()
|
defer c.mu.RUnlock()
|
||||||
|
|
||||||
if limit <= 0 || limit > c.config.MaxCorrelations {
|
limit = normalizeCorrelationLimit(limit, c.config.MaxCorrelations, len(c.correlations))
|
||||||
limit = c.config.MaxCorrelations
|
|
||||||
}
|
|
||||||
if limit > len(c.correlations) {
|
|
||||||
limit = len(c.correlations)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return most recent
|
// Return most recent
|
||||||
start := len(c.correlations) - limit
|
start := len(c.correlations) - limit
|
||||||
|
|
|
||||||
|
|
@ -662,12 +662,13 @@ func ptrFloat64(v float64) *float64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateNodes(config MockConfig) []models.Node {
|
func generateNodes(config MockConfig) []models.Node {
|
||||||
nodes := make([]models.Node, 0, config.NodeCount)
|
nodeCount := clampInt(config.NodeCount, 0, maxMockNodeCount)
|
||||||
|
nodes := make([]models.Node, 0, nodeCount)
|
||||||
|
|
||||||
// First 5 nodes are part of the cluster
|
// First 5 nodes are part of the cluster
|
||||||
clusterNodeCount := 5
|
clusterNodeCount := 5
|
||||||
if config.NodeCount < 5 {
|
if nodeCount < 5 {
|
||||||
clusterNodeCount = config.NodeCount
|
clusterNodeCount = nodeCount
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate clustered nodes
|
// Generate clustered nodes
|
||||||
|
|
@ -714,7 +715,7 @@ func generateNodes(config MockConfig) []models.Node {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate standalone nodes (if we have more than 5 nodes)
|
// Generate standalone nodes (if we have more than 5 nodes)
|
||||||
for i := clusterNodeCount; i < config.NodeCount; i++ {
|
for i := clusterNodeCount; i < nodeCount; i++ {
|
||||||
nodeName := fmt.Sprintf("standalone%d", i-clusterNodeCount+1)
|
nodeName := fmt.Sprintf("standalone%d", i-clusterNodeCount+1)
|
||||||
isHighLoad := false
|
isHighLoad := false
|
||||||
for _, n := range config.HighLoadNodes {
|
for _, n := range config.HighLoadNodes {
|
||||||
|
|
|
||||||
|
|
@ -1606,8 +1606,8 @@ func (a *VMIpAddress) UnmarshalJSON(data []byte) error {
|
||||||
if prefix > 128 {
|
if prefix > 128 {
|
||||||
prefix = 128
|
prefix = 128
|
||||||
}
|
}
|
||||||
if prefix <= 128 {
|
if prefixInt, ok := intFromUint64Checked(prefix); ok {
|
||||||
a.Prefix = int(prefix)
|
a.Prefix = prefixInt
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,28 @@
|
||||||
package proxmox
|
package proxmox
|
||||||
|
|
||||||
import "math"
|
import (
|
||||||
|
"math"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
func intFromInt64Checked(v int64) (int, bool) {
|
func intFromInt64Checked(v int64) (int, bool) {
|
||||||
if v > int64(math.MaxInt) || v < int64(math.MinInt) {
|
if strconv.IntSize == 32 {
|
||||||
return 0, false
|
if v > math.MaxInt32 || v < math.MinInt32 {
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
return int(int32(v)), true
|
||||||
}
|
}
|
||||||
return int(v), true
|
return int(v), true
|
||||||
}
|
}
|
||||||
|
|
||||||
func intFromUint64Checked(v uint64) (int, bool) {
|
func intFromUint64Checked(v uint64) (int, bool) {
|
||||||
if v > uint64(math.MaxInt) {
|
if strconv.IntSize == 32 {
|
||||||
|
if v > math.MaxInt32 {
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
return int(int32(v)), true
|
||||||
|
}
|
||||||
|
if v > math.MaxInt64 {
|
||||||
return 0, false
|
return 0, false
|
||||||
}
|
}
|
||||||
return int(v), true
|
return int(v), true
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue