summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Röder2023-10-18 16:32:34 +0000
committerFelix Fietkau2023-10-18 16:33:50 +0000
commitc286c51a9bd931d023a55988c0e89574ee6d8ffa (patch)
tree258ecf5bd0971522699238285d901234f892b67f
parent26c97a5a50bf914eb8551685b9c0d4e52d9a168b (diff)
downloadmdnsd-c286c51a9bd931d023a55988c0e89574ee6d8ffa.tar.gz
Fix AVL tree traversal in cache_record_find and cache_host_is_known
The AVL tree traversal in both functions systematically misses the last AVL tree element. This can lead to duplicate cache entries and lookup failures. The fix duplicates the correct AVL tree traversal approach of cache_dump_recursive(). Signed-off-by: Martin Röder <mroeder@metz-connect.com> Signed-off-by: Felix Fietkau <nbd@nbd.name>
-rw-r--r--cache.c14
1 files changed, 4 insertions, 10 deletions
diff --git a/cache.c b/cache.c
index 8c851a3..0ed52d7 100644
--- a/cache.c
+++ b/cache.c
@@ -197,13 +197,10 @@ cache_record_find(char *record, int type, int port, int rdlength, uint8_t *rdata
{
struct cache_record *l = avl_find_element(&records, record, l, avl);
- if (!l)
- return NULL;
-
- while (l && !avl_is_last(&records, &l->avl) && !strcmp(l->record, record)) {
+ while (l && !strcmp(l->record, record)) {
struct cache_record *r = l;
- l = avl_next_element(l, avl);
+ l = !avl_is_last(&records, &l->avl) ? avl_next_element(l, avl) : NULL;
if (r->type != type)
continue;
@@ -233,13 +230,10 @@ cache_host_is_known(char *record)
{
struct cache_record *l = avl_find_element(&records, record, l, avl);
- if (!l)
- return 0;
-
- while (l && !avl_is_last(&records, &l->avl) && !strcmp(l->record, record)) {
+ while (l && !strcmp(l->record, record)) {
struct cache_record *r = l;
- l = avl_next_element(l, avl);
+ l = !avl_is_last(&records, &l->avl) ? avl_next_element(l, avl) : NULL;
if ((r->type != TYPE_A) && (r->type != TYPE_AAAA))
continue;
return 1;