[MM-54456] Fix potential read after write issue when loading license (#24524)

* Fix potential read after write issue when loading license

* Use upsert
Этот коммит содержится в:
Claudio Costa
2023-09-13 14:47:12 -06:00
коммит произвёл GitHub
родитель c53b5f7b2b
Коммит b4a47803e6
8 изменённых файлов: 71 добавлений и 81 удалений

Просмотреть файл

@@ -5,6 +5,7 @@ package platform
import (
"bytes"
"context"
"encoding/json"
"fmt"
"net/http"
@@ -17,6 +18,7 @@ import (
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/mlog"
"github.com/mattermost/mattermost/server/v8/channels/jobs"
"github.com/mattermost/mattermost/server/v8/channels/store/sqlstore"
"github.com/mattermost/mattermost/server/v8/channels/utils"
"github.com/mattermost/mattermost/server/v8/einterfaces"
)
@@ -95,7 +97,7 @@ func (ps *PlatformService) LoadLicense() {
}
}
record, nErr := ps.Store.License().Get(licenseId)
record, nErr := ps.Store.License().Get(sqlstore.WithMaster(context.Background()), licenseId)
if nErr != nil {
ps.logger.Error("License key from https://mattermost.com required to unlock enterprise features.", mlog.Err(nErr))
ps.SetLicense(nil)
@@ -166,7 +168,7 @@ func (ps *PlatformService) SaveLicense(licenseBytes []byte) (*model.License, *mo
record.Id = license.Id
record.Bytes = string(licenseBytes)
_, nErr := ps.Store.License().Save(record)
nErr := ps.Store.License().Save(record)
if nErr != nil {
ps.RemoveLicense()
var appErr *model.AppError