From 388b3c0bc9b4fe23861c9a0b1e57b38782a541fa Mon Sep 17 00:00:00 2001 From: Aidan Garske Date: Wed, 21 Oct 2026 13:22:30 -0700 Subject: [PATCH 1/3] F-15467 - https://fenrir.wolfssl.com/finding/15467 - Clear new head entry prev pointer in list insert before helper --- src/wolfsentry_ll.h | 4 +++- tests/unittests.c | 56 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/src/wolfsentry_ll.h b/src/wolfsentry_ll.h index 59ec751..29d7752 100644 --- a/src/wolfsentry_ll.h +++ b/src/wolfsentry_ll.h @@ -71,8 +71,10 @@ static inline void wolfsentry_list_ent_insert_before(struct wolfsentry_list_head if (point_ent->prev) { new_ent->prev = point_ent->prev; new_ent->prev->next = new_ent; - } else + } else { + new_ent->prev = NULL; list->head = new_ent; + } point_ent->prev = new_ent; ++list->len; } diff --git a/tests/unittests.c b/tests/unittests.c index 7a75686..7cb0772 100644 --- a/tests/unittests.c +++ b/tests/unittests.c @@ -1391,6 +1391,60 @@ TEST_SKIP(test_rw_locks) #ifdef TEST_STATIC_ROUTES +static wolfsentry_errcode_t test_ll_insert_before_head_links(void) { + struct wolfsentry_list_header list; + struct wolfsentry_list_ent_header a, b, c, d; + struct wolfsentry_list_ent_header *cursor; + wolfsentry_hitcount_t n; + + WOLFSENTRY_LIST_HEADER_RESET(list); + wolfsentry_list_ent_append(&list, &a); + wolfsentry_list_ent_append(&list, &b); + wolfsentry_list_ent_append(&list, &c); + + /* unlink a middle entry and reinsert it before the head, as purge-list + * refresh does; the unlink leaves its old links, so the head insertion + * must clear prev. + */ + wolfsentry_list_ent_delete(&list, &b); + wolfsentry_list_ent_insert_before(&list, list.head, &b); + + if (list.head != &b) + WOLFSENTRY_ERROR_RETURN(UNIT_TEST_FAILURE); + if (list.head->prev != NULL) + WOLFSENTRY_ERROR_RETURN(UNIT_TEST_FAILURE); + if (list.tail->next != NULL) + WOLFSENTRY_ERROR_RETURN(UNIT_TEST_FAILURE); + + wolfsentry_list_ent_insert_before(&list, list.head, &d); + if ((list.head != &d) || (list.head->prev != NULL)) + WOLFSENTRY_ERROR_RETURN(UNIT_TEST_FAILURE); + + n = 0; + for (cursor = list.head; cursor != NULL; cursor = cursor->next) { + ++n; + if (n > list.len) + WOLFSENTRY_ERROR_RETURN(UNIT_TEST_FAILURE); + if ((cursor->next == NULL) && (cursor != list.tail)) + WOLFSENTRY_ERROR_RETURN(UNIT_TEST_FAILURE); + } + if (n != list.len) + WOLFSENTRY_ERROR_RETURN(UNIT_TEST_FAILURE); + + n = 0; + for (cursor = list.tail; cursor != NULL; cursor = cursor->prev) { + ++n; + if (n > list.len) + WOLFSENTRY_ERROR_RETURN(UNIT_TEST_FAILURE); + if ((cursor->prev == NULL) && (cursor != list.head)) + WOLFSENTRY_ERROR_RETURN(UNIT_TEST_FAILURE); + } + if (n != list.len) + WOLFSENTRY_ERROR_RETURN(UNIT_TEST_FAILURE); + + WOLFSENTRY_RETURN_OK; +} + static wolfsentry_errcode_t replace_rule_transactionally( WOLFSENTRY_CONTEXT_ARGS_IN, const char *event_label, @@ -1505,6 +1559,8 @@ static int test_static_routes(void) { WOLFSENTRY_THREAD_HEADER_CHECKED(WOLFSENTRY_THREAD_FLAG_NONE); + WOLFSENTRY_EXIT_ON_FAILURE(test_ll_insert_before_head_links()); + WOLFSENTRY_EXIT_ON_FAILURE( wolfsentry_init_ex( wolfsentry_build_settings, From 208784724bc86aea57be1284aa87b4f3c11a33a8 Mon Sep 17 00:00:00 2001 From: Aidan Garske Date: Wed, 21 Oct 2026 13:27:08 -0700 Subject: [PATCH 2/3] F-15466 - https://fenrir.wolfssl.com/finding/15466 - Set new tail entry next pointer in list insert after helper --- src/wolfsentry_ll.h | 4 +++- tests/unittests.c | 54 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/wolfsentry_ll.h b/src/wolfsentry_ll.h index 29d7752..bc7bb82 100644 --- a/src/wolfsentry_ll.h +++ b/src/wolfsentry_ll.h @@ -91,8 +91,10 @@ static inline void wolfsentry_list_ent_insert_after(struct wolfsentry_list_heade if (point_ent->next) { new_ent->next = point_ent->next; new_ent->next->prev = new_ent; - } else + } else { + new_ent->next = NULL; list->tail = new_ent; + } point_ent->next = new_ent; ++list->len; } diff --git a/tests/unittests.c b/tests/unittests.c index 7cb0772..8326315 100644 --- a/tests/unittests.c +++ b/tests/unittests.c @@ -1509,6 +1509,59 @@ static wolfsentry_errcode_t replace_rule_transactionally( WOLFSENTRY_ERROR_UNLOCK_AND_RERETURN(ret); } +static wolfsentry_errcode_t test_ll_insert_after_tail_links(void) { + struct wolfsentry_list_header list; + struct wolfsentry_list_ent_header a, b, c; + struct wolfsentry_list_ent_header sentinel; + struct wolfsentry_list_ent_header *cursor; + wolfsentry_hitcount_t n; + + WOLFSENTRY_LIST_HEADER_RESET(list); + wolfsentry_list_ent_append(&list, &a); + wolfsentry_list_ent_append(&list, &b); + + /* a freshly allocated entry carries an unrelated non-NULL next, which a + * correct tail insertion must overwrite with NULL. + */ + sentinel.prev = NULL; + sentinel.next = NULL; + c.prev = &sentinel; + c.next = &sentinel; + + wolfsentry_list_ent_insert_after(&list, list.tail, &c); + + if (list.tail != &c) + WOLFSENTRY_ERROR_RETURN(UNIT_TEST_FAILURE); + if (list.tail->next != NULL) + WOLFSENTRY_ERROR_RETURN(UNIT_TEST_FAILURE); + if (list.head->prev != NULL) + WOLFSENTRY_ERROR_RETURN(UNIT_TEST_FAILURE); + + n = 0; + for (cursor = list.head; cursor != NULL; cursor = cursor->next) { + ++n; + if (n > list.len) + WOLFSENTRY_ERROR_RETURN(UNIT_TEST_FAILURE); + if ((cursor->next == NULL) && (cursor != list.tail)) + WOLFSENTRY_ERROR_RETURN(UNIT_TEST_FAILURE); + } + if (n != list.len) + WOLFSENTRY_ERROR_RETURN(UNIT_TEST_FAILURE); + + n = 0; + for (cursor = list.tail; cursor != NULL; cursor = cursor->prev) { + ++n; + if (n > list.len) + WOLFSENTRY_ERROR_RETURN(UNIT_TEST_FAILURE); + if ((cursor->prev == NULL) && (cursor != list.head)) + WOLFSENTRY_ERROR_RETURN(UNIT_TEST_FAILURE); + } + if (n != list.len) + WOLFSENTRY_ERROR_RETURN(UNIT_TEST_FAILURE); + + WOLFSENTRY_RETURN_OK; +} + static int test_static_routes(void) { struct wolfsentry_context *wolfsentry; @@ -1560,6 +1613,7 @@ static int test_static_routes(void) { WOLFSENTRY_THREAD_HEADER_CHECKED(WOLFSENTRY_THREAD_FLAG_NONE); WOLFSENTRY_EXIT_ON_FAILURE(test_ll_insert_before_head_links()); + WOLFSENTRY_EXIT_ON_FAILURE(test_ll_insert_after_tail_links()); WOLFSENTRY_EXIT_ON_FAILURE( wolfsentry_init_ex( From 59ed0c2cd31312fe8d6da6fed62419a6359b4d6d Mon Sep 17 00:00:00 2001 From: Aidan Garske Date: Fri, 23 Oct 2026 13:56:10 -0700 Subject: [PATCH 3/3] F-15467 - https://fenrir.wolfssl.com/finding/15467 - Allow the list tests to call the inline list primitives under -Winline --- tests/unittests.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/unittests.c b/tests/unittests.c index 8326315..750995b 100644 --- a/tests/unittests.c +++ b/tests/unittests.c @@ -33,6 +33,11 @@ #define PRIVATE_DATA_ALIGNMENT 16 #endif +#ifdef __GNUC__ +/* the list tests call the inline list primitives directly from run-once code */ +#pragma GCC diagnostic ignored "-Winline" +#endif + #include "src/wolfsentry_internal.h" #if (defined(_POSIX_C_SOURCE) || defined(__MACH__)) && !defined(FREERTOS)