Skip to content

Commit d4a461a

Browse files
author
Paweł Andruszkiewicz
committed
BUG#36105235 Uri_parser fails to parse an URI which contains unescaped '@' character
When an URL contained an unescaped '@' character in the target path, i.e.: https://mysql.com/@.manifest.json Uri_parser treated "mysql.com/" as a user name. Slash is not a valid character in a user name, and an exception was thrown. Change-Id: I5a5fa848043029c2cf0a6102a0fe992261c7557d
1 parent 78aa9ae commit d4a461a

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

mysqlshdk/libs/db/uri_parser.cc

+6-3
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,10 @@ void Uri_parser::preprocess(const std::string &input) {
808808
// It is safe to look for the first @ symbol since before the
809809
// userinfo@targetinfo the @ should come pct-encoded. i.e. in a password
810810
position = input.find("@", first_char);
811-
if (position != std::string::npos) {
811+
812+
// BUG#36105235 - make sure that '@' was not found in the path part of query
813+
// NOTE: if '/' is not found, second condition is also true
814+
if (position != std::string::npos && position < input.find("/", first_char)) {
812815
if (position > first_char) {
813816
_chunks[URI_USER_INFO] = {first_char, position - 1};
814817
first_char = position + 1;
@@ -835,9 +838,9 @@ void Uri_parser::preprocess(const std::string &input) {
835838
// definition
836839

837840
int path_offset = 0;
838-
if (m_type == Type::Generic)
841+
if (m_type == Type::Generic) {
839842
position = input.find("/", first_char);
840-
else {
843+
} else {
841844
position = input.rfind("/", last_char);
842845
path_offset = 1;
843846
}

unittest/mysqlshdk/libs/db/uri_parser_t.cc

+5
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,11 @@ TEST(Uri_parser, parse_user_info) {
474474
validate_bad_uri("ssh://user%2Aname:p@[email protected]",
475475
"Illegal character [@] found at position 26", Type::Ssh);
476476
validate_bad_uri("ssh://:[email protected]", "Missing user name", Type::Ssh);
477+
478+
// BUG#36105235 - an unescaped '@' character in the target path
479+
validate_uri("mysqlx://mysql.com/@.manifest.json", "mysqlx", NO_USER,
480+
NO_PASSWORD, "mysql.com", NO_PORT, NO_SOCK, "@.manifest.json",
481+
HAS_NO_PASSWORD, HAS_NO_PORT, Transport_type::Tcp, false);
477482
}
478483

479484
TEST(Uri_parser, parse_host_name) {

0 commit comments

Comments
 (0)