parseAddress: improve port parsing (verify that port is a valid int)

This commit is contained in:
Azat Khuzhin 2021-05-20 21:02:45 +03:00
parent 44c85edae0
commit 1eceb5a8d3
2 changed files with 9 additions and 6 deletions

View File

@ -39,13 +39,16 @@ std::pair<std::string, UInt16> parseAddress(const std::string & str, UInt16 defa
throw Exception(ErrorCodes::BAD_ARGUMENTS,
"Illegal port prefix passed to function parseAddress: {}", port);
++port;
UInt16 port_number;
if (!tryParse<UInt16>(port_number, port + 1))
ReadBufferFromMemory port_buf(port, end - port);
if (!tryReadText<UInt16>(port_number, port_buf) || !port_buf.eof())
{
throw Exception(ErrorCodes::BAD_ARGUMENTS,
"Illegal port passed to function parseAddress: {}", port + 1);
"Illegal port passed to function parseAddress: {}", port);
}
return { std::string(begin, port), port_number };
return { std::string(begin, port - 1), port_number };
}
else if (default_port)
{

View File

@ -4,9 +4,9 @@ SELECT * FROM remote('[::1]', system.one) FORMAT Null;
SELECT * FROM remote('[::1]:9000', system.one) FORMAT Null;
SELECT * FROM remote('[::1', system.one) FORMAT Null; -- { serverError 36 }
SELECT * FROM remote('::1]', system.one) FORMAT Null; -- { serverError 519 }
SELECT * FROM remote('::1', system.one) FORMAT Null; -- { serverError 519 }
SELECT * FROM remote('::1]', system.one) FORMAT Null; -- { serverError 36 }
SELECT * FROM remote('::1', system.one) FORMAT Null; -- { serverError 36 }
SELECT * FROM remote('[::1][::1]', system.one) FORMAT Null; -- { serverError 36 }
SELECT * FROM remote('[::1][::1', system.one) FORMAT Null; -- { serverError 36 }
SELECT * FROM remote('[::1]::1]', system.one) FORMAT Null; -- { serverError 519 }
SELECT * FROM remote('[::1]::1]', system.one) FORMAT Null; -- { serverError 36 }