From 7ccfb103920258dc8eee6d424b300bf8b702032e Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Wed, 3 Oct 2007 19:11:50 +0000 Subject: [PATCH] fixup nasty cache overwriting bug. git-svn-id: file:///svn/unbound/trunk@656 be551aaa-1e26-0410-a405-d3ace91eadb9 --- doc/Changelog | 2 ++ services/cache/rrset.c | 3 +++ util/data/msgreply.c | 6 +++--- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/doc/Changelog b/doc/Changelog index 138fc0f19..739b61202 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -7,6 +7,8 @@ number with parse errors. - unit test for multiple ENT case. - fix for cname out of validated unsec zone. + - fixup nasty id=0 reuse. Also added assertions to detect its + return (the assertion catches in the existing test cases). 1 October 2007: Wouter - skip F77, CXX, objC tests in configure step. diff --git a/services/cache/rrset.c b/services/cache/rrset.c index 628a9e631..431a660b9 100644 --- a/services/cache/rrset.c +++ b/services/cache/rrset.c @@ -177,6 +177,7 @@ rrset_cache_update(struct rrset_cache* r, struct rrset_ref* ref, hashvalue_t h = k->entry.hash; uint16_t rrset_type = ntohs(k->rk.type); int equal = 0; + log_assert(ref->id != 0 && k->id != 0); /* looks up item with a readlock - no editing! */ if((e=slabhash_lookup(&r->table, h, k, 0)) != 0) { /* return id and key as they will be used in the cache @@ -206,6 +207,7 @@ rrset_cache_update(struct rrset_cache* r, struct rrset_ref* ref, /* use insert to update entry to manage lruhash * cache size values nicely. */ } + log_assert(ref->key->id != 0); slabhash_insert(&r->table, h, &k->entry, k->entry.data, alloc); if(e) { /* For NSEC, NSEC3, DNAME, when rdata is updated, update @@ -261,6 +263,7 @@ rrset_array_lock(struct rrset_ref* ref, size_t count, uint32_t timenow) if(i>0 && ref[i].key == ref[i-1].key) continue; /* only lock items once */ lock_rw_rdlock(&ref[i].key->entry.lock); + log_assert(ref[i].id != 0 && ref[i].key->id != 0); if(ref[i].id != ref[i].key->id || timenow > ((struct packed_rrset_data*)(ref[i].key->entry.data)) ->ttl) { diff --git a/util/data/msgreply.c b/util/data/msgreply.c index ef72d5fd9..91f9256af 100644 --- a/util/data/msgreply.c +++ b/util/data/msgreply.c @@ -596,13 +596,13 @@ repinfo_copy_rrsets(struct reply_info* dest, struct reply_info* from, fk = from->rrsets[i]; dk = dest->rrsets[i]; fd = (struct packed_rrset_data*)fk->entry.data; - dk->id = fk->id; dk->entry.hash = fk->entry.hash; dk->rk = fk->rk; - if(region) + if(region) { + dk->id = fk->id; dk->rk.dname = (uint8_t*)region_alloc_init(region, fk->rk.dname, fk->rk.dname_len); - else + } else dk->rk.dname = (uint8_t*)memdup(fk->rk.dname, fk->rk.dname_len); if(!dk->rk.dname) -- 2.47.2