From 06c4d75f277217b6026d49ce8da180954ecefd8d Mon Sep 17 00:00:00 2001 From: bernd Date: Mon, 17 Jul 2023 19:07:37 +0200 Subject: [PATCH] utf-8 decoding in ein try-except gepackt --- source/server/apistatusd.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/source/server/apistatusd.py b/source/server/apistatusd.py index 9a89b4a..d6ef14e 100755 --- a/source/server/apistatusd.py +++ b/source/server/apistatusd.py @@ -132,9 +132,18 @@ def receive_buffer_is_valid(raw_data): param 1: byte object return: boolean ''' - if raw_data.decode('utf-8', 'strict') in ('0', '1'): - logging.debug('Argument is valid: {}'.format(raw_data)) - return True + try: + if raw_data.decode('utf-8', 'strict') in ('0', '1'): + logging.debug('Argument is valid: {}'.format(raw_data)) + return True + except UnicodeDecodeError as err: + logging.error('Argument is not valid unicode') + logging.error(err) + return False + except Exception as err: + logging.error('Exception occurred') + logging.error(err) + return False logging.debug('Argument is not valid: {}'.format(raw_data)) return False