]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Handle cases when buf_size is zero
authorAram Sargsyan <aram@isc.org>
Tue, 22 Aug 2023 12:10:40 +0000 (12:10 +0000)
committerAram Sargsyan <aram@isc.org>
Thu, 24 Aug 2023 11:59:57 +0000 (11:59 +0000)
The isc_dnsstream_assembler_incoming() inline function expects that
when 'buf_size' is zero, then 'buf' must be NULL. The expectation is
not correct, because those values come from the libuv read callback,
and its documentation notes[1] that 'nread' ('buf_size' here) might
be 0, which does not indicate an error or EOF, but is equivalent to
EAGAIN or EWOULDBLOCK under read(2).

Change the isc_dnsstream_assembler_incoming() inline function to
remove the invalid expectation.

[1] https://docs.libuv.org/en/v1.x/stream.html#c.uv_read_cb

lib/isc/include/isc/dnsstream.h

index 1e6a26b08697d7d54fef6a921fdaa1a98a134e32..88e361331a7a9161da096f7bc708ee786a99fee1 100644 (file)
@@ -491,13 +491,9 @@ isc_dnsstream_assembler_incoming(isc_dnsstream_assembler_t *restrict dnsasm,
        REQUIRE(dnsasm != NULL);
        INSIST(!dnsasm->calling_cb);
 
-       if (buf_size == 0) {
-               INSIST(buf == NULL);
-       } else {
+       if (buf != NULL && buf_size > 0) {
                size_t remaining;
 
-               INSIST(buf != NULL);
-
                remaining = isc_buffer_remaininglength(&dnsasm->dnsbuf);
 
                if (remaining == 0) {
@@ -525,7 +521,7 @@ isc_dnsstream_assembler_incoming(isc_dnsstream_assembler_t *restrict dnsasm,
                         * when receiving the next batch of data.
                         */
                        return;
-               } else if (remaining == 1 && buf_size > 0) {
+               } else if (remaining == 1) {
                        /* Mostly the same case as above, but we have incomplete
                         * message length in the buffer and received at least
                         * one byte to complete it.