forked from M-Labs/artiq
1
0
Fork 0

coredevice: truncate overlong exception messages.

If we have a really long one (megabytes) then this may exhaust
the heap of the core device and crash it.
This commit is contained in:
whitequark 2017-06-25 04:39:08 +00:00
parent 1fa8be3835
commit fdb24ef139
1 changed files with 10 additions and 3 deletions

View File

@ -494,6 +494,12 @@ class CommKernel:
else:
raise IOError("Unknown RPC value tag: {}".format(repr(tag)))
def _truncate_message(self, msg, limit=4096):
if len(msg) > limit:
return msg[0:limit] + "... (truncated)"
else:
return msg
def _serve_rpc(self, embedding_map):
async = self._read_bool()
service_id = self._read_int32()
@ -526,7 +532,7 @@ class CommKernel:
if hasattr(exn, "artiq_core_exception"):
exn = exn.artiq_core_exception
self._write_string(exn.name)
self._write_string(exn.message)
self._write_string(self._truncate_message(exn.message))
for index in range(3):
self._write_int64(exn.param[index])
@ -543,8 +549,9 @@ class CommKernel:
else:
exn_id = embedding_map.store_object(exn_type)
self._write_string("{}:{}.{}".format(exn_id,
exn_type.__module__, exn_type.__qualname__))
self._write_string(str(exn))
exn_type.__module__,
exn_type.__qualname__))
self._write_string(self._truncate_message(str(exn)))
for index in range(3):
self._write_int64(0)