From: Mathieu Desnoyers Date: Tue, 17 May 2016 01:42:52 +0000 (-0400) Subject: Fix: illegal memory access in write_pidfile X-Git-Tag: v2.9.0-rc1~221 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=b8d767059daccc468ee4afcb671074e1a249782d;p=lttng-tools.git Fix: illegal memory access in write_pidfile 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 --- 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/"