From 3fe7413b4dc54fc4190e41b210823707d9f24414 Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Sat, 18 Jun 2016 18:05:01 +0100 Subject: [PATCH] Fix calculation of buffer size for LISTEN_FDS environment variable. (Fortunately, it still gave the correct result in all expected cases). --- src/service.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/service.cc b/src/service.cc index 770f875..b81c323 100644 --- a/src/service.cc +++ b/src/service.cc @@ -682,8 +682,10 @@ bool ServiceRecord::start_ps_process(const std::vector &cmd, bool sigaddset(&sigwait_set, SIGTERM); sigprocmask(SIG_UNBLOCK, &sigwait_set, NULL); - constexpr int bufsz = ((CHAR_BIT * sizeof(pid_t) - 1) / 3 + 2) + 11; - // "LISTEN_PID=" - 11 characters + constexpr int bufsz = ((CHAR_BIT * sizeof(pid_t)) / 3 + 2) + 11; + // "LISTEN_PID=" - 11 characters; the expression above gives a conservative estimate + // on the maxiumum number of bytes required for LISTEN=xxx, including nul terminator, + // where xxx is a pid_t in decimal (i.e. one decimal digit is worth just over 3 bits). char nbuf[bufsz]; if (socket_fd != -1) { -- 2.25.1