From: Vladimír Čunát Date: Thu, 15 Jun 2017 14:33:33 +0000 (+0200) Subject: hints: change the handling of repeated hints (again) X-Git-Tag: v1.3.2~5^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fbe88ccd2;p=thirdparty%2Fknot-resolver.git hints: change the handling of repeated hints (again) In reverse (PTR) records, now the last definition wins, and non-canonical names don't get (shadowed) records. --- diff --git a/lib/generic/pack.h b/lib/generic/pack.h index 54c515394..b42fd18fc 100644 --- a/lib/generic/pack.h +++ b/lib/generic/pack.h @@ -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 */ diff --git a/modules/hints/hints.c b/modules/hints/hints.c index c83fe6562..45cd5e5df 100644 --- a/modules/hints/hints.c +++ b/modules/hints/hints.c @@ -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; }