From 3c6573922d46a99f86396f25f3e60b6b8c91b9ef Mon Sep 17 00:00:00 2001 From: Stephen Cheng Date: Thu, 20 Nov 2025 13:11:03 +0800 Subject: [PATCH] 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 --- 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 bc836487d..c363cd13c 100644 --- a/src/nvme/tree.c +++ b/src/nvme/tree.c @@ -145,9 +145,9 @@ int nvme_host_get_ids(nvme_root_t r, h = nvme_first_host(r); if (h) { if (!hid) - hid = strdup(nvme_host_get_hostid(h)); + hid = xstrdup(nvme_host_get_hostid(h)); if (!hnqn) - hnqn = strdup(nvme_host_get_hostnqn(h)); + hnqn = xstrdup(nvme_host_get_hostnqn(h)); } /* /etc/nvme/hostid and/or /etc/nvme/hostnqn */