From 87b7f4d878aafb8056df67f6dd622c2e728838c5 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Sun, 26 Mar 2017 14:35:13 +1300 Subject: [PATCH] torcontrol: Log invalid parameters in Tor reply strings where meaningful --- src/torcontrol.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/torcontrol.cpp b/src/torcontrol.cpp index e957e38bd..60181b440 100644 --- a/src/torcontrol.cpp +++ b/src/torcontrol.cpp @@ -261,6 +261,7 @@ static std::pair SplitTorReplyLine(const std::string &s } /** Parse reply arguments in the form 'METHODS=COOKIE,SAFECOOKIE COOKIEFILE=".../control_auth_cookie"'. + * Returns a map of keys to values, or an empty map if there was an error. * Grammar is implicitly defined in https://spec.torproject.org/control-spec by * the server reply formats for PROTOCOLINFO (S3.21), AUTHCHALLENGE (S3.24), * and ADD_ONION (S3.27). See also sections 2.1 and 2.3. @@ -444,6 +445,13 @@ void TorController::add_onion_cb(TorControlConnection& conn, const TorControlRep if ((i = m.find("PrivateKey")) != m.end()) private_key = i->second; } + if (service_id.empty()) { + LogPrintf("tor: Error parsing ADD_ONION parameters:\n"); + for (const std::string &s : reply.lines) { + LogPrintf(" %s\n", SanitizeString(s)); + } + return; + } service = CService(service_id+".onion", GetListenPort(), false); LogPrintf("tor: Got service ID %s, advertizing service %s\n", service_id, service.ToString()); @@ -521,6 +529,10 @@ void TorController::authchallenge_cb(TorControlConnection& conn, const TorContro std::pair l = SplitTorReplyLine(reply.lines[0]); if (l.first == "AUTHCHALLENGE") { std::map m = ParseTorReplyMapping(l.second); + if (m.empty()) { + LogPrintf("tor: Error parsing AUTHCHALLENGE parameters: %s\n", SanitizeString(l.second)); + return; + } std::vector serverHash = ParseHex(m["SERVERHASH"]); std::vector serverNonce = ParseHex(m["SERVERNONCE"]); LogPrint("tor", "tor: AUTHCHALLENGE ServerHash %s ServerNonce %s\n", HexStr(serverHash), HexStr(serverNonce));