From 35d8b178ce97ffcdc556dcf8bda68c570bb66bc5 Mon Sep 17 00:00:00 2001 From: Lauren Perry Date: Tue, 20 Jan 2015 11:48:05 +0000 Subject: Fix distbuild controller crashing on some invalid inputs --- distbuild/initiator_connection.py | 22 +++++++++++++--------- distbuild/jm.py | 9 +++++++-- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/distbuild/initiator_connection.py b/distbuild/initiator_connection.py index db982230..4bb3889a 100644 --- a/distbuild/initiator_connection.py +++ b/distbuild/initiator_connection.py @@ -100,15 +100,19 @@ class InitiatorConnection(distbuild.StateMachine): logging.debug('InitiatorConnection: from %s: %r', self.initiator_name, event.msg) - if event.msg['type'] == 'build-request': - new_id = self._idgen.next() - self.our_ids.add(new_id) - self._route_map.add(event.msg['id'], new_id) - event.msg['id'] = new_id - build_controller = distbuild.BuildController( - self, event.msg, self.artifact_cache_server, - self.morph_instance) - self.mainloop.add_state_machine(build_controller) + try: + if event.msg['type'] == 'build-request': + new_id = self._idgen.next() + self.our_ids.add(new_id) + self._route_map.add(event.msg['id'], new_id) + event.msg['id'] = new_id + build_controller = distbuild.BuildController( + self, event.msg, self.artifact_cache_server, + self.morph_instance) + self.mainloop.add_state_machine(build_controller) + except (KeyError, ValueError) as ex: + logging.error('Invalid message from initiator: %s: exception %s', + event.msg, ex.value) def _disconnect(self, event_source, event): for id in self.our_ids: diff --git a/distbuild/jm.py b/distbuild/jm.py index 1277b4db..68fb6088 100644 --- a/distbuild/jm.py +++ b/distbuild/jm.py @@ -105,8 +105,13 @@ class JsonMachine(StateMachine): line = line.rstrip() if self.debug_json: logging.debug('JsonMachine: line: %s' % repr(line)) - msg = yaml.load(json.loads(line)) - self.mainloop.queue_event(self, JsonNewMessage(msg)) + msg = None + try: + msg = yaml.safe_load(json.loads(line)) + except Exception: + logging.error('Invalid input: %s' % line) + if msg: + self.mainloop.queue_event(self, JsonNewMessage(msg)) def _send_eof(self, event_source, event): self.mainloop.queue_event(self, JsonEof()) -- cgit v1.2.1 From 9ae7b0e248e2c4738e66d3820173cf8bb6d6d6eb Mon Sep 17 00:00:00 2001 From: Lauren Perry Date: Thu, 29 Jan 2015 16:24:19 +0000 Subject: Update copyright years --- distbuild/initiator_connection.py | 2 +- distbuild/jm.py | 2 +- distbuild/socketsrc.py | 2 +- distbuild/sockserv.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/distbuild/initiator_connection.py b/distbuild/initiator_connection.py index 4bb3889a..b53ede2f 100644 --- a/distbuild/initiator_connection.py +++ b/distbuild/initiator_connection.py @@ -1,6 +1,6 @@ # distbuild/initiator_connection.py -- communicate with initiator # -# Copyright (C) 2012, 2014 Codethink Limited +# Copyright (C) 2012, 2015 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/distbuild/jm.py b/distbuild/jm.py index 68fb6088..90b2ba6f 100644 --- a/distbuild/jm.py +++ b/distbuild/jm.py @@ -1,6 +1,6 @@ # mainloop/jm.py -- state machine for JSON communication between nodes # -# Copyright (C) 2012, 2014 Codethink Limited +# Copyright (C) 2012, 2015 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/distbuild/socketsrc.py b/distbuild/socketsrc.py index 21c99b42..6bf02e76 100644 --- a/distbuild/socketsrc.py +++ b/distbuild/socketsrc.py @@ -1,6 +1,6 @@ # mainloop/socketsrc.py -- events and event sources for sockets # -# Copyright (C) 2012, 2014 Codethink Limited +# Copyright (C) 2012, 2015 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/distbuild/sockserv.py b/distbuild/sockserv.py index 964352e7..6b7f994d 100644 --- a/distbuild/sockserv.py +++ b/distbuild/sockserv.py @@ -1,6 +1,6 @@ # mainloop/sockserv.py -- socket server state machines # -# Copyright (C) 2012, 2014 Codethink Limited +# Copyright (C) 2012, 2015 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by -- cgit v1.2.1