@@ -267,6 +267,7 @@ static std::pair<std::string,std::string> SplitTorReplyLine(const std::string &s
267
267
}
268
268
269
269
/* * Parse reply arguments in the form 'METHODS=COOKIE,SAFECOOKIE COOKIEFILE=".../control_auth_cookie"'.
270
+ * Returns a map of keys to values, or an empty map if there was an error.
270
271
* Grammar is implicitly defined in https://spec.torproject.org/control-spec by
271
272
* the server reply formats for PROTOCOLINFO (S3.21), AUTHCHALLENGE (S3.24),
272
273
* and ADD_ONION (S3.27). See also sections 2.1 and 2.3.
@@ -450,6 +451,13 @@ void TorController::add_onion_cb(TorControlConnection& _conn, const TorControlRe
450
451
if ((i = m.find (" PrivateKey" )) != m.end ())
451
452
private_key = i->second ;
452
453
}
454
+ if (service_id.empty ()) {
455
+ LogPrintf (" tor: Error parsing ADD_ONION parameters:\n " );
456
+ for (const std::string &s : reply.lines ) {
457
+ LogPrintf (" %s\n " , SanitizeString (s));
458
+ }
459
+ return ;
460
+ }
453
461
service = LookupNumeric (std::string (service_id+" .onion" ).c_str (), GetListenPort ());
454
462
LogPrintf (" tor: Got service ID %s, advertising service %s\n " , service_id, service.ToString ());
455
463
if (WriteBinaryFile (GetPrivateKeyFile (), private_key)) {
@@ -527,6 +535,10 @@ void TorController::authchallenge_cb(TorControlConnection& _conn, const TorContr
527
535
std::pair<std::string,std::string> l = SplitTorReplyLine (reply.lines [0 ]);
528
536
if (l.first == " AUTHCHALLENGE" ) {
529
537
std::map<std::string,std::string> m = ParseTorReplyMapping (l.second );
538
+ if (m.empty ()) {
539
+ LogPrintf (" tor: Error parsing AUTHCHALLENGE parameters: %s\n " , SanitizeString (l.second ));
540
+ return ;
541
+ }
530
542
std::vector<uint8_t > serverHash = ParseHex (m[" SERVERHASH" ]);
531
543
std::vector<uint8_t > serverNonce = ParseHex (m[" SERVERNONCE" ]);
532
544
LogPrint (BCLog::TOR, " tor: AUTHCHALLENGE ServerHash %s ServerNonce %s\n " , HexStr (serverHash), HexStr (serverNonce));
0 commit comments