From: Jens Axboe Date: Tue, 15 Apr 2014 14:18:08 +0000 (-0600) Subject: strcpy: kill last of the suspect ones X-Git-Tag: fio-2.1.9~21 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=3660ceae229f08b4086279be7c82e86926f0304b;p=fio.git strcpy: kill last of the suspect ones Signed-off-by: Jens Axboe --- diff --git a/cconv.c b/cconv.c index 5b9c3be2..ee3b0ca6 100644 --- a/cconv.c +++ b/cconv.c @@ -10,14 +10,17 @@ static void string_to_cpu(char **dst, const uint8_t *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'; } +#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); diff --git a/filesetup.c b/filesetup.c index 490f0fc2..60e79474 100644 --- a/filesetup.c +++ b/filesetup.c @@ -711,8 +711,8 @@ static unsigned long long get_fs_free_counts(struct thread_data *td) 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); diff --git a/init.c b/init.c index 7630978c..84485868 100644 --- a/init.c +++ b/init.c @@ -937,7 +937,7 @@ static struct fpre_keyword { { .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; @@ -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); - 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 { @@ -1012,7 +1014,7 @@ static char *make_filename(char *buf, struct thread_options *o, if (post_start) strncpy(dst, buf + post_start, dst_left); - strcpy(buf, copy); + strncpy(buf, copy, buf_size - 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, 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 fbf0118c..3adb46ea 100644 --- 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; - 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; - strcpy(ts->verror, td->verror); + ts->verror[sizeof(ts->verror) - 1] = '\0'; + strncpy(ts->verror, td->verror, sizeof(ts->verror) - 1); } }