Fix B602: Fix IndexError on subprocess calls with keyword arguments#1342
Open
balaram753 wants to merge 3 commits intoPyCQA:mainfrom
Open
Fix B602: Fix IndexError on subprocess calls with keyword arguments#1342balaram753 wants to merge 3 commits intoPyCQA:mainfrom
balaram753 wants to merge 3 commits intoPyCQA:mainfrom
Conversation
Member
|
Please add test cases to prevent regression here |
Comment on lines
+48
to
+50
| self.assertEqual( | ||
| "call with shell=True", "call with shell=True" | ||
| ) # Dummy assertion |
| context = mock.Mock() | ||
| context.call_function_name_qual = function_name | ||
| # context.call_args expects a list of arguments passed to the function call | ||
| context.call_args = args or [] |
Member
There was a problem hiding this comment.
You seem to be passing in only [mock.Mock()] this doesn't make very much sense at all.
Furthermore, call_args and call_keywords are what's recorded on the mock. You shouldn't be setting these.
Member
There was a problem hiding this comment.
Ah, I see you're trying to build up a https://github.com/PyCQA/bandit/blob/main/bandit/core/context.py. Why use a mock here instead of building up a real Context?
| self.assertIsInstance(result, bandit.Issue) | ||
| self.assertEqual(bandit.LOW, result.severity) | ||
|
|
||
| # HIGH if dynamic |
Member
There was a problem hiding this comment.
Suggested change
| # HIGH if dynamic | |
| # HIGH if dynamic parameters to process call | |
| # Example: | |
| # def run(cmd: str) -> Any: | |
| # return os.system(cmd) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before Fix: The code would crash because it tried to access context.node.args[0] which was empty. (Note: My reproduction script required some environment mocking).
After Fix: The code correctly handles the empty args list and finds the args keyword argument (or returns HIGH if not found), preventing the crash.