Correctly handle three-digit octals with leading digit 4-7

This commit is contained in:
Jack Grigg
2017-04-21 13:22:51 +12:00
parent d15cab21bc
commit 8df5fd1116
2 changed files with 8 additions and 7 deletions

View File

@@ -329,13 +329,14 @@ 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')) {
escaped_value.push_back(strtol(value.substr(i, j).c_str(), NULL, 8));
// Account for automatic incrementing at loop end
i += j - 1;
} else {
escaped_value.push_back(value[i]);
// 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;
} else {
escaped_value.push_back(value[i]);
}