From e499aedc141da35cf778116d0abcb9cfcd53470c Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Tue, 11 Nov 2014 20:51:37 -0700 Subject: [PATCH] verify: verify_state_gen_name() should check size Signed-off-by: Jens Axboe --- server.c | 3 ++- verify.c | 2 +- verify.h | 8 +++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/server.c b/server.c index a8d4868f..c4ab906f 100644 --- a/server.c +++ b/server.c @@ -1391,7 +1391,8 @@ int fio_server_get_verify_state(const char *name, int threadnumber, rep->data = NULL; rep->error = 0; - verify_state_gen_name((char *) out.path, name, me, threadnumber); + verify_state_gen_name((char *) out.path, sizeof(out.path), name, me, + threadnumber); tag = (uint64_t) (uintptr_t) rep; fio_net_send_cmd(server_fd, FIO_NET_CMD_SENDFILE, &out, sizeof(out), &tag, NULL); diff --git a/verify.c b/verify.c index a0c2e38a..f05e85df 100644 --- a/verify.c +++ b/verify.c @@ -1375,7 +1375,7 @@ static int open_state_file(const char *name, const char *prefix, int num, else flags = O_RDONLY; - verify_state_gen_name(out, name, prefix, num); + verify_state_gen_name(out, sizeof(out), name, prefix, num); fd = open(out, flags, 0644); if (fd == -1) { diff --git a/verify.h b/verify.h index 3e52f9c1..43de887d 100644 --- a/verify.h +++ b/verify.h @@ -138,10 +138,12 @@ static inline struct thread_io_list *io_list_next(struct thread_io_list *s) return (void *) s + thread_io_list_sz(s); } -static inline void verify_state_gen_name(char *out, const char *name, - const char *prefix, int num) +static inline void verify_state_gen_name(char *out, size_t size, + const char *name, const char *prefix, + int num) { - sprintf(out, "%s-%s-%d-verify.state", prefix, name, num); + snprintf(out, size, "%s-%s-%d-verify.state", prefix, name, num); + out[size - 1] = '\0'; } #endif -- 2.25.1