]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Preserve the contents of socket buffer on realloc
authorOndřej Surý <ondrej@isc.org>
Wed, 22 Sep 2021 16:55:02 +0000 (18:55 +0200)
committerOndřej Surý <ondrej@isc.org>
Thu, 23 Sep 2021 20:36:01 +0000 (22:36 +0200)
On TCPDNS/TLSDNS read callback, the socket buffer could be reallocated
if the received contents would be larger than the buffer.  The existing
code would not preserve the contents of the existing buffer which lead
to the loss of the already received data.

This commit changes the isc_mem_put()+isc_mem_get() with isc_mem_reget()
to preserve the existing contents of the socket buffer.

lib/isc/netmgr/netmgr.c

index 5b1ff7cdb85b8f9067118c91b794873c90700cbf..a74047d763d8262c5076cf4843a0d86794f8609d 100644 (file)
@@ -1894,8 +1894,8 @@ isc__nm_alloc_dnsbuf(isc_nmsocket_t *sock, size_t len) {
                sock->buf_size = alloc_len;
        } else {
                /* We have the buffer but it's too small */
-               isc_mem_put(sock->mgr->mctx, sock->buf, sock->buf_size);
-               sock->buf = isc_mem_get(sock->mgr->mctx, NM_BIG_BUF);
+               sock->buf = isc_mem_reget(sock->mgr->mctx, sock->buf,
+                                         sock->buf_size, NM_BIG_BUF);
                sock->buf_size = NM_BIG_BUF;
        }
 }