Commit 737607ba authored by Justin Santa Barbara's avatar Justin Santa Barbara

AWS: Fix suspicious loop comparing permissions

Because we only ever call it with a single UserId/GroupId, this would not have been a problem in practice, but this fixes the code. Fix #36902
parent ad43147e
...@@ -2030,17 +2030,22 @@ func ipPermissionExists(newPermission, existing *ec2.IpPermission, compareGroupU ...@@ -2030,17 +2030,22 @@ func ipPermissionExists(newPermission, existing *ec2.IpPermission, compareGroupU
break break
} }
} }
if found == false { if !found {
return false return false
} }
} }
for _, leftPair := range newPermission.UserIdGroupPairs { for _, leftPair := range newPermission.UserIdGroupPairs {
found := false
for _, rightPair := range existing.UserIdGroupPairs { for _, rightPair := range existing.UserIdGroupPairs {
if isEqualUserGroupPair(leftPair, rightPair, compareGroupUserIDs) { if isEqualUserGroupPair(leftPair, rightPair, compareGroupUserIDs) {
return true found = true
break
} }
} }
return false if !found {
return false
}
} }
return true return true
......
...@@ -877,6 +877,18 @@ func TestIpPermissionExistsHandlesMultipleGroupIds(t *testing.T) { ...@@ -877,6 +877,18 @@ func TestIpPermissionExistsHandlesMultipleGroupIds(t *testing.T) {
if equals { if equals {
t.Errorf("Should have not been considered equal since first is not in the second array of groups") t.Errorf("Should have not been considered equal since first is not in the second array of groups")
} }
// The first pair matches, but the second does not
newIpPermission2 := ec2.IpPermission{
UserIdGroupPairs: []*ec2.UserIdGroupPair{
{GroupId: aws.String("firstGroupId")},
{GroupId: aws.String("fourthGroupId")},
},
}
equals = ipPermissionExists(&newIpPermission2, &oldIpPermission, false)
if equals {
t.Errorf("Should have not been considered equal since first is not in the second array of groups")
}
} }
func TestIpPermissionExistsHandlesRangeSubsets(t *testing.T) { func TestIpPermissionExistsHandlesRangeSubsets(t *testing.T) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment