From 0e23d456e00d49b295dd3aeac59539fd9c6d97a7 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Thu, 29 Mar 2018 08:24:23 -0700 Subject: [PATCH] Make it clear to Coverity that the tmp buffer in switch_ioscheduler() is \0-terminated The 'tmp' buffer used by switch_ioscheduler() will be '\0'-terminated because the I/O scheduler name read from sysfs has much fewer characters than the buffer size (256). Make it clear to Coverity that it is guaranteed that the 'tmp' buffer is '\0'-terminated. Additionally, fix the order of the fread() arguments. This patch fixes Coverity ID #24132. Fixes: b44b9e45cf38 ("Clear sysfs path before reading current ioscheduler from sysfs") Signed-off-by: Bart Van Assche --- backend.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend.c b/backend.c index fc83ed17..fe335b5e 100644 --- a/backend.c +++ b/backend.c @@ -1364,13 +1364,13 @@ static int switch_ioscheduler(struct thread_data *td) /* * Read back and check that the selected scheduler is now the default. */ - memset(tmp, 0, sizeof(tmp)); - ret = fread(tmp, sizeof(tmp), 1, f); + ret = fread(tmp, 1, sizeof(tmp) - 1, f); if (ferror(f) || ret < 0) { td_verror(td, errno, "fread"); fclose(f); return 1; } + tmp[ret] = '\0'; /* * either a list of io schedulers or "none\n" is expected. */ -- 2.25.1