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).
pull/2133/head
sebres 2018-04-26 16:24:35 +02:00
parent e01981cc72
commit 60b36c4213
1 changed files with 9 additions and 3 deletions

View File

@ -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