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
This commit is contained in:
Heikki Linnakangas 2024-07-03 15:58:14 +03:00
parent a06e8f84a1
commit f3412a61f3

View 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;
}