Skip to content

Commit

Permalink
Nil check pointer fields in some watchers before using them (#4248)
Browse files Browse the repository at this point in the history
- Nil check entity field coming from watcher
- Nil check tessen config coming from watcher
- Nil check check config coming from watcher

Signed-off-by: Cyril Cressent <cyril@sensu.io>
  • Loading branch information
ccressent committed Apr 1, 2021
1 parent 2f56751 commit d2fb55d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ round robin checks.
in OSS builds.
- Fixed a potential crash in tessend.
- Fixed a potential deadlock in agentd.
- Fixed a bug where some Etcd watchers could try to process watch events holding
invalid pointers.

## [6.2.2] - 2021-01-14

Expand Down
5 changes: 5 additions & 0 deletions backend/agentd/agentd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package agentd
import (
"context"
"crypto/tls"
"errors"
"fmt"
"log"
"net"
Expand Down Expand Up @@ -246,6 +247,10 @@ func (a *Agentd) runWatcher() {
}

func (a *Agentd) handleEvent(event store.WatchEventEntityConfig) error {
if event.Entity == nil {
return errors.New("nil entity received from entity config watcher")
}

topic := messaging.EntityConfigTopic(event.Entity.Metadata.Namespace, event.Entity.Metadata.Name)
if err := a.bus.Publish(topic, &event); err != nil {
logger.WithField("topic", topic).WithError(err).
Expand Down
6 changes: 6 additions & 0 deletions backend/schedulerd/check_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ func (c *CheckWatcher) startWatcher() {

func (c *CheckWatcher) handleWatchEvent(watchEvent store.WatchEventCheckConfig) {
check := watchEvent.CheckConfig

if check == nil {
logger.Error("nil check config received from check config watcher")
return
}

key := concatUniqueKey(check.Name, check.Namespace)

c.mu.Lock()
Expand Down
5 changes: 5 additions & 0 deletions backend/tessend/tessend.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,11 @@ func (t *Tessend) startWatcher() {
func (t *Tessend) handleWatchEvent(watchEvent store.WatchEventTessenConfig) {
tessen := watchEvent.TessenConfig

if tessen == nil {
logger.Error("nil config received from tessen config watcher")
return
}

switch watchEvent.Action {
case store.WatchCreate:
logger.WithField("opt-out", tessen.OptOut).Debug("tessen configuration created")
Expand Down

0 comments on commit d2fb55d

Please sign in to comment.