Blame SOURCES/0001-Make-seinfo-output-predictable.patch

a4d343
From 8ed316d6bfb65e5e9b57f3761ea8490022ab3a05 Mon Sep 17 00:00:00 2001
a4d343
From: Petr Lautrbach <plautrba@redhat.com>
a4d343
Date: Thu, 18 Nov 2021 13:59:08 +0100
a4d343
Subject: [PATCH] Make seinfo output predictable
a4d343
a4d343
There are few places where frozenset is used. Given that frozenset is an unordered
a4d343
collection the output generated from this is unpredictable.
a4d343
a4d343
The following command outputs are fixed using sorted() on frozensets:
a4d343
a4d343
    seinfo --constrain
a4d343
    seinfo --common
a4d343
    seinfo -c -x
a4d343
    seinfo -r -x
a4d343
    seinfo -u -x
a4d343
a4d343
Fixes: https://github.com/SELinuxProject/setools/issues/65
a4d343
a4d343
Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
a4d343
---
a4d343
 setools/policyrep/constraint.pxi | 2 +-
a4d343
 setools/policyrep/objclass.pxi   | 4 ++--
a4d343
 setools/policyrep/role.pxi       | 2 +-
a4d343
 setools/policyrep/user.pxi       | 2 +-
a4d343
 4 files changed, 5 insertions(+), 5 deletions(-)
a4d343
a4d343
diff --git a/setools/policyrep/constraint.pxi b/setools/policyrep/constraint.pxi
a4d343
index 01c63d87425b..0b4c5b9bcf6a 100644
a4d343
--- a/setools/policyrep/constraint.pxi
a4d343
+++ b/setools/policyrep/constraint.pxi
a4d343
@@ -72,7 +72,7 @@ cdef class Constraint(BaseConstraint):
a4d343
 
a4d343
     def statement(self):
a4d343
         if len(self.perms) > 1:
a4d343
-            perms = "{{ {0} }}".format(' '.join(self.perms))
a4d343
+            perms = "{{ {0} }}".format(' '.join(sorted(self.perms)))
a4d343
         else:
a4d343
             # convert to list since sets cannot be indexed
a4d343
             perms = list(self.perms)[0]
a4d343
diff --git a/setools/policyrep/objclass.pxi b/setools/policyrep/objclass.pxi
a4d343
index b7ec7b7de5c3..8ed2be5a9bed 100644
a4d343
--- a/setools/policyrep/objclass.pxi
a4d343
+++ b/setools/policyrep/objclass.pxi
a4d343
@@ -75,7 +75,7 @@ cdef class Common(PolicySymbol):
a4d343
         return other in self.perms
a4d343
 
a4d343
     def statement(self):
a4d343
-        return "common {0}\n{{\n\t{1}\n}}".format(self, '\n\t'.join(self.perms))
a4d343
+        return "common {0}\n{{\n\t{1}\n}}".format(self, '\n\t'.join(sorted(self.perms)))
a4d343
 
a4d343
 
a4d343
 cdef class ObjClass(PolicySymbol):
a4d343
@@ -204,7 +204,7 @@ cdef class ObjClass(PolicySymbol):
a4d343
 
a4d343
         # a class that inherits may not have additional permissions
a4d343
         if len(self.perms) > 0:
a4d343
-            stmt += "{{\n\t{0}\n}}".format('\n\t'.join(self.perms))
a4d343
+            stmt += "{{\n\t{0}\n}}".format('\n\t'.join(sorted(self.perms)))
a4d343
 
a4d343
         return stmt
a4d343
 
a4d343
diff --git a/setools/policyrep/role.pxi b/setools/policyrep/role.pxi
a4d343
index 9a0dd39f27d9..3af8a3f72a1f 100644
a4d343
--- a/setools/policyrep/role.pxi
a4d343
+++ b/setools/policyrep/role.pxi
a4d343
@@ -58,7 +58,7 @@ cdef class Role(PolicySymbol):
a4d343
         if count == 1:
a4d343
             stmt += " types {0}".format(types[0])
a4d343
         else:
a4d343
-            stmt += " types {{ {0} }}".format(' '.join(types))
a4d343
+            stmt += " types {{ {0} }}".format(' '.join(sorted(types)))
a4d343
 
a4d343
         stmt += ";"
a4d343
         return stmt
a4d343
diff --git a/setools/policyrep/user.pxi b/setools/policyrep/user.pxi
a4d343
index 9c82aa92eb72..e37af2939820 100644
a4d343
--- a/setools/policyrep/user.pxi
a4d343
+++ b/setools/policyrep/user.pxi
a4d343
@@ -81,7 +81,7 @@ cdef class User(PolicySymbol):
a4d343
         if count == 1:
a4d343
             stmt += roles[0]
a4d343
         else:
a4d343
-            stmt += "{{ {0} }}".format(' '.join(roles))
a4d343
+            stmt += "{{ {0} }}".format(' '.join(sorted(roles)))
a4d343
 
a4d343
         if self._level:
a4d343
             stmt += " level {0.mls_level} range {0.mls_range};".format(self)
a4d343
-- 
a4d343
2.33.1
a4d343