From 6679baadbb44b0beaae02865c13aff49eba39823 Mon Sep 17 00:00:00 2001 From: anonym Date: Fri, 20 Jan 2017 10:12:33 +0100 Subject: [PATCH] TorManager.send(): read until repsonse terminator. Tor command responses terminate with "250 OK\r\n" so we have to read until that sequence is encountered. The previous implementation is racy: after sending a command it would accept whatever that is found on the socket as its response, no matter if it is correctly terminated or not. This commit fixes: https://github.com/HelloZeroNet/ZeroNet/issues/756 --- src/Tor/TorManager.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Tor/TorManager.py b/src/Tor/TorManager.py index 9eefb6dd..7816b280 100644 --- a/src/Tor/TorManager.py +++ b/src/Tor/TorManager.py @@ -239,10 +239,12 @@ class TorManager: if not conn: conn = self.conn self.log.debug("> %s" % cmd) + back = "" for retry in range(2): try: conn.sendall("%s\r\n" % cmd) - back = conn.recv(1024 * 64).decode("utf8", "ignore") + while not back.endswith("250 OK\r\n"): + back += conn.recv(1024 * 64).decode("utf8", "ignore") break except Exception, err: self.log.error("Tor send error: %s, reconnecting..." % err)