Author: Emre Kultursay Date: 2020-03-26T11:35:54+01:00 New Revision: 57be22fa179703b78b1807217b72eaffa0c518bf
URL: https://github.com/llvm/llvm-project/commit/57be22fa179703b78b1807217b72eaffa0c518bf DIFF: https://github.com/llvm/llvm-project/commit/57be22fa179703b78b1807217b72eaffa0c518bf.diff LOG: [LLDB] Fix parsing of IPv6 host:port inside brackets Summary: When using IPv6 host:port pairs, typically the host is put inside brackets, such as [2601:1234:...:0213]:5555, and the UriParser can handle this format. However, the Android infrastructure in LLDB assumes an additional brackets around the host:port pair, such that the entire host:port string can be treated as the host (which is used as an Android Serial Number), and UriParser cannot handle multiple brackets. Parsing inputs with such extra backets requires searching the closing bracket from the right. Test: BracketedHostnameWithPortIPv6 covers the case mentioned above Reviewers: #lldb, labath Reviewed By: labath Subscribers: kwk, shafik, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D76736 Added: Modified: lldb/source/Utility/UriParser.cpp lldb/unittests/Utility/UriParserTest.cpp Removed: ################################################################################ diff --git a/lldb/source/Utility/UriParser.cpp b/lldb/source/Utility/UriParser.cpp index a6172caa8c5c..8169b0eee121 100644 --- a/lldb/source/Utility/UriParser.cpp +++ b/lldb/source/Utility/UriParser.cpp @@ -42,7 +42,7 @@ bool UriParser::Parse(llvm::StringRef uri, llvm::StringRef &scheme, // Extract hostname if (!host_port.empty() && host_port[0] == '[') { // hostname is enclosed with square brackets. - pos = host_port.find(']'); + pos = host_port.rfind(']'); if (pos == std::string::npos) return false; diff --git a/lldb/unittests/Utility/UriParserTest.cpp b/lldb/unittests/Utility/UriParserTest.cpp index c07d59a55e01..c88a647ef937 100644 --- a/lldb/unittests/Utility/UriParserTest.cpp +++ b/lldb/unittests/Utility/UriParserTest.cpp @@ -74,12 +74,19 @@ TEST(UriParserTest, LongPath) { VALIDATE } -TEST(UriParserTest, TypicalPortPath) { +TEST(UriParserTest, TypicalPortPathIPv4) { const UriTestCase testCase("connect://192.168.100.132:5432/", "connect", "192.168.100.132", 5432, "/"); VALIDATE; } +TEST(UriParserTest, TypicalPortPathIPv6) { + const UriTestCase testCase( + "connect://[2601:600:107f:db64:a42b:4faa:284:3082]:5432/", "connect", + "2601:600:107f:db64:a42b:4faa:284:3082", 5432, "/"); + VALIDATE; +} + TEST(UriParserTest, BracketedHostnamePort) { const UriTestCase testCase("connect://[192.168.100.132]:5432/", "connect", "192.168.100.132", 5432, "/"); @@ -102,6 +109,21 @@ TEST(UriParserTest, BracketedHostname) { VALIDATE } +TEST(UriParserTest, BracketedHostnameWithPortIPv4) { + // Android device over IPv4: port is a part of the hostname. + const UriTestCase testCase("connect://[192.168.100.132:1234]", "connect", + "192.168.100.132:1234", -1, "/"); + VALIDATE +} + +TEST(UriParserTest, BracketedHostnameWithPortIPv6) { + // Android device over IPv6: port is a part of the hostname. + const UriTestCase testCase( + "connect://[[2601:600:107f:db64:a42b:4faa:284]:1234]", "connect", + "[2601:600:107f:db64:a42b:4faa:284]:1234", -1, "/"); + VALIDATE +} + TEST(UriParserTest, BracketedHostnameWithColon) { const UriTestCase testCase("connect://[192.168.100.132:5555]:1234", "connect", "192.168.100.132:5555", 1234, "/"); _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits