]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
ldns_resolver_search_status: ensure returning pkt with LDNS_STATUS_OK 282/head
authorFabian Groffen <grobian@bitzolder.nl>
Sat, 28 Jun 2025 08:34:01 +0000 (10:34 +0200)
committerFabian Groffen <grobian@bitzolder.nl>
Sat, 28 Jun 2025 08:34:01 +0000 (10:34 +0200)
Ensure we return a pkt by returning the final one in case the input is
not an absolute dname and no error occurred getting a response packet.

The return of ldns_resolver_query_status can be LDNS_STATUS_OK, but the
rcode from pkt an error.  In such case, when all search domains are
exhausted and the final query is done on the input dname as is, *pkt is
set freed and set to NULL, while s still is LDNS_STATUS_OK.  As a
result, the function returns with LDNS_STATUS_OK and pkt NULL.

This particular return makes the caller unable to handle the return
sensically, other than guessing there was an error of some sort.  By
returning the last retrieved pkt, the caller is able to get the RCODE
and return a meaningful error (such as SERVFAIL).

Signed-off-by: Fabian Groffen <grobian@bitzolder.nl>
resolver.c

index a426b82c034ee236ca94e8b91698198fa9d8143c..1b1c43bc67654500d9abef69ba2bc90829ee82ec 100644 (file)
@@ -1082,9 +1082,10 @@ ldns_resolver_search_status(ldns_pkt** pkt,
                                                LDNS_RCODE_NOERROR) {
 
                                        return LDNS_STATUS_OK;
+                               } else if (i < ldns_resolver_searchlist_count(r)) {
+                                       ldns_pkt_free(*pkt);
+                                       *pkt = NULL;
                                }
-                               ldns_pkt_free(*pkt);
-                               *pkt = NULL;
                        }
                }
        }