Skip to content

Commit 7b3a74b

Browse files
ccushingcodycushing
authored andcommitted
Check for nil values in Security List rules before trying to cast to the respective options object
* Lists modified outside Terraform (in the Console) now return with an unpopulated *_options object. This allowed the code to proceed past an array length check where a cast to `map[string]interface{}` would result in panic.
1 parent ca3c85f commit 7b3a74b

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

oci/core_security_list_resource.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ func egressSecurityRulesHashCodeForSets(v interface{}) int {
10141014
buf.WriteString(fmt.Sprintf("%v-", oci_core.EgressSecurityRuleDestinationTypeCidrBlock))
10151015
}
10161016
if icmpOptions, ok := m["icmp_options"]; ok {
1017-
if tmpList := icmpOptions.([]interface{}); len(tmpList) > 0 {
1017+
if tmpList := icmpOptions.([]interface{}); len(tmpList) > 0 && tmpList[0] != nil {
10181018
buf.WriteString("icmp_options-")
10191019
icmpOptionsRaw := tmpList[0].(map[string]interface{})
10201020
if code, ok := icmpOptionsRaw["code"]; ok {
@@ -1034,7 +1034,7 @@ func egressSecurityRulesHashCodeForSets(v interface{}) int {
10341034
buf.WriteString(fmt.Sprintf("%v-", "false"))
10351035
}
10361036
if tcpOptions, ok := m["tcp_options"]; ok {
1037-
if tmpList := tcpOptions.([]interface{}); len(tmpList) > 0 {
1037+
if tmpList := tcpOptions.([]interface{}); len(tmpList) > 0 && tmpList[0] != nil {
10381038
buf.WriteString("tcp_options-")
10391039
tcpOptionsRaw := tmpList[0].(map[string]interface{})
10401040
if max, ok := tcpOptionsRaw["max"]; ok {
@@ -1059,7 +1059,7 @@ func egressSecurityRulesHashCodeForSets(v interface{}) int {
10591059
}
10601060
}
10611061
if udpOptions, ok := m["udp_options"]; ok {
1062-
if tmpList := udpOptions.([]interface{}); len(tmpList) > 0 {
1062+
if tmpList := udpOptions.([]interface{}); len(tmpList) > 0 && tmpList[0] != nil {
10631063
buf.WriteString("udp_options-")
10641064
udpOptionsRaw := tmpList[0].(map[string]interface{})
10651065
if max, ok := udpOptionsRaw["max"]; ok && max != 0 {
@@ -1090,7 +1090,7 @@ func ingressSecurityRulesHashCodeForSets(v interface{}) int {
10901090
var buf bytes.Buffer
10911091
m := v.(map[string]interface{})
10921092
if icmpOptions, ok := m["icmp_options"]; ok {
1093-
if tmpList := icmpOptions.([]interface{}); len(tmpList) > 0 {
1093+
if tmpList := icmpOptions.([]interface{}); len(tmpList) > 0 && tmpList[0] != nil {
10941094
buf.WriteString("icmp_options-")
10951095
icmpOptionsRaw := tmpList[0].(map[string]interface{})
10961096
if code, ok := icmpOptionsRaw["code"]; ok {
@@ -1118,7 +1118,7 @@ func ingressSecurityRulesHashCodeForSets(v interface{}) int {
11181118
buf.WriteString(fmt.Sprintf("%v-", "false"))
11191119
}
11201120
if tcpOptions, ok := m["tcp_options"]; ok {
1121-
if tmpList := tcpOptions.([]interface{}); len(tmpList) > 0 {
1121+
if tmpList := tcpOptions.([]interface{}); len(tmpList) > 0 && tmpList[0] != nil {
11221122
buf.WriteString("tcp_options-")
11231123
tcpOptionsRaw := tmpList[0].(map[string]interface{})
11241124
if max, ok := tcpOptionsRaw["max"]; ok {
@@ -1142,7 +1142,7 @@ func ingressSecurityRulesHashCodeForSets(v interface{}) int {
11421142
}
11431143
}
11441144
if udpOptions, ok := m["udp_options"]; ok {
1145-
if tmpList := udpOptions.([]interface{}); len(tmpList) > 0 {
1145+
if tmpList := udpOptions.([]interface{}); len(tmpList) > 0 && tmpList[0] != nil {
11461146
buf.WriteString("udp_options-")
11471147
udpOptionsRaw := tmpList[0].(map[string]interface{})
11481148
if max, ok := udpOptionsRaw["max"]; ok {

0 commit comments

Comments
 (0)