From 5d1cf49fb6d586e94aff293bf0c87dae4aaccf06 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 7 Jul 2022 14:16:47 +0530 Subject: [PATCH] Only set control msg metadata when actually sending a control msg --- prewarm-launcher.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/prewarm-launcher.c b/prewarm-launcher.c index 53de62e08..79d9d7e94 100644 --- a/prewarm-launcher.c +++ b/prewarm-launcher.c @@ -294,12 +294,17 @@ create_launch_msg(int argc, char *argv[]) { sio(stdin, STDIN_FILENO); sio(stdout, STDOUT_FILENO); sio(stderr, STDERR_FILENO); #undef sio w("finish", ""); - struct cmsghdr *cmsg = CMSG_FIRSTHDR(&launch_msg_container); - cmsg->cmsg_level = SOL_SOCKET; - cmsg->cmsg_type = SCM_RIGHTS; - cmsg->cmsg_len = CMSG_LEN(sizeof(fds[0]) * num_fds); - memcpy(CMSG_DATA(cmsg), fds, num_fds * sizeof(fds[0])); - launch_msg_container.msg_controllen = cmsg->cmsg_len; + if (num_fds) { + struct cmsghdr *cmsg = CMSG_FIRSTHDR(&launch_msg_container); + cmsg->cmsg_len = CMSG_LEN(sizeof(fds[0]) * num_fds); + memcpy(CMSG_DATA(cmsg), fds, num_fds * sizeof(fds[0])); + launch_msg_container.msg_controllen = cmsg->cmsg_len; + cmsg->cmsg_level = SOL_SOCKET; + cmsg->cmsg_type = SCM_RIGHTS; + } else { + launch_msg_container.msg_controllen = 0; + launch_msg_container.msg_control = 0; + } return true; #undef w }