parse: ensure strings are pre-terminated when using strncpy()
authorJens Axboe <axboe@fb.com>
Thu, 22 Jan 2015 21:51:56 +0000 (14:51 -0700)
committerJens Axboe <axboe@fb.com>
Thu, 22 Jan 2015 21:51:56 +0000 (14:51 -0700)
Signed-off-by: Jens Axboe <axboe@fb.com>
parse.c

diff --git a/parse.c b/parse.c
index e70ed20bda7e64b3727e93cacad71de65148862b..7912212ecda47594bac999e8abbecdacaf81aeb1 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -506,6 +506,7 @@ static int __handle_option(struct fio_option *o, const char *ptr, void *data,
                if (!is_time && o->is_time)
                        is_time = o->is_time;
 
                if (!is_time && o->is_time)
                        is_time = o->is_time;
 
+               tmp[sizeof(tmp) - 1] = '\0';
                strncpy(tmp, ptr, sizeof(tmp) - 1);
                p = strchr(tmp, ',');
                if (p)
                strncpy(tmp, ptr, sizeof(tmp) - 1);
                p = strchr(tmp, ',');
                if (p)
@@ -705,6 +706,7 @@ static int __handle_option(struct fio_option *o, const char *ptr, void *data,
                char tmp[128];
                char *p1, *p2;
 
                char tmp[128];
                char *p1, *p2;
 
+               tmp[sizeof(tmp) - 1] = '\0';
                strncpy(tmp, ptr, sizeof(tmp) - 1);
 
                /* Handle bsrange with separate read,write values: */
                strncpy(tmp, ptr, sizeof(tmp) - 1);
 
                /* Handle bsrange with separate read,write values: */