Avoid 0-length memcpy to NULL with EXEC_BACKEND
authorHeikki Linnakangas <[email protected]>
Wed, 3 Jul 2024 12:58:14 +0000 (15:58 +0300)
committerHeikki Linnakangas <[email protected]>
Wed, 3 Jul 2024 12:58:14 +0000 (15:58 +0300)
memcpy(NULL, src, 0) is forbidden by POSIX, even though every
production version of libc allows it. Let's be tidy.

Per report from Thomas Munro, running UBSan with EXEC_BACKEND.
Backpatch to v17, where this code was added.

Discussion: https://www.postgresql.org/message-id/CA%2BhUKG%2Be-dV7YWBzfBZXsgovgRuX5VmvmOT%[email protected]

src/backend/postmaster/launch_backend.c

index 49e4be4b399b5c56d17b3fddf7f62cd1053c3e89..f9b24b7989913b14183eb05f67a003f7932d3a1c 100644 (file)
@@ -762,7 +762,8 @@ save_backend_variables(BackendParameters *param, ClientSocket *client_sock,
    strlcpy(param->pkglib_path, pkglib_path, MAXPGPATH);
 
    param->startup_data_len = startup_data_len;
-   memcpy(param->startup_data, startup_data, startup_data_len);
+   if (startup_data_len > 0)
+       memcpy(param->startup_data, startup_data, startup_data_len);
 
    return true;
 }