]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Do not pass NULL pointer to memmove - undefined behaviour
authorMark Andrews <marka@isc.org>
Tue, 3 Jan 2023 03:28:11 +0000 (14:28 +1100)
committerMark Andrews <marka@isc.org>
Tue, 3 Jan 2023 03:40:30 +0000 (14:40 +1100)
Check if 'old_base' is NULL and if so skip calling memmove.

lib/isc/include/isc/buffer.h

index d9cec44c6b0a4e258b776df0046cd69b2083e3fc..4e73c9c7c5771832cd5bb023b029fea85093f515 100644 (file)
@@ -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,