From 6a432a41b9629b6e70a41308f6d9487acf6f4621 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Wed, 4 Jun 2014 01:17:46 +0200 Subject: [PATCH 1/1] cache: fix host length calculation The previous version was returning negative values for some records due to unchecked name matching Signed-off-by: Felix Fietkau --- cache.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/cache.c b/cache.c index b5653dd..be26fb6 100644 --- a/cache.c +++ b/cache.c @@ -248,6 +248,7 @@ cache_answer(struct uloop_fd *u, uint8_t *base, int blen, char *name, struct dns char *p = NULL; char *name_buf; void *rdata_ptr, *txt_ptr; + int host_len = 0; if (!(a->class & CLASS_IN)) return; @@ -268,15 +269,11 @@ cache_answer(struct uloop_fd *u, uint8_t *base, int blen, char *name, struct dns rdlength = strlen(rdata_buffer); - if (!strcmp(C_DNS_SD, name)) { - cache_entry(u, rdata_buffer, 0, a->ttl); - return; - } - - if ((rdlength < nlen) && (rdlength - nlen - 1 > 0)) - return; + if (strcmp(C_DNS_SD, name) != 0 && + nlen + 1 < rdlength && !strcmp(rdata_buffer + rdlength - nlen, name)) + host_len = rdlength - nlen - 1; - cache_entry(u, rdata_buffer, rdlength - nlen - 1, a->ttl); + cache_entry(u, rdata_buffer, host_len, a->ttl); return; case TYPE_SRV: -- 2.11.0