Skip to content
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

Cannot seek stdin on pipe #496

Merged
merged 40 commits into from Feb 18, 2022
Merged
Changes from 17 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
272fd74
add namespaces for parent attributes
tylerwince May 13, 2019
7a5e827
pylint formatting changes
tylerwince May 13, 2019
583149a
added _Seeker for running seek on sys.stdin
tylerwince May 15, 2019
cf4f11a
Merge branch 'master' into 495-cannot-seek-stdin-on-pipe
tylerwince May 15, 2019
acd80a7
Update node_visitor.py
tylerwince May 15, 2019
edcecbe
Update general_hardcoded_password.py
tylerwince May 15, 2019
ca5cfe3
Update general_hardcoded_password.py
tylerwince May 15, 2019
6a33c6e
pep8 fixes
tylerwince May 15, 2019
91543c2
added list handling for hard fname swaps
cat-code May 15, 2019
969e816
updated manager
tylerwince May 15, 2019
6535101
maintaining list order
cat-code May 15, 2019
10c6378
Merge pull request #1 from JuanHuaXu/495-cannot-seek-stdin-on-pipe
tylerwince May 15, 2019
9f99d63
updated pep8 errors
tylerwince May 16, 2019
c9bb2b5
Merge branch 'master' into 495-cannot-seek-stdin-on-pipe
tylerwince May 27, 2019
8305291
Merge branch 'master' into 495-cannot-seek-stdin-on-pipe
tylerwince Jun 25, 2019
132e1c2
Merge branch 'master' into 495-cannot-seek-stdin-on-pipe
tylerwince Aug 2, 2019
c88dcac
Merge branch 'master' into 495-cannot-seek-stdin-on-pipe
ericwb Aug 18, 2019
ce523ba
Merge branch 'master' into 495-cannot-seek-stdin-on-pipe
tylerwince Oct 8, 2019
7b62387
Merge branch 'master' into 495-cannot-seek-stdin-on-pipe
ericwb Jan 12, 2020
c4dda4d
Merge branch 'master' into 495-cannot-seek-stdin-on-pipe
ericwb Jan 21, 2020
235acee
Merge branch 'master' into 495-cannot-seek-stdin-on-pipe
ericwb Mar 8, 2020
8038c11
Merge branch 'main' into 495-cannot-seek-stdin-on-pipe
ericwb Feb 14, 2022
fe741b4
Update manager.py
ericwb Feb 14, 2022
b035898
Update manager.py
ericwb Feb 14, 2022
f0e8316
Update manager.py
ericwb Feb 16, 2022
f0106e4
Update issue.py
ericwb Feb 16, 2022
e27cb8a
Update node_visitor.py
ericwb Feb 16, 2022
410a7cf
Update manager.py
ericwb Feb 16, 2022
0b43d58
Update issue.py
ericwb Feb 16, 2022
3f0139e
Update context.py
ericwb Feb 17, 2022
128fb4e
Update issue.py
ericwb Feb 17, 2022
217fe52
Update manager.py
ericwb Feb 17, 2022
1a9b389
Update node_visitor.py
ericwb Feb 17, 2022
4ab2d4a
Update tester.py
ericwb Feb 17, 2022
c42e501
Update issue.py
ericwb Feb 17, 2022
e583627
Update manager.py
ericwb Feb 17, 2022
86ffba3
Update context.py
ericwb Feb 17, 2022
a5e44ba
Update node_visitor.py
ericwb Feb 17, 2022
2e9b2d4
Update manager.py
ericwb Feb 17, 2022
6562a4d
Merge branch 'main' into 495-cannot-seek-stdin-on-pipe
tylerwince Feb 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 35 additions & 1 deletion bandit/core/manager.py
Expand Up @@ -16,6 +16,7 @@

import collections
import fnmatch
import io
import json
import logging
import os
Expand Down Expand Up @@ -248,7 +249,9 @@ def run_tests(self):
sys.stderr.flush()
try:
if fname == '-':
sys.stdin = os.fdopen(sys.stdin.fileno(), 'rb', 0)
sys.stdin = _Seeker(os.fdopen(sys.stdin.fileno(), 'rb', 0))
new_files_list = ["<stdin>" if x == "-" else
x for x in new_files_list]
self._parse_file('<stdin>', sys.stdin, new_files_list)
else:
with open(fname, 'rb') as fdata:
Expand Down Expand Up @@ -325,6 +328,37 @@ def _execute_ast_visitor(self, fname, data, nosec_lines):
return score


class _Seeker(object):
def __init__(self, fileobj):
self.fileobj = fileobj
self.buf = io.BytesIO()

def _append_to_buf(self, contents):
oldpos = self.buf.tell()
self.buf.seek(0, os.SEEK_END)
self.buf.write(contents)
self.buf.seek(oldpos)

def seek(self, size):
contents = self.fileobj.read(size)
self._append_to_buf(contents)
return contents

def read(self, size=None):
if size is None:
return self.buf.read() + self.fileobj.read()
contents = self.buf.read(size)
if len(contents) < size:
contents += self.fileobj.read(size - len(contents))
return contents

def readline(self):
line = self.buf.readline()
if not line.endswith("\n".encode()):
line += self.fileobj.readline()
return line


def _get_files_from_dir(files_dir, included_globs=None,
excluded_path_strings=None):
if not included_globs:
Expand Down