Skip to content

Commit

Permalink
Fix check segment_result range(for node issue #51514) (#581)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenKS12138 authored Jan 21, 2024
1 parent 4814d2f commit 219ac56
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
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
2 changes: 1 addition & 1 deletion src/url_aggregator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ bool url_aggregator::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<TypeParam>("http://1.1.1.256");
ASSERT_FALSE(out);
}

0 comments on commit 219ac56

Please sign in to comment.