Coverity points out that there is a check in the main thread loop for the
ctrlr->bdev being NULL, but by that stage the pointer has already been
dereferenced. Therefore, for safety, before we enter the loop do an
initial check on the parameter structure.
Coverity issue: 158657
Fixes: db75c7af19bb ("examples/vhost_scsi: introduce a new sample app")
CC: [email protected]
CC: Maxime Coquelin <[email protected]>
CC: Tiwei Bie <[email protected]>
CC: Zhihong Wang <[email protected]>
Signed-off-by: Bruce Richardson <[email protected]>
---
examples/vhost_scsi/vhost_scsi.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/examples/vhost_scsi/vhost_scsi.c b/examples/vhost_scsi/vhost_scsi.c
index 2908ff68b..a6465d089 100644
--- a/examples/vhost_scsi/vhost_scsi.c
+++ b/examples/vhost_scsi/vhost_scsi.c
@@ -285,6 +285,12 @@ ctrlr_worker(void *arg)
cpu_set_t cpuset;
pthread_t thread;
+ if (ctrlr == NULL || ctrlr->bdev == NULL) {
+ fprintf(stdout, "%s: Error, invalid argument passed to worker
thread\n",
+ __func__);
+ return NULL;
+ }
+
thread = pthread_self();
CPU_ZERO(&cpuset);
CPU_SET(0, &cpuset);
--
2.20.1