Skip to content

Commit d65b44c

Browse files
Stephen Chengigaw
authored andcommitted
tree: Fix potential NULL pointer dereference in nvme_host_get_ids()
The nvme_host_get_hostid() and nvme_host_get_hostnqn() functions can return NULL when the host configuration is incomplete or invalid. Using strdup() directly on these return values causes a segmentation fault when NULL is passed to strdup(). Replace strdup() calls with xstrdup() to safely handle NULL input values. Signed-off-by: Stephen Cheng <stephen.cheng@citrix.com>
1 parent becae3d commit d65b44c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/nvme/tree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ int nvme_host_get_ids(nvme_root_t r,
145145
h = nvme_first_host(r);
146146
if (h) {
147147
if (!hid)
148-
hid = strdup(nvme_host_get_hostid(h));
148+
hid = xstrdup(nvme_host_get_hostid(h));
149149
if (!hnqn)
150-
hnqn = strdup(nvme_host_get_hostnqn(h));
150+
hnqn = xstrdup(nvme_host_get_hostnqn(h));
151151
}
152152

153153
/* /etc/nvme/hostid and/or /etc/nvme/hostnqn */

0 commit comments

Comments
 (0)