diff --git a/changes/33149-bugfix-nil-point-batch-profiles b/changes/33149-bugfix-nil-point-batch-profiles new file mode 100644 index 0000000000..2e28d4e36d --- /dev/null +++ b/changes/33149-bugfix-nil-point-batch-profiles @@ -0,0 +1,2 @@ +- Fixed bug where batch setting MDM profiles could cause a nil pointer dereference when processing + an invalid profile (e.g., cannot parse mobileconfig because it is bad xml). diff --git a/server/service/integration_mdm_profiles_test.go b/server/service/integration_mdm_profiles_test.go index b2ac532688..014c48fb66 100644 --- a/server/service/integration_mdm_profiles_test.go +++ b/server/service/integration_mdm_profiles_test.go @@ -4472,6 +4472,19 @@ func (s *integrationMDMTestSuite) TestBatchSetMDMProfiles() { http.StatusUnprocessableEntity) require.Contains(t, extractServerErrorText(resp.Body), "Validation Failed: maximum configuration profile file size is 1 MB") + // invalid profile (bad mobileconfig) + resp = s.Do("POST", "/api/v1/fleet/mdm/profiles/batch", batchSetMDMProfilesRequest{Profiles: []fleet.MDMProfileBatchPayload{ + { + Name: "Bad mobileconfig", Contents: []byte(` + + + + PayloadContent + `), + }, + }}, http.StatusUnprocessableEntity) + require.Contains(t, extractServerErrorText(resp.Body), "Validation Failed: new MDMAppleConfigProfile: plist: error parsing XML property list: XML syntax error") + // apply an empty set to no-team s.Do("POST", "/api/v1/fleet/mdm/profiles/batch", batchSetMDMProfilesRequest{Profiles: nil}, http.StatusNoContent) // Nothing changed, so no activity items diff --git a/server/service/mdm.go b/server/service/mdm.go index 0383a890ea..52f9943035 100644 --- a/server/service/mdm.go +++ b/server/service/mdm.go @@ -2411,12 +2411,12 @@ func getAppleProfiles( } mdmProf, err := fleet.NewMDMAppleConfigProfile(prof.Contents, tmID) - mdmProf.SecretsUpdatedAt = prof.SecretsUpdatedAt if err != nil { return nil, nil, ctxerr.Wrap(ctx, fleet.NewInvalidArgumentError(prof.Name, err.Error()), "invalid mobileconfig profile") } + mdmProf.SecretsUpdatedAt = prof.SecretsUpdatedAt for _, labelName := range prof.LabelsIncludeAll { if lbl, ok := labelMap[labelName]; ok {