crytic / amarna

Amarna is a static-analyzer and linter for the Cairo programming language.
https://blog.trailofbits.com/2022/04/20/amarna-static-analysis-for-cairo-programs/
GNU Affero General Public License v3.0
149 stars 7 forks source link

Noisy fail when running amarna on directories with no cairo files #23

Closed coolhill closed 2 years ago

coolhill commented 2 years ago

It might make more sense to have amarna "fail" silently when run on an empty directory. Currently there is an error trace:

pytest_venv) coolhill@coolhill:~/amarna$ amarna -s /tmp/
Traceback (most recent call last):
  File "/home/coolhill/pytest_venv/bin/amarna", line 33, in <module>
    sys.exit(load_entry_point('amarna', 'console_scripts', 'amarna')())
  File "/home/coolhill/amarna/amarna/command_line.py", line 154, in main
    results = analyze_directory(filename, rule_set_names)
  File "/home/coolhill/amarna/amarna/amarna.py", line 155, in analyze_directory
    all_results += amarna.run_post_process_rules()
  File "/home/coolhill/amarna/amarna/amarna.py", line 120, in run_post_process_rules
    results += Rule.run_rule(self.data)
  File "/home/coolhill/amarna/amarna/rules/post_process_rules/ImportedExternalsRule.py", line 21, in run_rule
    DeclaredFunctionsGatherer.GATHERER_NAME
KeyError: 'DeclaredFunctionsGatherer'

Maybe because post process rules are being run even if the directory is empty, as per https://github.com/crytic/amarna/blob/d170deb21367b02cb96ae7c29393f58f58c4d82b/amarna/amarna.py#L155

fcasal commented 2 years ago

Yes, the cause is that the gatherers never ran so it will fail when trying to access the gathered_data during the post processing rules.