Skip to content

Commit

Permalink
prevent nil deref when loading cti config (#3176)
Browse files Browse the repository at this point in the history
* correct variable names

* prevent nil deref when loading cti config
  • Loading branch information
mmetc authored Aug 12, 2024
1 parent 3532e87 commit 52995b8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pkg/apiserver/apic.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const (
metricsIntervalDefault = time.Minute * 30
metricsIntervalDelta = time.Minute * 15
usageMetricsInterval = time.Minute * 30
usageMetricsIntervalFirst = time.Minute * 15
usageMetricsIntervalDelta = time.Minute * 15
)

type apic struct {
Expand Down Expand Up @@ -196,7 +196,7 @@ func NewAPIC(config *csconfig.OnlineApiClientCfg, dbClient *database.Client, con
metricsInterval: metricsIntervalDefault,
metricsIntervalFirst: randomDuration(metricsIntervalDefault, metricsIntervalDelta),
usageMetricsInterval: usageMetricsInterval,
usageMetricsIntervalFirst: randomDuration(usageMetricsInterval, usageMetricsIntervalFirst),
usageMetricsIntervalFirst: randomDuration(usageMetricsInterval, usageMetricsIntervalDelta),
isPulling: make(chan bool, 1),
whitelists: apicWhitelist,
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/csconfig/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,15 @@ type CTICfg struct {

func (a *CTICfg) Load() error {
if a.Key == nil {
*a.Enabled = false
a.Enabled = ptr.Of(false)
}

if a.Key != nil && *a.Key == "" {
return errors.New("empty cti key")
}

if a.Enabled == nil {
a.Enabled = new(bool)
*a.Enabled = true
a.Enabled = ptr.Of(true)
}

if a.CacheTimeout == nil {
Expand Down

0 comments on commit 52995b8

Please sign in to comment.