From 60b36c421380b1ded02c5c6118f9e6dda070249d Mon Sep 17 00:00:00 2001 From: sebres Date: Thu, 26 Apr 2018 16:24:35 +0200 Subject: [PATCH] rewritten preventive measure to convert "unexpected" type before pickled in CS-protocols: don't convert all basic types now (also bool, int etc). Fixed bug with ignoreself option, which reached fail2ban-server as string 'False' (and not as boolean), so no matter which value was set - it results always in True (see gh-2078). --- fail2ban/client/csocket.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/fail2ban/client/csocket.py b/fail2ban/client/csocket.py index 3b48e507..ab3e294b 100644 --- a/fail2ban/client/csocket.py +++ b/fail2ban/client/csocket.py @@ -47,9 +47,7 @@ class CSocket: def send(self, msg, nonblocking=False, timeout=None): # Convert every list member to string - obj = dumps(map( - lambda m: str(m) if not isinstance(m, (list, dict, set)) else m, msg), - HIGHEST_PROTOCOL) + obj = dumps(map(CSocket.convert, msg), HIGHEST_PROTOCOL) self.__csock.send(obj + CSPROTO.END) return self.receive(self.__csock, nonblocking, timeout) @@ -70,6 +68,14 @@ class CSocket: pass self.__csock = None + @staticmethod + def convert(m): + """Convert every "unexpected" member of message to string""" + if isinstance(m, (basestring, bool, int, float, list, dict, set)): + return m + else: # pragma: no cover + return str(m) + @staticmethod def receive(sock, nonblocking=False, timeout=None): msg = CSPROTO.EMPTY