libnvme: fix segfault when trying to list nvme drives

Resolves: RHEL-49544

Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
This commit is contained in:
Maurizio Lombardi 2024-08-01 10:29:22 +02:00
parent 15e40ecbbe
commit 91633a7c13
2 changed files with 37 additions and 1 deletions

View File

@ -0,0 +1,32 @@
From 49a4cd8f62d05bb4e1b6e1365bad638c366cdba9 Mon Sep 17 00:00:00 2001
From: Greg Joyce <gjoyce@linux.ibm.com>
Date: Tue, 23 Jul 2024 01:04:42 +0530
Subject: [PATCH] tree: handle no address phy slot dirs
Not all directories have an address. Verify addr before calling
strcmp().
Fixes: 42ac45359635 ("tree: Add PCI physical slot number for controller")
Signed-off-by: Greg Joyce <gjoyce@linux.ibm.com>
---
src/nvme/tree.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/nvme/tree.c b/src/nvme/tree.c
index 288b23c73a1b..b0ee94047634 100644
--- a/src/nvme/tree.c
+++ b/src/nvme/tree.c
@@ -1867,6 +1867,10 @@ static char *nvme_ctrl_lookup_phy_slot(nvme_root_t r, const char *address)
return NULL;
}
addr = nvme_get_attr(path, "address");
+
+ /* some directories don't have an address entry */
+ if (!addr)
+ continue;
if (strcmp(addr, target_addr) == 0)
return strdup(entry->d_name);
}
--
2.43.0

View File

@ -4,13 +4,14 @@
Name: libnvme
Summary: Linux-native nvme device management library
Version: 1.9
Release: 2%{?dist}
Release: 3%{?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
# https://issues.redhat.com/browse/RHEL-37608
Patch0: libnvme-1.10-uriparser.patch
Patch1: 0001-tree-handle-no-address-phy-slot-dirs.patch
BuildRequires: gcc gcc-c++
BuildRequires: swig
@ -96,6 +97,9 @@ mv %{buildroot}/usr/*.rst %{buildroot}%{_pkgdocdir}/
%{python3_sitearch}/libnvme/*
%changelog
* Thu Aug 01 2024 Maurizio Lombardi <mlombard@redhat.com> - 1.9-3
- Backport fix for RHEL-49544
* Wed Jul 24 2024 Tomas Bzatek <tbzatek@redhat.com> - 1.9-2
- Backport URI parser API