-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Python: Improve File Not Closed query to reduce false positives and provide clearer alerts #20392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python: Improve File Not Closed query to reduce false positives and provide clearer alerts #20392
Conversation
This reduces some confusing FPs, though appears to introduce another
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR improves the Python "File Not Closed" query to reduce false positives and enhance alert clarity. The changes focus on better handling of with
statements that guard exceptions and providing more informative error messages by linking to specific exception-raising locations.
- Refactored exception guarding logic to use local dataflow instead of basic block reachability
- Enhanced alert messages to include links to specific operations that may raise exceptions
- Added comprehensive test cases documenting previous false positive behaviors
Reviewed Changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
python/ql/src/Resources/FileNotAlwaysClosed.ql | Updated query to support enhanced alert messages with exception location links |
python/ql/src/Resources/FileNotAlwaysClosedQuery.qll | Improved exception guarding logic and dataflow analysis for better accuracy |
python/ql/test/query-tests/Resources/FileNotAlwaysClosed/resources_test.py | Updated test annotations and added new test cases for previous false positives |
python/ql/test/query-tests/Resources/FileNotAlwaysClosed/FileNotAlwaysClosed.qlref | Added query reference configuration |
python/ql/test/query-tests/Resources/FileNotAlwaysClosed/FileNotAlwaysClosed.expected | Added expected test results |
python/ql/test/query-tests/Resources/FileNotAlwaysClosed/resources_test.py
Outdated
Show resolved
Hide resolved
python/ql/test/query-tests/Resources/FileNotAlwaysClosed/resources_test.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. 👍
with
statements guarding exceptions, that was resulting in some unintuitve false positives