fix: fix infinite loop in containsRole() (#2136)

This commit is contained in:
June 2023-07-25 19:53:08 +07:00 committed by GitHub
parent 6986dad295
commit 55d5ae10f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -391,10 +391,13 @@ func GetAncestorRoles(roleIds ...string) ([]*Role, error) {
// containsRole is a helper function to check if a roles is related to any role in the given list roles
func containsRole(role *Role, roleMap map[string]*Role, visited map[string]bool, roleIds ...string) bool {
if isContain, ok := visited[role.GetId()]; ok {
roleId := role.GetId()
if isContain, ok := visited[roleId]; ok {
return isContain
}
visited[role.GetId()] = false
for _, subRole := range role.Roles {
if util.HasString(roleIds, subRole) {
return true