Browse Source

torcontrol: Fix ParseTorReplyMapping

- Ignore remaining input if it is an OptArguments
- Correctly handle escapes
pull/4/head
Jack Grigg 7 years ago
parent
commit
64101d0407
No known key found for this signature in database GPG Key ID: 6A6914DAFBEA00DA
  1. 6
      src/torcontrol.cpp

6
src/torcontrol.cpp

@ -271,17 +271,19 @@ static std::map<std::string,std::string> ParseTorReplyMapping(const std::string
size_t ptr=0;
while (ptr < s.size()) {
std::string key, value;
while (ptr < s.size() && s[ptr] != '=') {
while (ptr < s.size() && s[ptr] != '=' && s[ptr] != ' ') {
key.push_back(s[ptr]);
++ptr;
}
if (ptr == s.size()) // unexpected end of line
return std::map<std::string,std::string>();
if (s[ptr] == ' ') // The remaining string is an OptArguments
break;
++ptr; // skip '='
if (ptr < s.size() && s[ptr] == '"') { // Quoted string
++ptr; // skip opening '"'
bool escape_next = false;
while (ptr < s.size() && (!escape_next && s[ptr] != '"')) {
while (ptr < s.size() && (escape_next || s[ptr] != '"')) {
escape_next = (s[ptr] == '\\');
value.push_back(s[ptr]);
++ptr;

Loading…
Cancel
Save