From ee3f0ab59afc1b0222517b7ce20a15e9f80e562f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hozza?= Date: Tue, 31 Dec 2024 06:07:07 +0100 Subject: [PATCH] tools/osbuild-image-info: make read_boot_entries() more robust MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `read_boot_entries()` could previously fail when trying to split lines in bootloader entries, which contained only "\n" and became empty string after stripping whitespace characters. This is the case e.g. on F41 images. Moreover, bootloader entries can contain comments as lines starting with "#", which were previously not ignored by the function and would end up in the parsed entry and could potentially fail to be split. Signed-off-by: Tomáš Hozza --- tools/osbuild-image-info | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/osbuild-image-info b/tools/osbuild-image-info index c082017b..7cb9aaf4 100755 --- a/tools/osbuild-image-info +++ b/tools/osbuild-image-info @@ -366,7 +366,14 @@ def read_boot_entries(boot_dir): entries = [] for conf in glob.glob(f"{boot_dir}/loader/entries/*.conf"): with open(conf) as f: - entries.append(dict(line.strip().split(" ", 1) for line in f)) + entry = dict() + for line in f: + line = line.strip() + if not line or line.startswith("#"): + continue + key, value = line.split(" ", 1) + entry[key] = value + entries.append(entry) return sorted(entries, key=lambda e: e["title"])