]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
gc: fix kr_gc_key_consistent to work with root zone NSECs
authorPetr Špaček <petr.spacek@nic.cz>
Tue, 25 Jun 2019 10:44:42 +0000 (12:44 +0200)
committerPetr Špaček <petr.spacek@nic.cz>
Wed, 10 Jul 2019 13:59:23 +0000 (15:59 +0200)
utils/cache_gc/db.c

index 40fba149f7a698b0068dc47a10fd526b0c2591f2..606c6733b7c773d51164657843c43ef0970d9217 100644 (file)
@@ -77,11 +77,19 @@ const uint16_t *kr_gc_key_consistent(knot_db_val_t key)
 {
        const static uint16_t NSEC1 = KNOT_RRTYPE_NSEC;
        const static uint16_t NSEC3 = KNOT_RRTYPE_NSEC3;
-       // find the first double zero in the key; CACHE_KEY_DEF
        const uint8_t *kd = key.data;
        ssize_t i;
-       for (i = 2; !(kd[i - 1] == 0 && kd[i - 2] == 0); ++i) {
-               if (i >= key.len) return NULL;
+       /* CACHE_KEY_DEF */
+       if (key.len >= 2 && kd[0] == '\0') {
+                /* Beware: root zone is special and starts with
+                *         a single \0 followed by type sign */
+                i = 1;
+       } else {
+               /* find the first double zero in the key */
+                for (i = 2; !kd[i - 1] == 0 || !kd[i - 2] == 0; ++i) {
+                    if (i >= key.len)
+                           return NULL;
+                }
        }
        // the next character can be used for classification
        switch (kd[i]) {