PyCQA / bandit

Bandit is a tool designed to find common security issues in Python code.
https://bandit.readthedocs.io
Apache License 2.0
6.51k stars 612 forks source link

IndexError: list index out of range while scanning cpython #1141

Closed ericwb closed 5 months ago

ericwb commented 6 months ago

Describe the bug

Received a IndexError: list index out of range while scanning the source code contents of the Python cpython library.

Reproduction steps

1. `git clone https://github.com/python/cpython`
2. Run `bandit -r cpython`
3. Notice the IndexError at the beginning of the output.

[main]  INFO    running on Python 3.12.2
Working... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸━━━━━━━━━━━  72% 0:00:26[tester]    ERROR   Bandit internal error running: start_process_with_partial_path on file ../cpython/Lib/test/test_subprocess.py at line 180: list index out of rangeTraceback (most recent call last):
  File "/Users/ericwb/workspace/bandit/bandit/core/tester.py", line 51, in run_tests
    result = test(context, test._config)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ericwb/workspace/bandit/bandit/plugins/injection_shell.py", line 687, in start_process_with_partial_path
    node = node.elts[0]
           ~~~~~~~~~^^^
IndexError: list index out of range

[tester]    ERROR   Bandit internal error running: start_process_with_partial_path on file ../cpython/Lib/test/test_subprocess.py at line 184: list index out of rangeTraceback (most recent call last):
  File "/Users/ericwb/workspace/bandit/bandit/core/tester.py", line 51, in run_tests
    result = test(context, test._config)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ericwb/workspace/bandit/bandit/plugins/injection_shell.py", line 687, in start_process_with_partial_path
    node = node.elts[0]
           ~~~~~~~~~^^^
IndexError: list index out of range


### Expected behavior

The code should be more robust to avoid exceptions and errors.

### Bandit version

1.7.7 (Default)

### Python version

3.12 (Default)

### Additional context

_No response_