From 1eceb5a8d39067c5ef1926be8bdbdc4e4450a8f8 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Thu, 20 May 2021 21:02:45 +0300 Subject: [PATCH] parseAddress: improve port parsing (verify that port is a valid int) --- src/Common/parseAddress.cpp | 9 ++++++--- tests/queries/0_stateless/01880_remote_ipv6.sql | 6 +++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Common/parseAddress.cpp b/src/Common/parseAddress.cpp index b398f5cff10..c99c08896ab 100644 --- a/src/Common/parseAddress.cpp +++ b/src/Common/parseAddress.cpp @@ -39,13 +39,16 @@ std::pair 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(port_number, port + 1)) + ReadBufferFromMemory port_buf(port, end - port); + if (!tryReadText(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) { diff --git a/tests/queries/0_stateless/01880_remote_ipv6.sql b/tests/queries/0_stateless/01880_remote_ipv6.sql index 9d9c25addbf..057b3ad7ec6 100644 --- a/tests/queries/0_stateless/01880_remote_ipv6.sql +++ b/tests/queries/0_stateless/01880_remote_ipv6.sql @@ -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 }