strcpy: kill last of the suspect ones
authorJens Axboe <axboe@fb.com>
Tue, 15 Apr 2014 14:18:08 +0000 (08:18 -0600)
committerJens Axboe <axboe@fb.com>
Tue, 15 Apr 2014 14:18:08 +0000 (08:18 -0600)
Signed-off-by: Jens Axboe <axboe@fb.com>
cconv.c
filesetup.c
init.c
stat.c

diff --git a/cconv.c b/cconv.c
index 5b9c3be2590c79b3b6ec50f664c3ed49bec3d88a..ee3b0ca673a51d9790f6bbdab8ed545f72027906 100644 (file)
--- a/cconv.c
+++ b/cconv.c
@@ -10,14 +10,17 @@ static void string_to_cpu(char **dst, const uint8_t *src)
                *dst = strdup(__src);
 }
 
                *dst = strdup(__src);
 }
 
-static void string_to_net(uint8_t *dst, const char *src)
+static void __string_to_net(uint8_t *dst, const char *src, size_t dst_size)
 {
 {
-       if (src)
-               strcpy((char *) dst, src);
-       else
+       if (src) {
+               dst[dst_size - 1] = '\0';
+               strncpy((char *) dst, src, dst_size - 1);
+       } else
                dst[0] = '\0';
 }
 
                dst[0] = '\0';
 }
 
+#define string_to_net(dst, src)        __string_to_net((dst), (src), sizeof(dst))
+
 static void free_thread_options_to_cpu(struct thread_options *o)
 {
        free(o->description);
 static void free_thread_options_to_cpu(struct thread_options *o)
 {
        free(o->description);
index 490f0fc2101bc912e6f27ab55b93640471031430..60e79474d2cba91b465c4aca3c34749096c2fbce 100644 (file)
@@ -711,8 +711,8 @@ static unsigned long long get_fs_free_counts(struct thread_data *td)
                if (fm)
                        continue;
 
                if (fm)
                        continue;
 
-               fm = malloc(sizeof(*fm));
-               strcpy(fm->__base, buf);
+               fm = calloc(1, sizeof(*fm));
+               strncpy(fm->__base, buf, sizeof(fm->__base) - 1);
                fm->base = basename(fm->__base);
                fm->key = sb.st_dev;
                flist_add(&fm->list, &list);
                fm->base = basename(fm->__base);
                fm->key = sb.st_dev;
                flist_add(&fm->list, &list);
diff --git a/init.c b/init.c
index 7630978cc3ca805839dbbf280f8681b83925295d..8448586847c8db10a74143610a1c233d92b72278 100644 (file)
--- a/init.c
+++ b/init.c
@@ -937,7 +937,7 @@ static struct fpre_keyword {
        { .keyword = NULL, },
        };
 
        { .keyword = NULL, },
        };
 
-static char *make_filename(char *buf, struct thread_options *o,
+static char *make_filename(char *buf, size_t buf_size,struct thread_options *o,
                           const char *jobname, int jobnum, int filenum)
 {
        struct fpre_keyword *f;
                           const char *jobname, int jobnum, int filenum)
 {
        struct fpre_keyword *f;
@@ -952,7 +952,9 @@ static char *make_filename(char *buf, struct thread_options *o,
        for (f = &fpre_keywords[0]; f->keyword; f++)
                f->strlen = strlen(f->keyword);
 
        for (f = &fpre_keywords[0]; f->keyword; f++)
                f->strlen = strlen(f->keyword);
 
-       strcpy(buf, o->filename_format);
+       buf[buf_size - 1] = '\0';
+       strncpy(buf, o->filename_format, buf_size - 1);
+
        memset(copy, 0, sizeof(copy));
        for (f = &fpre_keywords[0]; f->keyword; f++) {
                do {
        memset(copy, 0, sizeof(copy));
        for (f = &fpre_keywords[0]; f->keyword; f++) {
                do {
@@ -1012,7 +1014,7 @@ static char *make_filename(char *buf, struct thread_options *o,
                        if (post_start)
                                strncpy(dst, buf + post_start, dst_left);
 
                        if (post_start)
                                strncpy(dst, buf + post_start, dst_left);
 
-                       strcpy(buf, copy);
+                       strncpy(buf, copy, buf_size - 1);
                } while (1);
        }
 
                } while (1);
        }
 
@@ -1072,7 +1074,7 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num,
                        add_file(td, jobname, job_add_num, 0);
                else {
                        for (i = 0; i < o->nr_files; i++)
                        add_file(td, jobname, job_add_num, 0);
                else {
                        for (i = 0; i < o->nr_files; i++)
-                               add_file(td, make_filename(fname, o, jobname, job_add_num, i), job_add_num, 0);
+                               add_file(td, make_filename(fname, sizeof(fname), o, jobname, job_add_num, i), job_add_num, 0);
                }
        }
 
                }
        }
 
diff --git a/stat.c b/stat.c
index fbf0118c6d7ae1a4a895dc450cf808be7db4041c..3adb46eab8087cc53ae0fd2b7c15ad048596c040 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -1272,10 +1272,12 @@ static void __show_run_stats(void)
                        if (!td->error && td->o.continue_on_error &&
                            td->first_error) {
                                ts->error = td->first_error;
                        if (!td->error && td->o.continue_on_error &&
                            td->first_error) {
                                ts->error = td->first_error;
-                               strcpy(ts->verror, td->verror);
+                               ts->verror[sizeof(ts->verror) - 1] = '\0';
+                               strncpy(ts->verror, td->verror, sizeof(ts->verror) - 1);
                        } else  if (td->error) {
                                ts->error = td->error;
                        } else  if (td->error) {
                                ts->error = td->error;
-                               strcpy(ts->verror, td->verror);
+                               ts->verror[sizeof(ts->verror) - 1] = '\0';
+                               strncpy(ts->verror, td->verror, sizeof(ts->verror) - 1);
                        }
                }
 
                        }
                }