From: Heikki Linnakangas Date: Wed, 3 Jul 2024 12:58:14 +0000 (+0300) Subject: Avoid 0-length memcpy to NULL with EXEC_BACKEND X-Git-Tag: REL_18_BETA1~2484 X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=f3412a61f3f92d795ce0c8bb715831ec02124bfb;p=postgresql.git Avoid 0-length memcpy to NULL with EXEC_BACKEND 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%2Bv0aXiZJ-EKbXcw@mail.gmail.com --- diff --git a/src/backend/postmaster/launch_backend.c b/src/backend/postmaster/launch_backend.c index 49e4be4b399..f9b24b79899 100644 --- a/src/backend/postmaster/launch_backend.c +++ b/src/backend/postmaster/launch_backend.c @@ -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; }