From: Felix Fietkau Date: Tue, 3 Jun 2014 23:17:46 +0000 (+0200) Subject: cache: fix host length calculation X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fmdnsd.git;a=commitdiff_plain;h=6a432a41b9629b6e70a41308f6d9487acf6f4621 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 --- 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: