From 28de4beed5a3ffb8ce5ad6a2543e60c5efb46430 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 10 Jun 2014 00:42:10 +0200 Subject: [PATCH] fix segfault while dumping records Signed-off-by: Felix Fietkau --- cache.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/cache.c b/cache.c index dbd258d..927b9cf 100644 --- a/cache.c +++ b/cache.c @@ -340,15 +340,12 @@ cache_answer(struct interface *iface, uint8_t *base, int blen, char *name, struc void cache_dump_records(struct blob_buf *buf, const char *name) { - struct cache_record *r, *q = avl_find_element(&records, name, r, avl); + struct cache_record *r, *last, *next; const char *txt; char buffer[INET6_ADDRSTRLEN]; - if (!q) - return; - - do { - r = q; + last = avl_last_element(&records, last, avl); + for (r = avl_find_element(&records, name, r, avl); r; r = next) { switch (r->type) { case TYPE_TXT: if (r->txt && strlen(r->txt)) { @@ -375,6 +372,12 @@ cache_dump_records(struct blob_buf *buf, const char *name) blobmsg_add_string(buf, "ipv6", buffer); break; } - q = avl_next_element(r, avl); - } while (q && !strcmp(r->record, q->record)); + + if (r == last) + break; + + next = avl_next_element(r, avl); + if (strcmp(r->record, next->record) != 0) + break; + } } -- 2.11.0