Blob Blame History Raw
From 866a48e6c3d8246d2897bb402a191df5f2848aa4 Mon Sep 17 00:00:00 2001
From: Vojtech Trefny <vtrefny@redhat.com>
Date: Tue, 23 Jun 2020 10:33:33 +0200
Subject: [PATCH] Fix possible UnicodeDecodeError when reading model from sysfs

Some Innovation IT NVMe devices have an (invalid) unicode in their
model name.

Resolves: rhbz#1849326
---
 blivet/udev.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/blivet/udev.py b/blivet/udev.py
index 41c99496..2c795225 100644
--- a/blivet/udev.py
+++ b/blivet/udev.py
@@ -185,8 +185,9 @@ def __is_blacklisted_blockdev(dev_name):
         if any(re.search(expr, dev_name) for expr in device_name_blacklist):
             return True
 
-    if os.path.exists("/sys/class/block/%s/device/model" % (dev_name,)):
-        model = open("/sys/class/block/%s/device/model" % (dev_name,)).read()
+    model_path = "/sys/class/block/%s/device/model" % dev_name
+    if os.path.exists(model_path):
+        model = open(model_path, encoding="utf-8", errors="replace").read()
         for bad in ("IBM *STMF KERNEL", "SCEI Flash-5", "DGC LUNZ"):
             if model.find(bad) != -1:
                 log.info("ignoring %s with model %s", dev_name, model)
-- 
2.26.2