From: Aram Sargsyan Date: Tue, 22 Aug 2023 12:10:40 +0000 (+0000) Subject: Handle cases when buf_size is zero X-Git-Tag: v9.19.17~31^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9a271371d32b7c0ff769cd9310af8beab471a3c9;p=thirdparty%2Fbind9.git Handle cases when buf_size is zero 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 --- diff --git a/lib/isc/include/isc/dnsstream.h b/lib/isc/include/isc/dnsstream.h index 1e6a26b0869..88e361331a7 100644 --- a/lib/isc/include/isc/dnsstream.h +++ b/lib/isc/include/isc/dnsstream.h @@ -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.