]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lib/cache pkt_renew(): fix an edge-case bug
authorVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 29 May 2023 11:59:00 +0000 (13:59 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 29 May 2023 11:59:00 +0000 (13:59 +0200)
It could happen that this condition didn't get triggered,
but the structures weren't completely clear.  In particular,
the current section could be past KNOT_ANSWER already.
Let's be more conservative here; pkt_recycle() shouldn't be expensive.

I'm not sure why I only ran into this on the new-policy branch,
but it really seems like bug here on master already.

lib/cache/knot_pkt.c

index 31fa7e9b0e08976d4af50e1a3b28fa7d2395ac51..864cb57ca9e32150e082cc3cdbd88be378fe30fb 100644 (file)
@@ -11,8 +11,8 @@
 
 int pkt_renew(knot_pkt_t *pkt, const knot_dname_t *name, uint16_t type)
 {
-       /* Update packet question if needed. */
-       if (!knot_dname_is_equal(knot_pkt_qname(pkt), name)
+       /* Clear the packet if needed. */
+       if (pkt->rrset_count != 0 || !knot_dname_is_equal(knot_pkt_qname(pkt), name)
            || knot_pkt_qtype(pkt) != type || knot_pkt_qclass(pkt) != KNOT_CLASS_IN) {
                int ret = kr_pkt_recycle(pkt);
                if (ret) return kr_error(ret);