]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
tree: Handle NULL hostid in nvme_lookup_host()
authorTomas Bzatek <tbzatek@redhat.com>
Wed, 1 Dec 2021 17:15:59 +0000 (18:15 +0100)
committerTomas Bzatek <tbzatek@redhat.com>
Wed, 1 Dec 2021 17:20:04 +0000 (18:20 +0100)
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

index c1e58f9371d5906381aa4f9cc4d9ec9fafe9707d..a782f04a2e92df048a0c5aed659c06b92dd2b2e5 100644 (file)
@@ -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;
        }