Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TorManager.send(): read until repsonse terminator. #784

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: #756
  • Loading branch information
anonym committed Jan 20, 2017
commit 6679baadbb44b0beaae02865c13aff49eba39823
4 changes: 3 additions & 1 deletion src/Tor/TorManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,12 @@ def send(self, cmd, conn=None):
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)
Expand Down