From 5d4c6f1425890d9a7cc39cee7c111f917b5c0c2f Mon Sep 17 00:00:00 2001 From: David Given Date: Fri, 16 Dec 2016 22:12:28 +0100 Subject: [PATCH] Fix crash when enumerating uninitialised hashtables. --- modules/src/data/hashtable.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/modules/src/data/hashtable.c b/modules/src/data/hashtable.c index 7c895b5a7..d4dba61db 100644 --- a/modules/src/data/hashtable.c +++ b/modules/src/data/hashtable.c @@ -163,15 +163,12 @@ void* hashtable_pop(struct hashtable* ht) void* hashtable_next(struct hashtable* ht, struct hashtable_iterator* it) { + lazy_init(ht); + while (!it->node) { if (it->bucket == ht->num_buckets) - { - it->key = it->value = NULL; - it->bucket = 0; - it->node = NULL; - return NULL; - } + goto eof; it->node = ht->buckets[it->bucket]; if (it->node) @@ -187,4 +184,10 @@ void* hashtable_next(struct hashtable* ht, struct hashtable_iterator* it) it->bucket++; return it->value; + +eof: + it->key = it->value = NULL; + it->bucket = 0; + it->node = NULL; + return NULL; } -- 2.34.1