Skip to content

Commit 0dc339a

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 <[email protected]>
1 parent 91cc3ee commit 0dc339a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

libnvme/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(struct nvme_global_ctx *ctx,
145145
h = nvme_first_host(ctx);
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)