Fix potential NULL pointer dereference in nvme_host_get_ids

Resolves: RHEL-181034

Signed-off-by: Utkarsh Singh <utsingh@redhat.com>
This commit is contained in:
Utkarsh Singh 2026-06-30 14:57:29 +05:30
parent a6f6682cf6
commit c0f86cd835
2 changed files with 43 additions and 1 deletions

View File

@ -0,0 +1,38 @@
From d65b44cd0a2cde7aba895c7c9f9c9fff198ead99 Mon Sep 17 00:00:00 2001
From: Stephen Cheng <stephen.cheng@citrix.com>
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 <stephen.cheng@citrix.com>
---
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 bc836487..c363cd13 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 */
--
2.54.0

View File

@ -4,11 +4,12 @@
Name: libnvme
Summary: Linux-native nvme device management library
Version: 1.16.1
Release: 3%{?dist}
Release: 4%{?dist}
License: LGPL-2.1-or-later
URL: https://github.com/linux-nvme/libnvme
Source0: %{url}/archive/v%{version_no_tilde}/%{name}-%{version_no_tilde}.tar.gz
Patch0: 0001-tree-cleanup-paths-when-freeing-namespace.patch
Patch1: 0002-tree-Fix-potential-NULL-pointer-dereference-in-nvme_host_get_ids.patch
BuildRequires: gcc gcc-c++
BuildRequires: swig
@ -99,6 +100,9 @@ rm -r %{buildroot}%{_pkgdocdir}/html/{.buildinfo,.doctrees/}
%{python3_sitearch}/libnvme/*
%changelog
* Tue Jun 30 2026 Utkarsh Singh <utsingh@redhat.com> - 1.16.1-4
- Fix potential NULL pointer dereference in nvme_host_get_ids (RHEL-181034)
* Fri Mar 27 2026 Maurizio Lombardi <mlombard@redhat.com> - 1.16.1-3
- Fix linked list corruption (RHEL-156539)