Index: /Users/vharron/ll/svn/lldb/gtest/unittest/Utility/UriParserTest.cpp =================================================================== --- /Users/vharron/ll/svn/lldb/gtest/unittest/Utility/UriParserTest.cpp +++ /Users/vharron/ll/svn/lldb/gtest/unittest/Utility/UriParserTest.cpp @@ -127,3 +127,9 @@ VALIDATE } +TEST_F (UriParserTest, PortOverflow) +{ + const UriTestCase testCase("x://y:0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789/"); + VALIDATE +} + Index: /Users/vharron/ll/svn/lldb/source/Utility/UriParser.cpp =================================================================== --- /Users/vharron/ll/svn/lldb/source/Utility/UriParser.cpp +++ /Users/vharron/ll/svn/lldb/source/Utility/UriParser.cpp @@ -33,14 +33,14 @@ char path_buf[2049] = {'/', 0}; bool ok = false; - if (4==sscanf(uri, "%99[^:/]://%255[^/:]:%[^/]/%2047s", scheme_buf, hostname_buf, port_buf, path_buf+1)) { ok = true; } - else if (3==sscanf(uri, "%99[^:/]://%255[^/:]:%[^/]", scheme_buf, hostname_buf, port_buf)) { ok = true; } + if (4==sscanf(uri, "%99[^:/]://%255[^/:]:%10[^/]/%2047s", scheme_buf, hostname_buf, port_buf, path_buf+1)) { ok = true; } + else if (3==sscanf(uri, "%99[^:/]://%255[^/:]:%10[^/]", scheme_buf, hostname_buf, port_buf)) { ok = true; } else if (3==sscanf(uri, "%99[^:/]://%255[^/]/%2047s", scheme_buf, hostname_buf, path_buf+1)) { ok = true; } else if (2==sscanf(uri, "%99[^:/]://%255[^/]", scheme_buf, hostname_buf)) { ok = true; } - char* end = port_buf; + char* end = nullptr; int port_tmp = strtoul(port_buf, &end, 10); - if (*end != 0) + if (*end != 0 || port_tmp > 65535) { // there are invalid characters in port_buf return false;