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.8.0~71 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=221cbdf3d5444fd8981eb2a6d4e9f9829341f573;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/"