backend: better NULL termination fix for IO scheduler switching
authorJens Axboe <axboe@fb.com>
Mon, 14 Apr 2014 17:36:01 +0000 (11:36 -0600)
committerJens Axboe <axboe@fb.com>
Mon, 14 Apr 2014 17:36:01 +0000 (11:36 -0600)
Signed-off-by: Jens Axboe <axboe@fb.com>
backend.c

index c1c8f96774850a755681dffa710d0ee1550fe16b..62bca29194ed08a80af9c68afdc1fbda75b164ef 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -1114,13 +1114,14 @@ 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, 1, sizeof(tmp) - 1, f);
+       ret = fread(tmp, sizeof(tmp), 1, f);
        if (ferror(f) || ret < 0) {
                td_verror(td, errno, "fread");
                fclose(f);
                return 1;
        }
+       tmp[sizeof(tmp) - 1] = '\0';
+
 
        sprintf(tmp2, "[%s]", td->o.ioscheduler);
        if (!strstr(tmp, tmp2)) {