Skip to content

Commit fbaf2ce

Browse files
authored
Fix traceback in hashlib_insecure_functions (#834)
This check should not raise an exception if there are no keywords defined for the call. Makes use of dict get() for safety. Closes #832 Signed-off-by: Eric Brown <[email protected]>
1 parent 20a0510 commit fbaf2ce

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

bandit/plugins/hashlib_insecure_functions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ def _hashlib_func(context):
5252

5353
if "hashlib" in qualname_list:
5454
func = qualname_list[-1]
55-
args = context.call_args
5655
keywords = context.call_keywords
57-
name = args[0] if args else keywords["name"]
5856

5957
if func in ("md4", "md5", "sha", "sha1"):
6058
if keywords.get("usedforsecurity", "True") == "True":
@@ -67,6 +65,8 @@ def _hashlib_func(context):
6765
lineno=context.node.lineno,
6866
)
6967
elif func == "new":
68+
args = context.call_args
69+
name = args[0] if args else keywords.get("name", None)
7070
if isinstance(name, str) and name.lower() in (
7171
"md4",
7272
"md5",
@@ -92,7 +92,7 @@ def _hashlib_new(context):
9292
if "hashlib" in qualname_list and func == "new":
9393
args = context.call_args
9494
keywords = context.call_keywords
95-
name = args[0] if args else keywords["name"]
95+
name = args[0] if args else keywords.get("name", None)
9696
if isinstance(name, str) and name.lower() in (
9797
"md4",
9898
"md5",

0 commit comments

Comments
 (0)