From: Ondřej Surý Date: Wed, 22 Sep 2021 16:55:02 +0000 (+0200) Subject: Preserve the contents of socket buffer on realloc X-Git-Tag: v9.17.19~26^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8248da3b836276b6dd782e597bb45ea7a05d1c26;p=thirdparty%2Fbind9.git Preserve the contents of socket buffer on realloc 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. --- diff --git a/lib/isc/netmgr/netmgr.c b/lib/isc/netmgr/netmgr.c index 5b1ff7cdb85..a74047d763d 100644 --- a/lib/isc/netmgr/netmgr.c +++ b/lib/isc/netmgr/netmgr.c @@ -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; } }