From: Vladimír Čunát Date: Mon, 29 May 2023 11:59:00 +0000 (+0200) Subject: lib/cache pkt_renew(): fix an edge-case bug X-Git-Tag: v5.7.0~7^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=93169196498c2675936b4e7298c9abed16111cf3;p=thirdparty%2Fknot-resolver.git lib/cache pkt_renew(): fix an edge-case bug 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. --- diff --git a/lib/cache/knot_pkt.c b/lib/cache/knot_pkt.c index 31fa7e9b0..864cb57ca 100644 --- a/lib/cache/knot_pkt.c +++ b/lib/cache/knot_pkt.c @@ -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);