Skip to content

Commit 1ab0788

Browse files
authored
Fix traceback from trojansource plugin (#1248)
The trojansource plugin functions differently where it doesn't process a file by AST node. It instead does a line by line search for suspicious characters. As a result, it can't rely on the linerange being automatically set based on values fetched from the node. So it needs to set the linerange manually. Fixes: #1246 Signed-off-by: Eric Brown <eric_wade_brown@yahoo.com>
1 parent 89bea99 commit 1ab0788

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

bandit/core/tester.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ def run_tests(self, raw_context, checktype):
6565

6666
if result.lineno is None:
6767
result.lineno = temp_context["lineno"]
68-
result.linerange = temp_context["linerange"]
68+
if result.linerange == []:
69+
result.linerange = temp_context["linerange"]
6970
if result.col_offset == -1:
7071
result.col_offset = temp_context["col_offset"]
7172
result.end_col_offset = temp_context.get(

bandit/plugins/trojansource.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,13 @@ def trojansource(context):
6767
"A Python source file contains bidirectional"
6868
" control characters (%r)." % char
6969
)
70-
return bandit.Issue(
70+
b_issue = bandit.Issue(
7171
severity=bandit.HIGH,
7272
confidence=bandit.MEDIUM,
7373
cwe=issue.Cwe.INAPPROPRIATE_ENCODING_FOR_OUTPUT_CONTEXT,
7474
text=text,
7575
lineno=lineno,
7676
col_offset=col_offset,
7777
)
78+
b_issue.linerange = [lineno]
79+
return b_issue

0 commit comments

Comments
 (0)