[PATCH] String copy limiting fixes
Avoid overflows when we can.
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
diff --git a/ioengines.c b/ioengines.c
index 6a5073c..96a9636 100644
--- a/ioengines.c
+++ b/ioengines.c
@@ -48,7 +48,7 @@
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 ae8d0d9..9f2ee0d 100644
--- a/parse.c
+++ b/parse.c
@@ -178,7 +178,7 @@
char tmp[128];
char *p1, *p2;
- strcpy(tmp, ptr);
+ strncpy(tmp, ptr, sizeof(tmp) - 1);
p1 = strchr(tmp, '-');
if (!p1) {
@@ -267,7 +267,7 @@
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 518d14d..0ae19b2 100644
--- a/stat.c
+++ b/stat.c
@@ -189,7 +189,7 @@
{
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 @@
/*
* 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 @@
log_err("unknown sysfs layout\n");
return;
}
- strcpy(tmp, p);
+ strncpy(tmp, p, PATH_MAX - 1);
sprintf(foo, "%s", tmp);
}