Skip to content

Commit

Permalink
Replace eval() with ast.literal_eval() for security reasons
Browse files Browse the repository at this point in the history
Summary:
Context: T176600074

As per https://www.internalfb.com/intern/staticdocs/pyre/docs/fb/warning_codes/code-5001, one of the recommended solutions is to replace eval() with ast.literal_eval()

Reviewed By: wat3rBro

Differential Revision: D56144071

fbshipit-source-id: 28f90ccbadb74455b70062ec0f058ae84ce402ee
  • Loading branch information
Naveen Suda authored and facebook-github-bot committed Apr 15, 2024
1 parent b7c7f4b commit 9ca6689
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion detectron2/config/lazy.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def safe_update(cfg, key, value):
for o in overrides:
key, value = o.split("=")
try:
value = eval(value, {})
value = ast.literal_eval(value)
except NameError:
pass
safe_update(cfg, key, value)
Expand Down
2 changes: 1 addition & 1 deletion tests/config/test_lazy_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_overrides(self):
self.assertEqual(cfg.dir1b_dict.a, "123")
self.assertEqual(cfg.lazyobj.x, 123)

LazyConfig.apply_overrides(cfg, ["dir1b_dict.a=abc"])
LazyConfig.apply_overrides(cfg, ["dir1b_dict.a='abc'"])
self.assertEqual(cfg.dir1b_dict.a, "abc")

def test_invalid_overrides(self):
Expand Down

0 comments on commit 9ca6689

Please sign in to comment.