[PATCH] String copy limiting fixes
authorJens Axboe <jens.axboe@oracle.com>
Thu, 2 Nov 2006 08:18:36 +0000 (09:18 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Thu, 2 Nov 2006 08:18:36 +0000 (09:18 +0100)
Avoid overflows when we can.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
ioengines.c
parse.c
stat.c

index 6a5073cf87ce06f1f851fed9bdf5815c4638f7cc..96a96360750038ea87909c8fdfd45f36a89c9d13 100644 (file)
@@ -48,7 +48,7 @@ struct ioengine_ops *load_ioengine(struct thread_data *td, const char *name)
        struct ioengine_ops *ops, *ret;
        void *dlhandle;
 
-       strcpy(engine, name);
+       strncpy(engine, name, sizeof(engine) - 1);
 
        /*
         * linux libaio has alias names, so convert to what we want
diff --git a/parse.c b/parse.c
index ae8d0d91e2a0a8bc6748d48bd8c98affe3712a03..9f2ee0d653c7fcdc781caa4eea1a46eee4776074 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -178,7 +178,7 @@ static int handle_option(struct fio_option *o, const char *ptr, void *data)
                char tmp[128];
                char *p1, *p2;
 
-               strcpy(tmp, ptr);
+               strncpy(tmp, ptr, sizeof(tmp) - 1);
 
                p1 = strchr(tmp, '-');
                if (!p1) {
@@ -267,7 +267,7 @@ int parse_option(const char *opt, struct fio_option *options, void *data)
        char *pre, *post;
        char tmp[64];
 
-       strcpy(tmp, opt);
+       strncpy(tmp, opt, sizeof(tmp) - 1);
 
        pre = strchr(tmp, '=');
        if (pre) {
diff --git a/stat.c b/stat.c
index 518d14dd13ad43dbe1dbfe02b6e83aec0a802eda..0ae19b282026782e09a8298f1363d4c448a24bf1 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -189,7 +189,7 @@ void init_disk_util(struct thread_data *td)
 {
        struct fio_file *f;
        struct stat st;
-       char foo[256], tmp[256];
+       char foo[PATH_MAX], tmp[PATH_MAX];
        dev_t dev;
        char *p;
 
@@ -209,7 +209,7 @@ void init_disk_util(struct thread_data *td)
                /*
                 * must be a file, open "." in that path
                 */
-               strcpy(foo, f->file_name);
+               strncpy(foo, f->file_name, PATH_MAX - 1);
                p = dirname(foo);
                if (stat(p, &st)) {
                        perror("disk util stat");
@@ -239,7 +239,7 @@ void init_disk_util(struct thread_data *td)
                        log_err("unknown sysfs layout\n");
                        return;
                }
-               strcpy(tmp, p);
+               strncpy(tmp, p, PATH_MAX - 1);
                sprintf(foo, "%s", tmp);
        }