File 0011-nvme-print-fix-nvme-list-segfault-if-controller-is-u.patch of Package nvme-cli.26915

From: Martin George <marting@netapp.com>
Date: Thu, 5 Aug 2021 18:01:24 +0530
Subject: nvme-print: fix 'nvme list' segfault if controller is
 unavailable
References: bsc#1189046
Git-commit: 59e7477c5a18ec4bcb1f9b1e20d2303b4e0cafb1

Check if the controller is available before dereferencing the
controller attributes.

Signed-off-by: Martin George <marting@netapp.com>
---
 nvme-print.c |    9 +++++++++
 1 file changed, 9 insertions(+)

--- a/nvme-print.c
+++ b/nvme-print.c
@@ -4684,6 +4684,9 @@ static void nvme_show_list_item(struct n
 	struct stat st;
 	int ret;
 
+	if (!n->ctrl)
+		return;
+
 	sprintf(path, "/dev/%s", n->name);
 	ret = stat(path, &st);
 	if (ret < 0)
@@ -4740,6 +4743,9 @@ static void nvme_show_details_ns(struct
 	char usage[128];
 	char format[128];
 
+	if (!n->ctrl)
+		return;
+
 	sprintf(usage,"%6.2f %2sB / %6.2f %2sB", nuse, u_suffix,
 		nsze, s_suffix);
 	sprintf(format,"%3.0f %2sB + %2d B", (double)lba, l_suffix,
@@ -4957,6 +4963,9 @@ static void json_simple_ns(struct nvme_n
 	long long lba;
 	char *devnode;
 
+	if (!n->ctrl)
+		return;
+
 	if (asprintf(&devnode, "/dev/%s", n->name) < 0)
 		return;
 
openSUSE Build Service is sponsored by