summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ot_accesslist.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/ot_accesslist.c b/ot_accesslist.c
index cdb964d..12bd29e 100644
--- a/ot_accesslist.c
+++ b/ot_accesslist.c
@@ -35,7 +35,7 @@ static int vector_compare_hash(const void *hash1, const void *hash2 ) {
35 35
36/* Read initial access list */ 36/* Read initial access list */
37static void accesslist_readfile( void ) { 37static void accesslist_readfile( void ) {
38 ot_hash *info_hash, *accesslist_new = NULL; 38 ot_hash *info_hash, *accesslist_new = NULL, *accesslist_old;
39 char *map, *map_end, *read_offs; 39 char *map, *map_end, *read_offs;
40 size_t maplen; 40 size_t maplen;
41 41
@@ -90,19 +90,19 @@ static void accesslist_readfile( void ) {
90 90
91 /* Now exchange the accesslist vector in the least race condition prone way */ 91 /* Now exchange the accesslist vector in the least race condition prone way */
92 pthread_mutex_lock(&g_accesslist_mutex); 92 pthread_mutex_lock(&g_accesslist_mutex);
93 free( g_accesslist ); 93
94 g_accesslist = accesslist_new; 94 accesslist_old = g_accesslist; /* Keep a copy for later free */
95 g_accesslist_size = info_hash - accesslist_new; 95 g_accesslist_size = 0; /* Set size to 0 to prevent clients from searching through uninitialised memory */
96 g_accesslist = accesslist_new; /* Only now set a new list */
97 g_accesslist_size = info_hash - accesslist_new; /* And finally store it's size */
98 free(g_accesslist_old); /* If new list is active, the old one can be destroyed */
96 pthread_mutex_unlock(&g_accesslist_mutex); 99 pthread_mutex_unlock(&g_accesslist_mutex);
97} 100}
98 101
99int accesslist_hashisvalid( ot_hash hash ) { 102int accesslist_hashisvalid( ot_hash hash ) {
100 void *exactmatch; 103 void *exactmatch;
101 104
102 /* Lock should hardly ever be contended */
103 pthread_mutex_lock(&g_accesslist_mutex);
104 exactmatch = bsearch( hash, g_accesslist, g_accesslist_size, OT_HASH_COMPARE_SIZE, vector_compare_hash ); 105 exactmatch = bsearch( hash, g_accesslist, g_accesslist_size, OT_HASH_COMPARE_SIZE, vector_compare_hash );
105 pthread_mutex_unlock(&g_accesslist_mutex);
106 106
107#ifdef WANT_ACCESSLIST_BLACK 107#ifdef WANT_ACCESSLIST_BLACK
108 return exactmatch == NULL; 108 return exactmatch == NULL;