UnicodeDecodeError: utf-8 on python semanage -i import

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Importing a .pp file with the python semanage -i option generates a "UnicodeDecodeError: utf-8" on an up to date Rocky 9 distribution.

packages:

policycoreutils-python-utils-3.6-2.1.el9.noarch
python-unversioned-command-3.9.18-3.el9.noarch

The open() in SetImportFile needs the binary "b" option to open the file in binary mode, as the .pp file is not in utf-8 format:

--- /semanage~ 2024-07-01 10:29:20.000000000 -0600
+++ /semanage 2024-07-01 10:54:30.520312298 -0600
@@ -122,11 +122,11 @@
 class SetImportFile(argparse.Action):
 
     def __call__(self, parser, namespace, values, option_string=None):
         if values and values != "-":
             try:
-                sys.stdin = open(values, 'r')
+                sys.stdin = open(values, 'rb')
             except IOError as e:
                 sys.stderr.write("%s: %s\n" % (e.__class__.__name__, str(e)))
                 sys.exit(1)
         setattr(namespace, self.dest, values)

patch also attached.

Thanks,

Allan Oepping
--- /semanage~	2024-07-01 10:29:20.000000000 -0600
+++ /semanage	2024-07-01 10:54:30.520312298 -0600
@@ -122,11 +122,11 @@
 class SetImportFile(argparse.Action):
 
     def __call__(self, parser, namespace, values, option_string=None):
         if values and values != "-":
             try:
-                sys.stdin = open(values, 'r')
+                sys.stdin = open(values, 'rb')
             except IOError as e:
                 sys.stderr.write("%s: %s\n" % (e.__class__.__name__, str(e)))
                 sys.exit(1)
         setattr(namespace, self.dest, values)
 

[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux