Correctly handle three-digit octals with leading digit 4-7
This commit is contained in:
parent
d15cab21bc
commit
8df5fd1116
|
@ -147,7 +147,7 @@ BOOST_AUTO_TEST_CASE(util_ParseTorReplyMapping)
|
|||
"Foo=\"Bar\\nBaz\\t\" Spam=\"\\rEggs\" Octals=\"\\1a\\11\\17\\18\\81\\377\\378\\400\" Final=Check", {
|
||||
{"Foo", "Bar\nBaz\t"},
|
||||
{"Spam", "\rEggs"},
|
||||
{"Octals", "\1a\11\17\1" "881\377\37" "8400"},
|
||||
{"Octals", "\1a\11\17\1" "881\377\37" "8\40" "0"},
|
||||
{"Final", "Check"},
|
||||
});
|
||||
CheckParseTorReplyMapping(
|
||||
|
|
|
@ -329,7 +329,11 @@ static std::map<std::string,std::string> ParseTorReplyMapping(const std::string
|
|||
// octal digit if encountered sooner.
|
||||
for (j = 1; j < 3 && (i+j) < value.size() && '0' <= value[i+j] && value[i+j] <= '7'; ++j) {}
|
||||
// Tor restricts first digit to 0-3 for three-digit octals.
|
||||
if (j < 3 || ('0' <= value[i] && value[i] <= '3')) {
|
||||
// A leading digit of 4-7 would therefore be interpreted as
|
||||
// a two-digit octal.
|
||||
if (j == 3 && value[i] > '3') {
|
||||
j--;
|
||||
}
|
||||
escaped_value.push_back(strtol(value.substr(i, j).c_str(), NULL, 8));
|
||||
// Account for automatic incrementing at loop end
|
||||
i += j - 1;
|
||||
|
@ -339,9 +343,6 @@ static std::map<std::string,std::string> ParseTorReplyMapping(const std::string
|
|||
} else {
|
||||
escaped_value.push_back(value[i]);
|
||||
}
|
||||
} else {
|
||||
escaped_value.push_back(value[i]);
|
||||
}
|
||||
}
|
||||
value = escaped_value;
|
||||
} else { // Unquoted value. Note that values can contain '=' at will, just no spaces
|
||||
|
|
Loading…
Reference in New Issue