diff options
author | Shreyas Kalyan <shreyaskalyan@gmail.com> | 2018-10-08 15:49:24 -0400 |
---|---|---|
committer | Shreyas Kalyan <shreyaskalyan@gmail.com> | 2018-10-12 16:35:55 -0400 |
commit | 2e58710210f996eea00e192f987ae90acb71abbf (patch) | |
tree | 4eb63e2f39158302eadb96d15013dfde85730e08 /src/mongo/client/mongo_uri.cpp | |
parent | 8657f94a66ff4950a9dc4c04eebec86730d87db2 (diff) | |
download | mongo-2e58710210f996eea00e192f987ae90acb71abbf.tar.gz |
SERVER-36272 Catch error in parsing values after % in URIs
Diffstat (limited to 'src/mongo/client/mongo_uri.cpp')
-rw-r--r-- | src/mongo/client/mongo_uri.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/mongo/client/mongo_uri.cpp b/src/mongo/client/mongo_uri.cpp index ea455cb0794..6d4eb7f83b0 100644 --- a/src/mongo/client/mongo_uri.cpp +++ b/src/mongo/client/mongo_uri.cpp @@ -84,13 +84,20 @@ void mongo::uriEncode(std::ostream& ss, StringData toEncode, StringData passthro mongo::StatusWith<std::string> mongo::uriDecode(StringData toDecode) { StringBuilder out; for (size_t i = 0; i < toDecode.size(); ++i) { - const auto c = toDecode[i]; + const char c = toDecode[i]; if (c == '%') { if (i + 2 > toDecode.size()) { return Status(ErrorCodes::FailedToParse, "Encountered partial escape sequence at end of string"); } - out << fromHex(toDecode.substr(i + 1, 2)); + auto swHex = fromHex(toDecode.substr(i + 1, 2)); + if (swHex.isOK()) { + out << swHex.getValue(); + } else { + return Status(ErrorCodes::FailedToParse, + "The characters after the % do not form a hex value. Please escape " + "the % or pass a valid hex value. "); + } i += 2; } else { out << c; |