]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
ukify: rstrip and escape binary null characters from 'inspect' output (#38607)
authorLi Tian <94442129+litian1992@users.noreply.github.com>
Mon, 18 Aug 2025 21:43:41 +0000 (05:43 +0800)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 3 Sep 2025 10:10:48 +0000 (12:10 +0200)
SBAT section of UKI may contain \u000 null characters. Rstrip them, and if there's anything left in the middle,
escape them so they are displayed as text.

Fixes #38606

(cherry picked from commit 776991a3f349d9c99fd166a0c87fcd2bc1bf92a5)

src/ukify/ukify.py

index 40be4adb6bdd7d1ecd5fcd31be1512a95e48cb96..90026e5d81208276fe5999e4bd7b768d4522c84a 100755 (executable)
@@ -1480,7 +1480,7 @@ def inspect_section(
 
     if ttype == 'text':
         try:
-            struct['text'] = data.decode()
+            struct['text'] = data.rstrip(b'\0').replace(b'\0', b'\\0').decode()
         except UnicodeDecodeError as e:
             print(f'Section {name!r} is not valid text: {e}', file=sys.stderr)
             struct['text'] = '(not valid UTF-8)'