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\\18\\81\\377\\378\\400\" Final=Check", {
|
||||||
{"Foo", "Bar\nBaz\t"},
|
{"Foo", "Bar\nBaz\t"},
|
||||||
{"Spam", "\rEggs"},
|
{"Spam", "\rEggs"},
|
||||||
{"Octals", "\1a\11\17\1" "881\377\37" "8400"},
|
{"Octals", "\1a\11\17\1" "881\377\37" "8\40" "0"},
|
||||||
{"Final", "Check"},
|
{"Final", "Check"},
|
||||||
});
|
});
|
||||||
CheckParseTorReplyMapping(
|
CheckParseTorReplyMapping(
|
||||||
|
|
|
@ -329,13 +329,14 @@ static std::map<std::string,std::string> ParseTorReplyMapping(const std::string
|
||||||
// octal digit if encountered sooner.
|
// octal digit if encountered sooner.
|
||||||
for (j = 1; j < 3 && (i+j) < value.size() && '0' <= value[i+j] && value[i+j] <= '7'; ++j) {}
|
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.
|
// 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
|
||||||
escaped_value.push_back(strtol(value.substr(i, j).c_str(), NULL, 8));
|
// a two-digit octal.
|
||||||
// Account for automatic incrementing at loop end
|
if (j == 3 && value[i] > '3') {
|
||||||
i += j - 1;
|
j--;
|
||||||
} else {
|
|
||||||
escaped_value.push_back(value[i]);
|
|
||||||
}
|
}
|
||||||
|
escaped_value.push_back(strtol(value.substr(i, j).c_str(), NULL, 8));
|
||||||
|
// Account for automatic incrementing at loop end
|
||||||
|
i += j - 1;
|
||||||
} else {
|
} else {
|
||||||
escaped_value.push_back(value[i]);
|
escaped_value.push_back(value[i]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue