From c4dde3d0ab12afce7bc1e90089fee6c37724752e Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Wed, 9 Jul 2025 09:37:36 +0530 Subject: [PATCH] MM-64632: Fix a panic in bulk import (#33360) We were incorrect de-referencing the channels slice without checking for nil pointer first. https://mattermost.atlassian.net/browse/MM-64632 ```release-note NONE ``` --- .../channels/app/imports/import_validators.go | 17 +++++++++-------- .../app/imports/import_validators_test.go | 13 +++++++++++++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/server/channels/app/imports/import_validators.go b/server/channels/app/imports/import_validators.go index 8fa3f7ff1b..f9bbc6dd31 100644 --- a/server/channels/app/imports/import_validators.go +++ b/server/channels/app/imports/import_validators.go @@ -791,16 +791,17 @@ func isValidGuestRoles(data UserImportData) bool { gtc++ } - if *team.Channels != nil { - for _, channel := range *team.Channels { - if channel.Roles != nil && model.IsInRole(*channel.Roles, model.ChannelGuestRoleId) { - ctc++ - } + if team.Channels == nil { + continue + } + for _, channel := range *team.Channels { + if channel.Roles != nil && model.IsInRole(*channel.Roles, model.ChannelGuestRoleId) { + ctc++ } + } - if ctc == len(*team.Channels) { - isChannelGuest = true - } + if ctc == len(*team.Channels) { + isChannelGuest = true } } if gtc == len(*data.Teams) { diff --git a/server/channels/app/imports/import_validators_test.go b/server/channels/app/imports/import_validators_test.go index 17b6647c8c..4502d2772e 100644 --- a/server/channels/app/imports/import_validators_test.go +++ b/server/channels/app/imports/import_validators_test.go @@ -1704,6 +1704,19 @@ func TestIsValidGuestRoles(t *testing.T) { }, expected: true, }, + { + name: "Valid case: User with team but nil channels array", + input: UserImportData{ + Roles: model.NewPointer(model.SystemUserRoleId), + Teams: &[]UserTeamImportData{ + { + Roles: model.NewPointer(model.TeamUserRoleId), + Channels: nil, + }, + }, + }, + expected: true, + }, } for _, tc := range testCases {