From 0bbab0e789d4d8438d63327da052d64b45f0596a Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 2 Nov 2006 09:18:36 +0100 Subject: [PATCH] [PATCH] String copy limiting fixes Avoid overflows when we can. Signed-off-by: Jens Axboe --- ioengines.c | 2 +- parse.c | 4 ++-- stat.c | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ioengines.c b/ioengines.c index 6a5073cf..96a96360 100644 --- a/ioengines.c +++ b/ioengines.c @@ -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 ae8d0d91..9f2ee0d6 100644 --- 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 518d14dd..0ae19b28 100644 --- 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); } -- 2.25.1