]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
hints: change the handling of repeated hints (again)
authorVladimír Čunát <vladimir.cunat@nic.cz>
Thu, 15 Jun 2017 14:33:33 +0000 (16:33 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 14 Jul 2017 10:39:39 +0000 (12:39 +0200)
In reverse (PTR) records, now the last definition wins,
and non-canonical names don't get (shadowed) records.

lib/generic/pack.h
modules/hints/hints.c

index 54c515394b177cfe868f375f14db671180d8a1d2..b42fd18fc143cd46a958e51384d93f5ae306eae2 100644 (file)
@@ -23,6 +23,8 @@
  * backed by an array.
  *
  * @note Maximum object size is 2^16 bytes, see  ::pack_objlen_t
+ * @TODO If some mistake happens somewhere, the access may end up in an infinite loop.
+ *       (equality comparison on pointers)
  *
  * # Example usage:
  *
@@ -113,6 +115,23 @@ static inline uint8_t *pack_obj_next(uint8_t *it)
        return pack_obj_val(it) + pack_obj_len(it);
 }
 
+/** Return pointer to the last packed object. */
+static inline uint8_t *pack_last(pack_t pack)
+{
+       if (pack.len == 0) {
+               return NULL;
+       }
+       uint8_t *it = pack_head(pack);
+       uint8_t *tail = pack_tail(pack);
+       while (true) {
+               uint8_t *next = pack_obj_next(it);
+               if (next == tail) {
+                       return it;
+               }
+               it = next;
+       }
+}
+
 /** Push object to the end of the pack
   * @return 0 on success, negative number on failure
   */
index c83fe656219c0cc4655f3b04adcddc362c3169f6..45cd5e5df144b04ca0472f8b83ba7c8f60dd2995 100644 (file)
@@ -83,7 +83,7 @@ static int satisfy_reverse(struct kr_zonecut *hints, knot_pkt_t *pkt, struct kr_
        knot_rrset_init(&rr, qname, KNOT_RRTYPE_PTR, KNOT_CLASS_IN);
 
        /* Append address records from hints */
-       uint8_t *addr = pack_head(*addr_set);
+       uint8_t *addr = pack_last(*addr_set);
        if (addr != NULL) {
                size_t len = pack_obj_len(addr);
                void *addr_val = pack_obj_val(addr);
@@ -334,8 +334,12 @@ static int load_map(struct hints_data *data, FILE *fp)
                        continue;
                }
                char *name_tok = strtok_r(NULL, " \t\n", &saveptr);
+               bool canonical_name = true;
                while (name_tok != NULL) {
-                       add_reverse_pair(&data->reverse_hints, name_tok, tok);
+                       if (canonical_name) {
+                               add_reverse_pair(&data->reverse_hints, name_tok, tok);
+                               canonical_name = false;
+                       }
                        if (add_pair(&data->hints, name_tok, tok) == 0) {
                                count += 1;
                        }