]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
Fix segfault listing models
authorKeith Busch <keith.busch@intel.com>
Tue, 6 Dec 2016 22:36:32 +0000 (15:36 -0700)
committerKeith Busch <keith.busch@intel.com>
Tue, 6 Dec 2016 22:36:32 +0000 (15:36 -0700)
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 <keith.busch@intel.com>
nvme-models.c

index c607b767141457f9edf2b27edc61fd556c1e594f..e55e7b07c2d51558dd9d7bcc3ca4a17ae15cafc7 100644 (file)
@@ -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);