Skip to content

Commit

Permalink
Properly handle incorrect port numbers in parseURL (fixes #4200)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chenna Keshava B S authored and nbougalis committed Jul 11, 2022
1 parent 3172a81 commit d632f9f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/ripple/basics/impl/StringUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
7 changes: 7 additions & 0 deletions src/test/basics/StringUtilities_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,13 @@ class StringUtilities_test : public beast::unit_test::suite
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!/"));
}

{
Expand Down

0 comments on commit d632f9f

Please sign in to comment.