Skip to content

Commit c8c14d3

Browse files
authored
fix(misconf): check if property is not nil before conversion (#7578)
Signed-off-by: nikpivkin <nikita.pivkin@smartforce.io>
1 parent 9da84f5 commit c8c14d3

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

pkg/iac/adapters/cloudformation/aws/ec2/adapt_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,34 @@ Resources:
338338
},
339339
},
340340
},
341+
{
342+
name: "empty",
343+
source: `---
344+
AWSTemplateFormatVersion: 2010-09-09
345+
Description: Godd example of excessive ports
346+
Resources:
347+
NetworkACL:
348+
Type: AWS::EC2::NetworkAcl
349+
Rule:
350+
Type: AWS::EC2::NetworkAclEntry
351+
Properties:
352+
NetworkAclId:
353+
Ref: NetworkACL`,
354+
expected: ec2.EC2{
355+
NetworkACLs: []ec2.NetworkACL{
356+
{
357+
Rules: []ec2.NetworkACLRule{
358+
{
359+
Action: types.StringTest("allow"),
360+
Type: types.StringTest("ingress"),
361+
FromPort: types.IntTest(-1),
362+
ToPort: types.IntTest(-1),
363+
},
364+
},
365+
},
366+
},
367+
},
368+
},
341369
}
342370

343371
for _, tt := range tests {

pkg/iac/scanners/cloudformation/parser/property_conversion.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import (
1010
)
1111

1212
func (p *Property) IsConvertableTo(conversionType cftypes.CfType) bool {
13+
if p.IsNil() {
14+
return false
15+
}
16+
1317
switch conversionType {
1418
case cftypes.Int:
1519
return p.isConvertableToInt()
@@ -62,6 +66,9 @@ func (p *Property) isConvertableToInt() bool {
6266
}
6367

6468
func (p *Property) ConvertTo(conversionType cftypes.CfType) *Property {
69+
if p.IsNil() {
70+
return nil
71+
}
6572

6673
if p.Type() == conversionType {
6774
return p

0 commit comments

Comments
 (0)