mirror of
https://github.com/idapython/src
synced 2026-06-08 14:47:00 +00:00
BUGFIX: IDAPython: inspect.stack() could fail on recent versions of Python3 (e.g., Python 3.7.4)
Don't leave empty strings ('') as '__file__' members of builtin modules' globals; some modules such as inspect expect that built-in modules don't have such an attribute.
This commit is contained in:
@@ -453,8 +453,11 @@ def IDAPython_ExecScript(script, g, print_error=True):
|
||||
sys.argv = [ script ]
|
||||
|
||||
# Adjust the __file__ path in the globals we pass to the script
|
||||
old__file__ = g['__file__'] if '__file__' in g else ''
|
||||
g['__file__'] = script
|
||||
FILE_ATTR = "__file__"
|
||||
has__file__ = FILE_ATTR in g
|
||||
if has__file__:
|
||||
old__file__ = g[FILE_ATTR]
|
||||
g[FILE_ATTR] = script
|
||||
|
||||
try:
|
||||
with open(script) as fin:
|
||||
@@ -467,7 +470,10 @@ def IDAPython_ExecScript(script, g, print_error=True):
|
||||
print(PY_COMPILE_ERR)
|
||||
finally:
|
||||
# Restore state
|
||||
g['__file__'] = old__file__
|
||||
if has__file__:
|
||||
g[FILE_ATTR] = old__file__
|
||||
else:
|
||||
del g[FILE_ATTR]
|
||||
sys.argv = argv
|
||||
|
||||
return PY_COMPILE_ERR
|
||||
|
||||
Reference in New Issue
Block a user