Skip to content

Commit bb2fef7

Browse files
committed
Fix IPv6 diff boundary bug and update test harnesses
- Fix ipset6_diff.c: always refresh lo1/hi1 and lo2/hi2 from the array after incrementing i1/i2 at the IPV6_ADDR_MAX boundary. The previous conditional refresh (lo1 > hi1) could leave stale values from the prior iteration, producing incorrect diff results for ranges ending at the maximum IPv6 address. - Use memset for addrinfo hints in ipset_dns.c for consistency with the IPv6 DNS resolver (defensive, avoids uninitialized struct fields). - Fix sanitizer test 05 and unit test harnesses: add ipset_dns.c to the compilation and define active_family/ipv6_dropped_in_ipv4_mode globals required after the DNS extraction and IPv6 additions.
1 parent 53a838d commit bb2fef7

File tree

10 files changed

+19
-4
lines changed

10 files changed

+19
-4
lines changed

run-unit-tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ PROJECT_SOURCES=(
2525
"$ROOT_DIR/src/ipset_common.c"
2626
"$ROOT_DIR/src/ipset_copy.c"
2727
"$ROOT_DIR/src/ipset_diff.c"
28+
"$ROOT_DIR/src/ipset_dns.c"
2829
"$ROOT_DIR/src/ipset_exclude.c"
2930
"$ROOT_DIR/src/ipset_load.c"
3031
"$ROOT_DIR/src/ipset_merge.c"

src/ipset6_diff.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ inline ipset6 *ipset6_diff(ipset6 *ips1, ipset6 *ips2) {
8484
lo2 = ips2->netaddrs[i2].addr;
8585
hi2 = ips2->netaddrs[i2].broadcast;
8686
}
87-
if(i1 < n1 && lo1 > hi1) {
87+
if(i1 < n1) {
8888
lo1 = ips1->netaddrs[i1].addr;
8989
hi1 = ips1->netaddrs[i1].broadcast;
9090
}
@@ -97,7 +97,7 @@ inline ipset6 *ipset6_diff(ipset6 *ips1, ipset6 *ips2) {
9797
lo1 = ips1->netaddrs[i1].addr;
9898
hi1 = ips1->netaddrs[i1].broadcast;
9999
}
100-
if(i2 < n2 && lo2 > hi2) {
100+
if(i2 < n2) {
101101
lo2 = ips2->netaddrs[i2].addr;
102102
hi2 = ips2->netaddrs[i2].broadcast;
103103
}

src/ipset_dns.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,9 @@ static void *dns_thread_resolve(void *ptr)
206206
int r;
207207
struct addrinfo *result, *rp, hints;
208208

209+
memset(&hints, 0, sizeof(hints));
209210
hints.ai_family = AF_INET;
210211
hints.ai_socktype = SOCK_DGRAM;
211-
hints.ai_flags = 0;
212-
hints.ai_protocol = 0;
213212

214213
r = getaddrinfo(d->hostname, "80", &hints, &result);
215214
if(r != 0) {

tests.sanitizers.d/05-dns-thread-create-failure/cmd.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ char *PROG = "dns-create-fail";
1515
int debug;
1616
int cidr_use_network = 1;
1717
int default_prefix = 32;
18+
int active_family = 0;
19+
unsigned long ipv6_dropped_in_ipv4_mode = 0;
1820
1921
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg) {
2022
(void)thread;
@@ -68,6 +70,7 @@ if ! "${CC:-clang}" \
6870
../../src/ipset_common.c \
6971
../../src/ipset_copy.c \
7072
../../src/ipset_diff.c \
73+
../../src/ipset_dns.c \
7174
../../src/ipset_exclude.c \
7275
../../src/ipset_load.c \
7376
../../src/ipset_merge.c \

tests.unit/combine_overflow.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ char *PROG = "combine_overflow";
55
int debug = 0;
66
int cidr_use_network = 1;
77
int default_prefix = 32;
8+
int active_family = 0;
9+
unsigned long ipv6_dropped_in_ipv4_mode = 0;
810

911
int main(void)
1012
{

tests.unit/copy_overflow.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
int cidr_use_network = 1;
44
int default_prefix = 32;
5+
int active_family = 0;
6+
unsigned long ipv6_dropped_in_ipv4_mode = 0;
57
char *PROG = "copy_overflow";
68
int debug = 0;
79

tests.unit/empty_ipset_ops.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ char *PROG = "unit-empty-ipset";
44
int debug;
55
int cidr_use_network = 1;
66
int default_prefix = 32;
7+
int active_family = 0;
8+
unsigned long ipv6_dropped_in_ipv4_mode = 0;
79

810
static ipset *make_single_ipset(const char *name, in_addr_t ip) {
911
ipset *ips = ipset_create(name, 1);

tests.unit/free_all_linked_list.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ char *PROG = "unit-free-all";
44
int debug;
55
int cidr_use_network = 1;
66
int default_prefix = 32;
7+
int active_family = 0;
8+
unsigned long ipv6_dropped_in_ipv4_mode = 0;
79

810
int main(void) {
911
ipset *a = ipset_create("a", 0);

tests.unit/merge_overflow.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ char *PROG = "merge_overflow";
55
int debug = 0;
66
int cidr_use_network = 1;
77
int default_prefix = 32;
8+
int active_family = 0;
9+
unsigned long ipv6_dropped_in_ipv4_mode = 0;
810

911
int main(void)
1012
{

tests.unit/optimize_empty_lsan.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ char *PROG = "unit-optimize-empty";
44
int debug;
55
int cidr_use_network = 1;
66
int default_prefix = 32;
7+
int active_family = 0;
8+
unsigned long ipv6_dropped_in_ipv4_mode = 0;
79

810
int main(void) {
911
ipset *ips = ipset_create("empty", 0);

0 commit comments

Comments
 (0)