Skip to content

Commit

Permalink
importlib.import_module also needs to handle string types (#389)
Browse files Browse the repository at this point in the history
The importlib.import_module module and function also needs to correctly
handle the new format for "true" strings in an argument value. It needs
to use value_str instead of value.

Signed-off-by: Eric Brown <eric.brown@securesauce.dev>
  • Loading branch information
ericwb authored Mar 26, 2024
1 parent 0e3a5ac commit 3d06551
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions precli/parsers/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ def unparse_import_from_statement(self, imports: tuple) -> str:
return f"from {package} import {', '.join(modules)}"

def importlib_import_module(self, call: Call) -> dict:
name = call.get_argument(position=0, name="name").value
package = call.get_argument(position=1, name="package").value
name = call.get_argument(position=0, name="name").value_str
package = call.get_argument(position=1, name="package").value_str
if package is None:
return name
subpkg = len(name) - len(name.lstrip(".")) - 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# level: ERROR
# start_line: 10
# end_line: 10
# start_column: 0
# end_column: 11
import importlib


hashlib = importlib.import_module("hashlib")
hashlib.md5()
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def test_rule_meta(self):
"hashlib_md4.py",
"hashlib_md5.py",
"hashlib_md5_as_identifier.py",
"hashlib_md5_importlib.py",
"hashlib_md5_usedforsecurity_true.py",
"hashlib_new_blake2b.py",
"hashlib_new_blake2s.py",
Expand Down

0 comments on commit 3d06551

Please sign in to comment.