]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lib/cache: reflect cache scope change when found answer from wider scope
authorMarek Vavruša <mvavrusa@cloudflare.com>
Fri, 7 Sep 2018 00:38:43 +0000 (17:38 -0700)
committerMarek Vavruša <mvavrusa@cloudflare.com>
Fri, 7 Sep 2018 17:45:21 +0000 (10:45 -0700)
This prevents situation when part of a CNAME chain is cached, but the
cached answers never update the scope length.

lib/cache/peek.c

index 58cca5732e2cc08ace9f64c56c7ab851600b7aed..f92ca50631a14122d1397167ccc75d6577b69424 100644 (file)
@@ -155,7 +155,7 @@ static int cache_key_read_scope(knot_db_val_t key, size_t off, const uint8_t **s
 }
 
 /* Check that one scoped key covers another one (they're not necessarily equal) */
-static int cache_key_match_scope(knot_db_val_t wanted_key, knot_db_val_t found_key, size_t key_length, const kr_cache_scope_t *scope)
+static int cache_key_match_scope(knot_db_val_t wanted_key, knot_db_val_t found_key, size_t key_length, kr_cache_scope_t *scope)
 {
        /* Check that the key part (without the scope) matches to make sure the keys differ only in scope. */
        if (found_key.len == wanted_key.len && memcmp(found_key.data, wanted_key.data, key_length) == 0) {
@@ -169,6 +169,8 @@ static int cache_key_match_scope(knot_db_val_t wanted_key, knot_db_val_t found_k
                if (cache_key_read_scope(found_key, key_length, &found_scope, &found_scope_len) == 0 &&
                        found_scope_len <= scope->scope_len &&
                        kr_bitcmp((const char *)found_scope, (const char *)scope->address, found_scope_len) == 0) {
+                               /* Update cache scope for found entry. */
+                               scope->scope_len = found_scope_len;
                                return kr_ok();
                }
        }