From b8d767059daccc468ee4afcb671074e1a249782d Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 16 May 2016 21:42:52 -0400 Subject: [PATCH] Fix: illegal memory access in write_pidfile MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Found by Coverity: CID 1243023 (#1 of 1): Buffer not null terminated (BUFFER_SIZE_WARNING)3. buffer_size_warning: Calling strncpy with a maximum size argument of 4096 bytes on destination array pidfile_path of size 4096 bytes might leave the destination string unterminated. Signed-off-by: Mathieu Desnoyers Signed-off-by: Jérémie Galarneau --- src/bin/lttng-sessiond/main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index d94dbd790..6081fb2b0 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -5443,7 +5443,10 @@ static int write_pidfile(void) assert(rundir); if (opt_pidfile) { - strncpy(pidfile_path, opt_pidfile, sizeof(pidfile_path)); + if (lttng_strncpy(pidfile_path, opt_pidfile, sizeof(pidfile_path))) { + ret = -1; + goto error; + } } else { /* Build pidfile path from rundir and opt_pidfile. */ ret = snprintf(pidfile_path, sizeof(pidfile_path), "%s/" -- 2.34.1