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.6.3~46 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=0825d4beedb0dbe7bc8abb779c34e80a9a1bc658;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 b87915536..c5a2ca64e 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -5061,7 +5061,10 @@ static void 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/"