From 096b280b1c5a19f2a613682f421543d665ed6c4c Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Tue, 3 Jan 2023 14:28:11 +1100 Subject: [PATCH] Do not pass NULL pointer to memmove - undefined behaviour Check if 'old_base' is NULL and if so skip calling memmove. --- lib/isc/include/isc/buffer.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/isc/include/isc/buffer.h b/lib/isc/include/isc/buffer.h index d9cec44c6b..4e73c9c7c5 100644 --- a/lib/isc/include/isc/buffer.h +++ b/lib/isc/include/isc/buffer.h @@ -1150,7 +1150,9 @@ isc_buffer_reserve(isc_buffer_t *restrict dbuf, const unsigned int size) { if (!dbuf->dynamic) { void *old_base = dbuf->base; dbuf->base = isc_mem_get(dbuf->mctx, len); - memmove(dbuf->base, old_base, dbuf->used); + if (old_base != NULL) { + memmove(dbuf->base, old_base, dbuf->used); + } dbuf->dynamic = true; } else { dbuf->base = isc_mem_reget(dbuf->mctx, dbuf->base, dbuf->length,