]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Hash: fix buffer overflow in unit test
authorIgor Putovny <igor.putovny@nic.cz>
Wed, 11 Jun 2025 10:00:23 +0000 (12:00 +0200)
committerMaria Matejka <mq@ucw.cz>
Mon, 22 Sep 2025 10:48:37 +0000 (12:48 +0200)
This bug manifested itself as segmentation fault of t_insert2_find test when
TEST_ORDER was increased from 13 to 14. When checking the validity of filled
table, the table is iterated from 0 to MAX_NUM. However, when order is an even
number, the size of the table is lower than MAX_NUM (due to table resizing),
which caused reading beyond the allocated memory.

This bug does not apply to BIRD itself.

lib/hash_test.c

index 33b9ac857aa9265664e213dd7d4d9dc419fa9a25..b384503fe09c5c8d381df3cea9b6b9da90b26a17 100644 (file)
@@ -40,10 +40,9 @@ struct test_node nodes[MAX_NUM];
 static void
 print_rate_of_fulfilment(void)
 {
-  int i;
   int num_stacked_items = 0;
 
-  for (i = 0; i < MAX_NUM; i++)
+  for (size_t i = 0; i < HASH_SIZE(hash); i++)
     if (!hash.data[i])
       num_stacked_items++;