From: Tomohiro Kusumi Date: Mon, 18 Sep 2017 17:53:50 +0000 (+0300) Subject: fix strncpy(3) copy length X-Git-Tag: fio-3.1~5 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=13a85be93769986e03662e8dae6f8bfdf2971aa9;hp=ba8b89a1549c5ce7d7544813c9137798de454fac 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 --- 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;