Skip to content

Commit 005fe25

Browse files
authored
Merge pull request fanal#429 from aquasecurity/owenr-fix-issue-no-filename
fix: handle no filename comeing through from defsec
2 parents fe1f9c9 + aac7cf5 commit 005fe25

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

config/scanner/scanner.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,12 @@ func (s Scanner) scanCloudFormation(files []types.Config) ([]types.Misconfigurat
175175
},
176176
}
177177

178-
filename := flattened.Location.Filename
179-
filePath, err := filepath.Rel(rootDir, filename)
180-
if err != nil {
181-
return nil, xerrors.Errorf("filepath rel, root: [%s], result: [%s] %w", rootDir, filename, err)
178+
var filePath = "unknown"
179+
if flattened.Location.Filename == "" {
180+
filePath, err = filepath.Rel(rootDir, flattened.Location.Filename)
181+
if err != nil {
182+
return nil, xerrors.Errorf("filepath rel, root: [%s], result: [%s] %w", rootDir, flattened.Location.Filename, err)
183+
}
182184
}
183185

184186
misconf, ok := misConfs[filePath]
@@ -244,9 +246,13 @@ func (s Scanner) scanTerraform(files []types.Config) ([]types.Misconfiguration,
244246
EndLine: flattened.Location.EndLine,
245247
},
246248
}
247-
filePath, err := filepath.Rel(rootDir, flattened.Location.Filename)
248-
if err != nil {
249-
return nil, xerrors.Errorf("filepath rel: %w", err)
249+
250+
var filePath = "unknown"
251+
if flattened.Location.Filename != "" {
252+
filePath, err = filepath.Rel(rootDir, flattened.Location.Filename)
253+
if err != nil {
254+
return nil, xerrors.Errorf("filepath rel, root: [%s], result: [%s] %w", rootDir, flattened.Location.Filename, err)
255+
}
250256
}
251257

252258
misconf, ok := misconfs[filePath]

0 commit comments

Comments
 (0)