From: Dmitry Monakhov Date: Tue, 7 Apr 2020 17:33:46 +0000 (+0300) Subject: engines: check options before dereference X-Git-Tag: fio-3.20~41^2~1 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=de8f86759f5e0aed5c65d0e4aaffaf33d27cbd89;p=fio.git 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 --- 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);