Skip to content

Commit d63677b

Browse files
committed
torcontrol: Fix ParseTorReplyMapping
- Ignore remaining input if it is an OptArguments - Correctly handle escapes
1 parent 29f3c20 commit d63677b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/torcontrol.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,17 +277,19 @@ static std::map<std::string,std::string> ParseTorReplyMapping(const std::string
277277
size_t ptr=0;
278278
while (ptr < s.size()) {
279279
std::string key, value;
280-
while (ptr < s.size() && s[ptr] != '=') {
280+
while (ptr < s.size() && s[ptr] != '=' && s[ptr] != ' ') {
281281
key.push_back(s[ptr]);
282282
++ptr;
283283
}
284284
if (ptr == s.size()) // unexpected end of line
285285
return std::map<std::string,std::string>();
286+
if (s[ptr] == ' ') // The remaining string is an OptArguments
287+
break;
286288
++ptr; // skip '='
287289
if (ptr < s.size() && s[ptr] == '"') { // Quoted string
288290
++ptr; // skip opening '"'
289291
bool escape_next = false;
290-
while (ptr < s.size() && (!escape_next && s[ptr] != '"')) {
292+
while (ptr < s.size() && (escape_next || s[ptr] != '"')) {
291293
escape_next = (s[ptr] == '\\');
292294
value.push_back(s[ptr]);
293295
++ptr;

0 commit comments

Comments
 (0)