summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@araneo.org>2015-09-23 16:40:28 +0200
committerTimotej Lazar <timotej.lazar@araneo.org>2015-09-23 16:40:28 +0200
commit45f1f450382c289e38a2224f0cc085e35684a3f0 (patch)
tree6a25b649558358fe1c6071f97a68c551863e30a9 /server
parent0e44fc38d85723db970089f6628a3f5093c515bd (diff)
Kill Python interpreter on excessive output
Diffstat (limited to 'server')
-rw-r--r--server/python_session.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/server/python_session.py b/server/python_session.py
index 85e1d2e..55a4812 100644
--- a/server/python_session.py
+++ b/server/python_session.py
@@ -150,12 +150,19 @@ def _interpreter(control, callback):
if retcode is None:
data = proc.stdout.read()
if data:
- # NOTE this might fail if read() stops in the middle of utf8 sequence
- text = data.decode('utf-8')
- if text:
- callback(text)
+ if len(data) > 20000:
+ proc.kill()
+ proc = None
+ callback('Child killed for talking too much.\n')
+ else:
+ # NOTE this might fail if read() stops in the middle of utf8 sequence
+ text = data.decode('utf-8')
+ if text:
+ callback(text)
else:
- if retcode == -31:
+ if retcode == -9: # killed by ulimit
+ callback('Child killed due to overconsumption.\n')
+ elif retcode == -31: # killed by seccomp
callback('Child killed due to sandbox misbehavior.\n')
else:
callback('Child exited with status "{}".\n'.format(retcode))