From f9262b8d3bbb9fd4ab65d70bf8185023081f1132 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Tue, 27 Oct 2026 01:14:38 +0100 Subject: Fix some sanitizer findings, mostly UB if no accesslist is configured and thread join problems --- ot_accesslist.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'ot_accesslist.c') diff --git a/ot_accesslist.c b/ot_accesslist.c index 724978e..4bf1701 100644 --- a/ot_accesslist.c +++ b/ot_accesslist.c @@ -160,6 +160,9 @@ static void accesslist_readfile(void) { const char *map; size_t maplen, capacity, found; + if (!g_accesslist_filename) + return; + if (accesslist_map(g_accesslist_filename, &map, &maplen) < 0) { char *wd = getcwd(NULL, 0); fprintf(stderr, "Warning: Can't open accesslist file: %s (but will try to create it later, if necessary and possible).\nPWD: %s\n", g_accesslist_filename, wd); @@ -185,7 +188,8 @@ static void accesslist_readfile(void) { if (map) munmap((void *)map, maplen); - qsort(accesslist_new->list, found, sizeof(ot_hash), vector_compare_hash); + if (found) + qsort(accesslist_new->list, found, sizeof(ot_hash), vector_compare_hash); accesslist_new->size = found; /* Now exchange the accesslist vector in the least race condition prone way */ @@ -223,18 +227,18 @@ int accesslist_hashisvalid(const ot_hash hash) { #endif void *exactmatch = NULL; - if (accesslist) + if (accesslist && accesslist->size) exactmatch = bsearch(hash, accesslist->list, accesslist->size, OT_HASH_COMPARE_SIZE, vector_compare_hash); #ifdef WANT_DYNAMIC_ACCESSLIST /* If we had no match on the main list, scan the list of dynamically added hashes */ accesslist_add = g_accesslist_add; - if ((exactmatch == NULL) && accesslist_add) + if ((exactmatch == NULL) && accesslist_add && accesslist_add->size) exactmatch = bsearch(hash, accesslist_add->list, accesslist_add->size, OT_HASH_COMPARE_SIZE, vector_compare_hash); /* If we found a matching hash on the main list, scan the list of dynamically deleted hashes */ accesslist_delete = g_accesslist_delete; - if ((exactmatch != NULL) && accesslist_delete && bsearch(hash, accesslist_delete->list, accesslist_delete->size, OT_HASH_COMPARE_SIZE, vector_compare_hash)) + if ((exactmatch != NULL) && accesslist_delete && accesslist_delete->size && bsearch(hash, accesslist_delete->list, accesslist_delete->size, OT_HASH_COMPARE_SIZE, vector_compare_hash)) exactmatch = NULL; #endif @@ -384,8 +388,9 @@ void accesslist_init(void) { } void accesslist_deinit(void) { - /* Wake up sleeping worker */ + /* Wake the worker and wait for it to notice that the tracker is stopping. */ pthread_kill(thread_id, SIGHUP); + pthread_join(thread_id, NULL); pthread_mutex_lock(&g_accesslist_mutex); @@ -397,7 +402,6 @@ void accesslist_deinit(void) { #endif pthread_mutex_unlock(&g_accesslist_mutex); - pthread_cancel(thread_id); pthread_mutex_destroy(&g_accesslist_mutex); } -- cgit v1.3