Add check for OPT_LEN_MAX being too small
authorJens Axboe <jens.axboe@oracle.com>
Wed, 3 Mar 2010 08:23:20 +0000 (09:23 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Wed, 3 Mar 2010 08:23:20 +0000 (09:23 +0100)
Will hopefully catch a bug like this in the future.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
parse.c

diff --git a/parse.c b/parse.c
index a55e52b02e513bc0c02603e4c1eb801f435029a9..d44d13082c91dd8951cbe0be7edf2c51dd73d7e0 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -620,6 +620,11 @@ static char *option_dup_subs(const char *opt)
        ssize_t nchr = OPT_LEN_MAX;
        size_t envlen;
 
+       if (strlen(in) + 1 > OPT_LEN_MAX) {
+               fprintf(stderr, "OPT_LEN_MAX (%d) is too small\n", OPT_LEN_MAX);
+               return NULL;
+       }
+
        in[OPT_LEN_MAX] = '\0';
        strncpy(in, opt, OPT_LEN_MAX);
 
@@ -659,6 +664,8 @@ int parse_option(const char *opt, struct fio_option *options, void *data)
        char *post, *tmp;
 
        tmp = option_dup_subs(opt);
+       if (!tmp)
+               return 1;
 
        o = get_option(tmp, options, &post);
        if (!o) {