cannot seek stdin on pipe
See original GitHub issueDescribe the bug There are couple bugs merged into one for stdin parsing
https://github.com/PyCQA/bandit/blob/master/bandit/core/manager.py#L249 self._parse_file(‘<stdin>’, sys.stdin, new_files_list)
Note we are artificially changing the file name from ‘-’ to ‘<stdin>’, which doesn’t exist in the new_file_list
https://github.com/PyCQA/bandit/blob/master/bandit/core/manager.py#L278 fdata.seek(0)
Note OS doesn’t allow seek on pipes/stream stdins, this causes us to fail into general catchall exception clause.
https://github.com/PyCQA/bandit/blob/master/bandit/core/manager.py#L303 new_files_list.remove(fname)
remember back in line 249 we artificially renamed the filename? Here is where it came back and bite us. Since ‘<stdin>’ doesn’t exist in the new_files_list as an item, it hard failed without try catch and dumps a stack trace.
To Reproduce cat blah.py | bandit --debug -
Expected behavior it should either parse the contents of the stdin stream or not having this functionality for pipes
Bandit version
master
Additional context Add any other context about the problem here.
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (4 by maintainers)

Top Related StackOverflow Question
I feel like this may be desired behavior has we are catching anything that doesn’t have a file on disk and this is one of those cases. Unless @ericwb feels like it should be redesigned, I feel like this is a good solution to the problem once your change on my branch is merged @JuanHuaXu.
Proposed fix is sitting in PR #496 – @JuanHuaXu if you have any comments please feel free to make them and please test out this branch to ensure it fixes the behavior you are seeing.