Properly handle incorrect port numbers in parseURL (fixes #4200)

This commit is contained in:
Chenna Keshava B S
2022-06-17 14:33:28 -07:00
committed by Nik Bougalis
parent 3172a816fa
commit d632f9f6c8
2 changed files with 14 additions and 0 deletions

View File

@@ -90,6 +90,13 @@ parseUrl(parsedURL& pUrl, std::string const& strUrl)
if (!port.empty())
{
pUrl.port = beast::lexicalCast<std::uint16_t>(port);
// For inputs larger than 2^32-1 (65535), lexicalCast returns 0.
// parseUrl returns false for such inputs.
if (pUrl.port == 0)
{
return false;
}
}
pUrl.path = smMatch[6];

View File

@@ -289,6 +289,13 @@ public:
BEAST_EXPECT(!parseUrl(pUrl, "nonsense"));
BEAST_EXPECT(!parseUrl(pUrl, "://"));
BEAST_EXPECT(!parseUrl(pUrl, ":///"));
BEAST_EXPECT(
!parseUrl(pUrl, "scheme://user:pass@domain:65536/abc:321"));
BEAST_EXPECT(!parseUrl(pUrl, "UPPER://domain:23498765/"));
BEAST_EXPECT(!parseUrl(pUrl, "UPPER://domain:0/"));
BEAST_EXPECT(!parseUrl(pUrl, "UPPER://domain:+7/"));
BEAST_EXPECT(!parseUrl(pUrl, "UPPER://domain:-7234/"));
BEAST_EXPECT(!parseUrl(pUrl, "UPPER://domain:@#$56!/"));
}
{