From 13a85be93769986e03662e8dae6f8bfdf2971aa9 Mon Sep 17 00:00:00 2001 From: Tomohiro Kusumi Date: Mon, 18 Sep 2017 20:53:50 +0300 Subject: [PATCH] fix strncpy(3) copy length 0 terminate the last byte, and copy at most size-1. (or 0 terminate the last byte after copying upto size bytes) Signed-off-by: Tomohiro Kusumi Signed-off-by: Jens Axboe --- os/windows/posix.c | 3 ++- server.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/os/windows/posix.c b/os/windows/posix.c index 488d0ed2..00f03355 100755 --- a/os/windows/posix.c +++ b/os/windows/posix.c @@ -584,7 +584,8 @@ char *basename(char *path) while (path[i] != '\\' && path[i] != '/' && i >= 0) i--; - strncpy(name, path + i + 1, MAX_PATH); + name[MAX_PATH - 1] = '\0'; + strncpy(name, path + i + 1, MAX_PATH - 1); return name; } diff --git a/server.c b/server.c index 0469cea7..e6ea4cdb 100644 --- a/server.c +++ b/server.c @@ -856,7 +856,7 @@ static int handle_probe_cmd(struct fio_net_cmd *cmd) #ifdef CONFIG_BIG_ENDIAN probe.bigendian = 1; #endif - strncpy((char *) probe.fio_version, fio_version_string, sizeof(probe.fio_version)); + strncpy((char *) probe.fio_version, fio_version_string, sizeof(probe.fio_version) - 1); probe.os = FIO_OS; probe.arch = FIO_ARCH; -- 2.25.1