From 6b648199f02ca7312ae9ca0a44083f2a0d0bc1d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Garc=C3=ADa=20Montoro?= Date: Thu, 5 Dec 2024 16:46:04 +0100 Subject: [PATCH] MM-61992: Verify license.Features.Users is not nil (#29417) * Verify license.Features.Users is not nil * Move check before DB call to avoid it if possible * Add more context to the error --- server/channels/app/platform/license.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/server/channels/app/platform/license.go b/server/channels/app/platform/license.go index e879521db7f..2b7fae0698b 100644 --- a/server/channels/app/platform/license.go +++ b/server/channels/app/platform/license.go @@ -126,6 +126,14 @@ func (ps *PlatformService) SaveLicense(licenseBytes []byte) (*model.License, *mo return nil, model.NewAppError("addLicense", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(jsonErr) } + if license.Features == nil { + return nil, model.NewAppError("addLicense", "api.license.add_license.invalid.app_error", nil, "", http.StatusBadRequest).Wrap(errors.New("license.Features is nil")) + } + + if license.Features.Users == nil { + return nil, model.NewAppError("addLicense", "api.license.add_license.invalid.app_error", nil, "", http.StatusBadRequest).Wrap(errors.New("license.Features.Users is nil")) + } + uniqueUserCount, err := ps.Store.User().Count(model.UserCountOptions{}) if err != nil { return nil, model.NewAppError("addLicense", "api.license.add_license.invalid_count.app_error", nil, "", http.StatusBadRequest).Wrap(err)