From 44c7aa9fa5b64641f00f3f5c91dde60c75786af1 Mon Sep 17 00:00:00 2001 From: Keith Busch Date: Tue, 6 Dec 2016 15:36:32 -0700 Subject: [PATCH] Fix segfault listing models The models strings may not exist in the place this program thinks it does. Check if the file is valid before reading from it, and return an apporpriate string accordingly. https://github.com/linux-nvme/nvme-cli/issues/140 Signed-off-by: Keith Busch --- nvme-models.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nvme-models.c b/nvme-models.c index c607b76..e55e7b0 100644 --- a/nvme-models.c +++ b/nvme-models.c @@ -249,6 +249,9 @@ char *nvme_product_name(int id) size_t size = 1024; char ret; + if (!file) + goto error1; + snprintf(fmt1, 78, _fmt1, id); snprintf(fmt2, 78, _fmt2, id); snprintf(fmt3, 78, _fmt3, id); -- 2.49.0