From 15ce06263d2d02b4fb39f9866eb787675db86aa0 Mon Sep 17 00:00:00 2001 From: Tomas Touceda Date: Wed, 1 Sep 2021 19:17:41 -0300 Subject: [PATCH] Dont fail config if agent opts is nil (#1898) * Handle agentopts nil better * Add changes file --- changes/dont-fail-config-agent-opts-nil | 1 + server/service/service_osquery.go | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 changes/dont-fail-config-agent-opts-nil diff --git a/changes/dont-fail-config-agent-opts-nil b/changes/dont-fail-config-agent-opts-nil new file mode 100644 index 0000000000..4dd292763a --- /dev/null +++ b/changes/dont-fail-config-agent-opts-nil @@ -0,0 +1 @@ +* Handle properly the case where the agent opts is nil in the app config. diff --git a/server/service/service_osquery.go b/server/service/service_osquery.go index 61e37810b5..5cbed99fa7 100644 --- a/server/service/service_osquery.go +++ b/server/service/service_osquery.go @@ -224,10 +224,13 @@ func (svc *Service) GetClientConfig(ctx context.Context) (map[string]interface{} return nil, osqueryError{message: "internal error: fetch base config: " + err.Error()} } - var config map[string]interface{} - err = json.Unmarshal(baseConfig, &config) - if err != nil { - return nil, osqueryError{message: "internal error: parse base configuration: " + err.Error()} + config := make(map[string]interface{}) + + if baseConfig != nil { + err = json.Unmarshal(baseConfig, &config) + if err != nil { + return nil, osqueryError{message: "internal error: parse base configuration: " + err.Error()} + } } packs, err := svc.ds.ListPacksForHost(host.ID)