Skip to content

Commit b00cba1

Browse files
authored
Merge pull request #21 from dmbaturin/T8374-fix-range-check
T8374: convert addresses to the host byte order before comparison in IPv4 range checks
2 parents 96b9fdc + 563fc7d commit b00cba1

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

src/ipaddrcheck_functions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ int is_ipv4_range(char* range_str, int prefix_length, int verbose)
562562
struct in_addr* left_in_addr = cidr_to_inaddr(left_addr, NULL);
563563
struct in_addr* right_in_addr = cidr_to_inaddr(right_addr, NULL);
564564

565-
if( left_in_addr->s_addr <= right_in_addr->s_addr )
565+
if( ntohl(left_in_addr->s_addr) <= ntohl(right_in_addr->s_addr) )
566566
{
567567
/* If non-zero prefix_length is given,
568568
check if the right address is within the network of the first one. */

tests/check_ipaddrcheck.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ START_TEST (test_is_ipv4_range)
408408
ck_assert_int_eq(is_ipv4_range("192.0.2.0-192.0.2.10", 0, 1), RESULT_SUCCESS);
409409
ck_assert_int_eq(is_ipv4_range("192.0.2.-", 0, 1), RESULT_FAILURE);
410410
ck_assert_int_eq(is_ipv4_range("192.0.2.99-192.0.2.11", 0, 1), RESULT_FAILURE);
411+
ck_assert_int_eq(is_ipv4_range("192.0.2.0-1.8.2.1", 0, 1), RESULT_FAILURE);
411412
}
412413
END_TEST
413414

0 commit comments

Comments
 (0)