Skip to content

Commit

Permalink
fix: check segment result range(for node issue #51514)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenKS12138 committed Jan 21, 2024
1 parent 4814d2f commit 54b6cb9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/url.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ bool url::parse_ipv4(std::string_view input) {
// We have the last value.
// At this stage, ipv4 contains digit_count*8 bits.
// So we have 32-digit_count*8 bits left.
if (segment_result > (uint64_t(1) << (32 - digit_count * 8))) {
if (segment_result >= (uint64_t(1) << (32 - digit_count * 8))) {
return is_valid = false;
}
ipv4 <<= (32 - digit_count * 8);
Expand Down
6 changes: 6 additions & 0 deletions tests/basic_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,9 @@ TYPED_TEST(basic_tests, nodejs_50235) {
ASSERT_EQ(out->get_href(), "http://test.com:5/path?param=1");
SUCCEED();
}

// https://github.com/nodejs/node/issues/51514
TYPED_TEST(basic_tests, nodejs_51514) {
auto out = ada::parse<ada::url>("http://1.1.1.256");
ASSERT_FALSE(out);
}

0 comments on commit 54b6cb9

Please sign in to comment.