From: Jeff Lucovsky Date: Tue, 11 Jan 2022 19:16:24 +0000 (-0500) Subject: suricatasc: Handle incomplete/empty recv values X-Git-Tag: suricata-5.0.9~105 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6500683b09611f1edf24b4e974ff9c627db02b15;p=thirdparty%2Fsuricata.git suricatasc: Handle incomplete/empty recv values Issue: 4947 Improve handling of values returned by recv. Sometimes, recv returns an empty string if suricata terminates asynchronously. (cherry picked from commit fc6fdef07006e5382839ef88873e90754b30e6e0) --- diff --git a/python/suricata/sc/suricatasc.py b/python/suricata/sc/suricatasc.py index b1b41f10ae..30dcf744ba 100644 --- a/python/suricata/sc/suricatasc.py +++ b/python/suricata/sc/suricatasc.py @@ -119,9 +119,14 @@ class SuricataSC: data = "" while True: if sys.version < '3': - data += self.socket.recv(INC_SIZE) + received = self.socket.recv(INC_SIZE) else: - data += self.socket.recv(INC_SIZE).decode('iso-8859-1') + received = self.socket.recv(INC_SIZE).decode('iso-8859-1') + + if not received: + break + + data += received if data.endswith('\n'): cmdret = json.loads(data) break