SeattleTestbed / repy_v2

Seattle Testbed's Repy ("Restricted Python") sandbox, version 2
MIT License
12 stars 50 forks source link

Code safety error when Exception object has an `e.lineno` of `None` #135

Closed aaaaalbert closed 7 years ago

aaaaalbert commented 7 years ago

95 and its subsequent fix 3cc932995c89e291e91cb917a52f10f6ccf89820 rectified a problem of line numbers in RepyV2 tracebacks being off by two. Part of the implementation changed safe_check.py to adjust the line numbers in Exception objects accordingly.

It can happen that an Exception object lacks a lineno attribute, and the code takes care of this. However, I recently saw an Exception with e.lineno == None, and then we get this error:

Traceback (most recent call last):
  File "/private/tmp/repy_v2/RUNNABLE/safe_check.py", line 33, in <module>
    len(encoding_header.ENCODING_DECLARATION.splitlines())
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'
Specified repy program is unsafe!
Static-code analysis failed with error: Code failed safety check! Error: Fatal error while evaluating code safety!

The fix is to also check for (and pass) TypeErrors in safe_check.py.