engines: check options before dereference
authorDmitry Monakhov <dmonakhov@gmail.com>
Tue, 7 Apr 2020 17:33:46 +0000 (20:33 +0300)
committerDmitry Monakhov <dmonakhov@gmail.com>
Tue, 7 Apr 2020 17:33:46 +0000 (20:33 +0300)
If FIO_OPT_STR_STORE option not provided it is initialized with NULL value, but
there are many places which assumes that is may be empty string
For example, commands below endup with null pointer dereference
fio  --name=test --ioengine=e4engine --size=1M
fio  --name=test --ioengine=rdma --port=1234 --size=1M

engines/e4defrag.c
engines/rbd.c
engines/rdma.c

index 8f71d02caa947867339d980e0f2722c9a5751b8d..0a0004d0477fc795dd415d417a6c935f4cfb3131 100644 (file)
@@ -72,7 +72,7 @@ static int fio_e4defrag_init(struct thread_data *td)
        struct stat stub;
        char donor_name[PATH_MAX];
 
-       if (!strlen(o->donor_name)) {
+       if (!o->donor_name || !strlen(o->donor_name)) {
                log_err("'donorname' options required\n");
                return 1;
        }
index 7d4d3faf9c5318462fb7c153b7e96a8437e40dc2..a08f47757acdfbe03e18f009d251cb7846272d4d 100644 (file)
@@ -200,6 +200,14 @@ static int _fio_rbd_connect(struct thread_data *td)
                log_err("rados_create failed.\n");
                goto failed_early;
        }
+       if (o->pool_name == NULL) {
+               log_err("rbd pool name must be provided.\n");
+               goto failed_early;
+       }
+       if (!o->rbd_name) {
+               log_err("rbdname must be provided.\n");
+               goto failed_early;
+       }
 
        r = rados_conf_read_file(rbd->cluster, NULL);
        if (r < 0) {
index 2569a8e32e6a0d34f61fb3c9a46e13be56dfcf27..43d8fa6aa7a28b577d70b913b788deeb731b593b 100644 (file)
@@ -1050,7 +1050,7 @@ static int fio_rdmaio_setup_connect(struct thread_data *td, const char *host,
                return err;
 
        /* resolve route */
-       if (strcmp(o->bindname, "") != 0) {
+       if (o->bindname && strlen(o->bindname)) {
                addrb.ss_family = AF_INET;
                err = aton(td, o->bindname, (struct sockaddr_in *)&addrb);
                if (err)
@@ -1116,7 +1116,7 @@ static int fio_rdmaio_setup_listen(struct thread_data *td, short port)
        rd->addr.sin_family = AF_INET;
        rd->addr.sin_port = htons(port);
 
-       if (strcmp(o->bindname, "") == 0)
+       if (!o->bindname || !strlen(o->bindname))
                rd->addr.sin_addr.s_addr = htonl(INADDR_ANY);
        else
                rd->addr.sin_addr.s_addr = htonl(*o->bindname);