From 45f1f450382c289e38a2224f0cc085e35684a3f0 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Wed, 23 Sep 2015 16:40:28 +0200 Subject: Kill Python interpreter on excessive output --- server/python_session.py | 17 ++++++++++++----- 1 file 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)) -- cgit v1.2.1