]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[dns] Add redundant explicit check for CNAME validity master 1813/head
authorMichael Brown <mcb30@ipxe.org>
Mon, 10 Aug 2026 13:28:15 +0000 (14:28 +0100)
committerMichael Brown <mcb30@ipxe.org>
Mon, 10 Aug 2026 13:41:10 +0000 (14:41 +0100)
Passing the invalid length returned from a failed call to dns_copy()
in to dns_question() will cause the latter to fail safely, but via a
path that is not obviously safe at first glance.

Check the return value from dns_copy() at the point of use, to reduce
future review noise.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/net/udp/dns.c

index 5891611140ad076dd37c732c3bccab9335e80d92..aaf72bd71792c34864ebd858f419ab884af9e160 100644 (file)
@@ -678,7 +678,7 @@ static int dns_xfer_deliver ( struct dns_request *dns,
        size_t answer_offset;
        size_t next_offset;
        size_t rdlength;
-       size_t name_len;
+       int name_len;
        int rc;
 
        /* Sanity check */
@@ -816,6 +816,11 @@ static int dns_xfer_deliver ( struct dns_request *dns,
                               dns, dns_name ( &buf ) );
                        dns->search.offset = dns->search.len;
                        name_len = dns_copy ( &buf, &dns->name );
+                       if ( name_len < 0 ) {
+                               rc = name_len;
+                               dns_done ( dns, rc );
+                               goto done;
+                       }
                        dns->offset = ( offsetof ( typeof ( dns->buf ), name ) +
                                        name_len - 1 /* Strip root label */ );
                        if ( ( rc = dns_question ( dns ) ) != 0 ) {