From de8f86759f5e0aed5c65d0e4aaffaf33d27cbd89 Mon Sep 17 00:00:00 2001 From: Dmitry Monakhov Date: Tue, 7 Apr 2020 20:33:46 +0300 Subject: [PATCH] engines: check options before dereference 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 | 2 +- engines/rbd.c | 8 ++++++++ engines/rdma.c | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/engines/e4defrag.c b/engines/e4defrag.c index 8f71d02c..0a0004d0 100644 --- a/engines/e4defrag.c +++ b/engines/e4defrag.c @@ -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; } diff --git a/engines/rbd.c b/engines/rbd.c index 7d4d3faf..a08f4775 100644 --- a/engines/rbd.c +++ b/engines/rbd.c @@ -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) { diff --git a/engines/rdma.c b/engines/rdma.c index 2569a8e3..43d8fa6a 100644 --- a/engines/rdma.c +++ b/engines/rdma.c @@ -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); -- 2.25.1