neil / rpms / python-blivet

Forked from rpms/python-blivet a year ago
Clone

Blame SOURCES/0015-Fix-possible-UnicodeDecodeError-when-reading-model-f.patch

4cd9fd
From 866a48e6c3d8246d2897bb402a191df5f2848aa4 Mon Sep 17 00:00:00 2001
4cd9fd
From: Vojtech Trefny <vtrefny@redhat.com>
4cd9fd
Date: Tue, 23 Jun 2020 10:33:33 +0200
4cd9fd
Subject: [PATCH] Fix possible UnicodeDecodeError when reading model from sysfs
4cd9fd
4cd9fd
Some Innovation IT NVMe devices have an (invalid) unicode in their
4cd9fd
model name.
4cd9fd
4cd9fd
Resolves: rhbz#1849326
4cd9fd
---
4cd9fd
 blivet/udev.py | 5 +++--
4cd9fd
 1 file changed, 3 insertions(+), 2 deletions(-)
4cd9fd
4cd9fd
diff --git a/blivet/udev.py b/blivet/udev.py
4cd9fd
index 41c99496..2c795225 100644
4cd9fd
--- a/blivet/udev.py
4cd9fd
+++ b/blivet/udev.py
4cd9fd
@@ -185,8 +185,9 @@ def __is_blacklisted_blockdev(dev_name):
4cd9fd
         if any(re.search(expr, dev_name) for expr in device_name_blacklist):
4cd9fd
             return True
4cd9fd
 
4cd9fd
-    if os.path.exists("/sys/class/block/%s/device/model" % (dev_name,)):
4cd9fd
-        model = open("/sys/class/block/%s/device/model" % (dev_name,)).read()
4cd9fd
+    model_path = "/sys/class/block/%s/device/model" % dev_name
4cd9fd
+    if os.path.exists(model_path):
4cd9fd
+        model = open(model_path, encoding="utf-8", errors="replace").read()
4cd9fd
         for bad in ("IBM *STMF KERNEL", "SCEI Flash-5", "DGC LUNZ"):
4cd9fd
             if model.find(bad) != -1:
4cd9fd
                 log.info("ignoring %s with model %s", dev_name, model)
4cd9fd
-- 
4cd9fd
2.26.2
4cd9fd