##// END OF EJS Templates
Swallow potential exceptions from showtraceback() (#13934)...
Matthias Bussonnier -
r28101:e548ee23 merge
parent child Browse files
Show More
@@ -3013,7 +3013,7 b' class InteractiveShell(SingletonConfigurable):'
3013 runner = _pseudo_sync_runner
3013 runner = _pseudo_sync_runner
3014
3014
3015 try:
3015 try:
3016 return runner(coro)
3016 result = runner(coro)
3017 except BaseException as e:
3017 except BaseException as e:
3018 info = ExecutionInfo(
3018 info = ExecutionInfo(
3019 raw_cell, store_history, silent, shell_futures, cell_id
3019 raw_cell, store_history, silent, shell_futures, cell_id
@@ -3021,6 +3021,7 b' class InteractiveShell(SingletonConfigurable):'
3021 result = ExecutionResult(info)
3021 result = ExecutionResult(info)
3022 result.error_in_exec = e
3022 result.error_in_exec = e
3023 self.showtraceback(running_compiled_code=True)
3023 self.showtraceback(running_compiled_code=True)
3024 finally:
3024 return result
3025 return result
3025
3026
3026 def should_run_async(
3027 def should_run_async(
@@ -1127,3 +1127,49 b' def test_set_custom_completer():'
1127
1127
1128 # clean up
1128 # clean up
1129 ip.Completer.custom_matchers.pop()
1129 ip.Completer.custom_matchers.pop()
1130
1131
1132 class TestShowTracebackAttack(unittest.TestCase):
1133 """Test that the interactive shell is resilient against the client attack of
1134 manipulating the showtracebacks method. These attacks shouldn't result in an
1135 unhandled exception in the kernel."""
1136
1137 def setUp(self):
1138 self.orig_showtraceback = interactiveshell.InteractiveShell.showtraceback
1139
1140 def tearDown(self):
1141 interactiveshell.InteractiveShell.showtraceback = self.orig_showtraceback
1142
1143 def test_set_show_tracebacks_none(self):
1144 """Test the case of the client setting showtracebacks to None"""
1145
1146 result = ip.run_cell(
1147 """
1148 import IPython.core.interactiveshell
1149 IPython.core.interactiveshell.InteractiveShell.showtraceback = None
1150
1151 assert False, "This should not raise an exception"
1152 """
1153 )
1154 print(result)
1155
1156 assert result.result is None
1157 assert isinstance(result.error_in_exec, TypeError)
1158 assert str(result.error_in_exec) == "'NoneType' object is not callable"
1159
1160 def test_set_show_tracebacks_noop(self):
1161 """Test the case of the client setting showtracebacks to a no op lambda"""
1162
1163 result = ip.run_cell(
1164 """
1165 import IPython.core.interactiveshell
1166 IPython.core.interactiveshell.InteractiveShell.showtraceback = lambda *args, **kwargs: None
1167
1168 assert False, "This should not raise an exception"
1169 """
1170 )
1171 print(result)
1172
1173 assert result.result is None
1174 assert isinstance(result.error_in_exec, AssertionError)
1175 assert str(result.error_in_exec) == "This should not raise an exception"
General Comments 0
You need to be logged in to leave comments. Login now