Crashing in runner.py due to AttributeError raised by checking None for keys
See original GitHub issueDescribe the bug I am getting a crash similar in appearance to #118 but for Terraform and not CloudFormation.
Scanning file: /some_directory/some-file.tf
full_file_path is /other_directory/some_directory/some-file.tf
Traceback (most recent call last):
File "/my_path/bin/checkov", line 5, in <module>
run()
File "/my_path/lib/python3.7/site-packages/checkov/main.py", line 108, in run
guidelines=guidelines, bc_integration=bc_integration)
File "/my_path/lib/python3.7/site-packages/checkov/common/runners/runner_registry.py", line 35, in run
runner_filter=self.runner_filter, collect_skip_comments=collect_skip_comments)
File "/my_path/lib/python3.7/site-packages/checkov/terraform/runner.py", line 78, in run
self.check_tf_definition(report, root_folder, runner_filter, collect_skip_comments)
File "/my_path/lib/python3.7/site-packages/checkov/terraform/runner.py", line 100, in check_tf_definition
scanned_file, runner_filter, abs_referrer)
File "/my_path/lib/python3.7/site-packages/checkov/terraform/runner.py", line 104, in run_all_blocks
for block_type in definition.keys():
AttributeError: 'NoneType' object has no attribute 'keys'
To Reproduce edit: See https://github.com/bridgecrewio/checkov/issues/941#issuecomment-790803047
That’s the thing 😢 It’s real hard to reproduce, if I run checkov
just on the file that it crashes on, things work fine! If I run it on just the last 10 files it scans before crashing, things work fine. For testing this, I’d recommend you simply run this on a big repo with a lot of output from find . -type f -name "*.tf"
and then turn all the files into individual --file arguments, like my cool checkov wrapper package does.
e.g. checkov --check CKV_AWS_88 --file fileA.tf --fileB.tf
(to save time, I just limited this to 1 check, but it could be any other check id)
Steps to reproduce the behavior:
- Run cli command
checkov --check CKV_AWS_88 --file fileA.tf --fileB.tf
on a ton of --file arguments. Pray it triggers the bug. - See error
Expected behavior No crashing.
Desktop (please complete the following information):
- OS: OS X
- Checkov Version: the latest as of today:
1.0.825
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (12 by maintainers)
Top GitHub Comments
That might make sense given how it loops over things? Hard to say for sure without being able to reproduce, but I’m pretty sure I have a change that will avoid the problem.
Ok. Normality restored. 🤪