Open aaaaalbert opened 10 years ago
To test @DennisMirante's patch, I modified the Repy runtime function randombytes
(any other will do too) to call tracebackrepy.handle_internalerror
. This now reliably triggers an "Internal Error" when I run the trigger script from the command line.
To trigger the "Unsafe call" problem, we need to make Repy use the servicelog:
python repy.py --servicelog restrictions.default trigger_internal_error.r2py
This however only shifts the problem to the next unsafe call, this time it's hasattr
in the Python posixpath
library:
Internal Error
---
Uncaught exception!
None
Inner abort of servicelogger
("Unsafe call 'hasattr' with args '(<module 'posixpath' from '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.pyc'>, 'samefile')', kwargs '{}'",) <class 'exception_hierarchy.RunBuiltinException'>
Traceback (most recent call last):
File "/Users/albert/Downloads/sensibility-20140924-1449/seattle_repy/tracebackrepy.py", line 246, in handle_internalerror
File "/Users/albert/Downloads/sensibility-20140924-1449/seattle_repy/servicelogger.py", line 213, in multi_process_log
File "/Users/albert/Downloads/sensibility-20140924-1449/seattle_repy/servicelogger.py", line 119, in get_servicevessel
File "/Users/albert/Downloads/sensibility-20140924-1449/seattle_repy/persist.py", line 163, in restore_object
File "/Users/albert/Downloads/sensibility-20140924-1449/seattle_repy/persist.py", line 89, in _copy
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 116, in copy
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 67, in copyfile
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 55, in _samefile
File "/Users/albert/Downloads/sensibility-20140924-1449/seattle_repy/safe.py", line 493, in exceptionraiser
RunBuiltinException: ("Unsafe call 'hasattr' with args '(<module 'posixpath' from '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.pyc'>, 'samefile')', kwargs '{}'",)
If you add: "hasattr = hasattr" to the outer scope of the servicelogger, I think it should fix this issue. We have similar code elsewhere that stashes references to exactly the unsafe calls we need.
On Fri, Sep 26, 2014 at 5:52 PM, aaaaalbert notifications@github.com wrote:
To test @DennisMirante https://github.com/DennisMirante's patch, I modified the Repy runtime function randombytes (any other will do too) to call tracebackrepy.handle_internalerror. This now reliably triggers an "Internal Error" when I run the trigger script from the command line.
To trigger the "Unsafe call" problem, we need to make Repy use the servicelog: python repy.py --servicelog restrictions.default trigger_internal_error.r2py
This however only shifts the problem to the next unsafe call, this time it's hasattr in the Python posixpath library:
Internal Error
Uncaught exception! None Inner abort of servicelogger ("Unsafe call 'hasattr' with args '(<module 'posixpath' from '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.pyc'>, 'samefile')', kwargs '{}'",) <class 'exception_hierarchy.RunBuiltinException'> Traceback (most recent call last): File "/Users/albert/Downloads/sensibility-20140924-1449/seattle_repy/tracebackrepy.py", line 246, in handle_internalerror File "/Users/albert/Downloads/sensibility-20140924-1449/seattle_repy/servicelogger.py", line 213, in multi_process_log File "/Users/albert/Downloads/sensibility-20140924-1449/seattle_repy/servicelogger.py", line 119, in get_servicevessel File "/Users/albert/Downloads/sensibility-20140924-1449/seattle_repy/persist.py", line 163, in restore_object File "/Users/albert/Downloads/sensibility-20140924-1449/seattle_repy/persist.py", line 89, in _copy File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 116, in copy File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 67, in copyfile File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 55, in _samefile File "/Users/albert/Downloads/sensibility-20140924-1449/seattle_repy/safe.py", line 493, in exceptionraiser RunBuiltinException: ("Unsafe call 'hasattr' with args '(<module 'posixpath' from '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.pyc'>, 'samefile')', kwargs '{}'",)
— Reply to this email directly or view it on GitHub https://github.com/SeattleTestbed/repy_v2/issues/92#issuecomment-57025409 .
I ended up adding a couple of things to namespace.py
:
import shutil
shutil.hasattr = hasattr
shutil.open = open
import persist
persist.open = open
persist.eval = eval
I'll experiment some more to see if that's the best place to put these additional stashes.
As a consequence of #69,
safe.py
destroying builtins likeimport
for everything that runs after it (including other Python code of the Repy runtime!),tracebackrepy.py
triggers an error when trying to log an "Internal Error" of Repy into the servicelogger log. See below for a traceback. This is because itimport
s a library inside of thehandle_internalerror
function rather than in the outmost scope (where it would be executed whentracebackrepy
itself is imported).Since it's probably a good idea to keep
safe.py
as paranoid about builtins as it is, the workaround will be to move the import ofservicelogger
out of the function.@DennisMirante suggested a patch whose gist is to move the import to the top,
and then use
service_logger
in place ofservicelogger
inhandle_internalerrror
.(With this, we need to check that
service_logger
is not callable from within Repy code.)Here's an emanation of the problem, as reported by @yyzhuang.