]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
vici: Check for closed connection in Python bindings
authorWeilu Jia <optix2000@teitoku.net>
Tue, 13 Dec 2016 02:17:10 +0000 (18:17 -0800)
committerTobias Brunner <tobias@strongswan.org>
Wed, 14 Dec 2016 10:35:31 +0000 (11:35 +0100)
The Python VICI library does not check if the socket is closed.
If the daemon closes the connection, _recvall() spins forever.

Closes strongswan/strongswan#56.

src/libcharon/plugins/vici/python/vici/protocol.py

index 4951817eb0387a5bec3dec40bd81f658a691ba27..880d3343c401c4ec09dbb6eed3ab05a3091b91d1 100644 (file)
@@ -33,7 +33,10 @@ class Transport(object):
         """Ensure to read count bytes from the socket"""
         data = b""
         while len(data) < count:
-            data += self.socket.recv(count - len(data))
+            buf = self.socket.recv(count - len(data))
+            if not buf:
+                raise socket.error('Connection closed')
+            data += buf
         return data