Skip to content

Commit 219ac56

Browse files
authored
Fix check segment_result range(for node issue #51514) (#581)
1 parent 4814d2f commit 219ac56

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/url.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ bool url::parse_ipv4(std::string_view input) {
6565
// We have the last value.
6666
// At this stage, ipv4 contains digit_count*8 bits.
6767
// So we have 32-digit_count*8 bits left.
68-
if (segment_result > (uint64_t(1) << (32 - digit_count * 8))) {
68+
if (segment_result >= (uint64_t(1) << (32 - digit_count * 8))) {
6969
return is_valid = false;
7070
}
7171
ipv4 <<= (32 - digit_count * 8);

src/url_aggregator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ bool url_aggregator::parse_ipv4(std::string_view input) {
898898
// We have the last value.
899899
// At this stage, ipv4 contains digit_count*8 bits.
900900
// So we have 32-digit_count*8 bits left.
901-
if (segment_result > (uint64_t(1) << (32 - digit_count * 8))) {
901+
if (segment_result >= (uint64_t(1) << (32 - digit_count * 8))) {
902902
return is_valid = false;
903903
}
904904
ipv4 <<= (32 - digit_count * 8);

tests/basic_tests.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,3 +396,9 @@ TYPED_TEST(basic_tests, nodejs_50235) {
396396
ASSERT_EQ(out->get_href(), "http://test.com:5/path?param=1");
397397
SUCCEED();
398398
}
399+
400+
// https://github.com/nodejs/node/issues/51514
401+
TYPED_TEST(basic_tests, nodejs_51514) {
402+
auto out = ada::parse<TypeParam>("http://1.1.1.256");
403+
ASSERT_FALSE(out);
404+
}

0 commit comments

Comments
 (0)