mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
AK: Check for overflow parsing IPv4 number in URL
Fixes OSS fuzz issue: https://oss-fuzz.com/download?testcase_id=6045676088459264
This commit is contained in:
parent
453dd0cf44
commit
3748f1d290
Notes:
sideshowbarker
2024-07-17 05:02:35 +09:00
Author: https://github.com/shannonbooth Commit: https://github.com/SerenityOS/serenity/commit/3748f1d290 Pull-request: https://github.com/SerenityOS/serenity/pull/21119 Reviewed-by: https://github.com/kemzeb
2 changed files with 15 additions and 5 deletions
|
@ -120,18 +120,22 @@ static Optional<ParsedIPv4Number> parse_ipv4_number(StringView input)
|
|||
}
|
||||
|
||||
// 8. Let output be the mathematical integer value that is represented by input in radix-R notation, using ASCII hex digits for digits with values 0 through 15.
|
||||
u32 output;
|
||||
Optional<u32> maybe_output;
|
||||
if (radix == 8)
|
||||
output = StringUtils::convert_to_uint_from_octal(input).release_value();
|
||||
maybe_output = StringUtils::convert_to_uint_from_octal(input);
|
||||
else if (radix == 10)
|
||||
output = input.to_uint().release_value();
|
||||
maybe_output = input.to_uint();
|
||||
else if (radix == 16)
|
||||
output = StringUtils::convert_to_uint_from_hex(input).release_value();
|
||||
maybe_output = StringUtils::convert_to_uint_from_hex(input);
|
||||
else
|
||||
VERIFY_NOT_REACHED();
|
||||
|
||||
// NOTE: Parsing may have failed due to overflow.
|
||||
if (!maybe_output.has_value())
|
||||
return {};
|
||||
|
||||
// 9. Return (output, validationError).
|
||||
return ParsedIPv4Number { output, validation_error };
|
||||
return ParsedIPv4Number { maybe_output.value(), validation_error };
|
||||
}
|
||||
|
||||
// https://url.spec.whatwg.org/#concept-ipv4-parser
|
||||
|
|
|
@ -535,4 +535,10 @@ TEST_CASE(ipv4_address)
|
|||
EXPECT(url.is_valid());
|
||||
EXPECT_EQ(MUST(url.serialized_host()), "52.251.94.56"sv);
|
||||
}
|
||||
|
||||
{
|
||||
constexpr auto ipv4_url = "http://9111111111"sv;
|
||||
URL url(ipv4_url);
|
||||
EXPECT(!url.is_valid());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue