MM-39420: Checks for presence of slice before index access. (#18826)

* MM-39420: Checks for presence of slice before index access.

* MM-39420: Sanitize all embeds with single method.

* MM-39420: Already checking len in method.
Этот коммит содержится в:
Martin Kraft
2021-11-04 09:41:19 -04:00
коммит произвёл GitHub
родитель 7287da6391
Коммит 412e52894c
2 изменённых файлов: 11 добавлений и 21 удалений

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

@@ -721,24 +721,19 @@ func (a *App) publishWebsocketEventForPermalinkPost(post *model.Post, message *m
return false, err
}
previewedChannel, err := a.GetChannel(previewedPost.ChannelId)
if err != nil {
if err.StatusCode == http.StatusNotFound {
mlog.Warn("channel containing permalinked post not found", mlog.String("referenced_channel_id", previewedPost.ChannelId))
return false, nil
}
return false, err
}
channelMembers, err := a.GetChannelMembersPage(post.ChannelId, 0, 10000000)
if err != nil {
return false, err
}
for _, cm := range channelMembers {
postForUser := post.Clone()
if !a.HasPermissionToReadChannel(cm.UserId, previewedChannel) {
postForUser.Metadata.Embeds[0].Data = nil
postForUser, err := a.SanitizePostMetadataForUser(post, cm.UserId)
if err != nil {
if err.StatusCode == http.StatusNotFound {
mlog.Warn("channel containing permalinked post not found", mlog.String("referenced_channel_id", previewedPost.ChannelId))
return false, nil
}
return false, err
}
messageCopy := message.Copy()
broadcastCopy := messageCopy.GetBroadcast()