From 6e9b35774807f99a437aa267a5d68dd12e1db6fe Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Wed, 1 Dec 2021 18:15:59 +0100 Subject: [PATCH] tree: Handle NULL hostid in nvme_lookup_host() When hostid is specified for lookup and some of the tree host records carry a NULL, avoid a segfault here on strcmp(). --- src/nvme/tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nvme/tree.c b/src/nvme/tree.c index c1e58f93..a782f04a 100644 --- a/src/nvme/tree.c +++ b/src/nvme/tree.c @@ -374,8 +374,8 @@ struct nvme_host *nvme_lookup_host(nvme_root_t r, const char *hostnqn, nvme_for_each_host(r, h) { if (strcmp(h->hostnqn, hostnqn)) continue; - if (hostid && - strcmp(h->hostid, hostid)) + if (hostid && (!h->hostid || + strcmp(h->hostid, hostid))) continue; return h; } -- 2.50.1