From 02f5b9a329c8b39fd18dbd113896e62a331e10df Mon Sep 17 00:00:00 2001 From: Chris PeBenito Date: Fri, 1 Apr 2016 15:20:57 -0400 Subject: [PATCH] Fix xperm rendering to use Python built-in "0x" formatting Also swap low/high if they are backwards in the TERuleQuery setter instead of erroring out --- setools/policyrep/terule.py | 4 ++-- setools/terulequery.py | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/setools/policyrep/terule.py b/setools/policyrep/terule.py index f1e39c3..fd5b1e1 100644 --- a/setools/policyrep/terule.py +++ b/setools/policyrep/terule.py @@ -182,9 +182,9 @@ class ioctlSet(set): for _, i in itertools.groupby(perms, key=lambda k, c=itertools.count(): k - next(c)): group = list(i) if len(group) > 1: - shortlist.append("0x{0:04x}-0x{1:04x}".format(group[0], group[-1])) + shortlist.append("{0:#06x}-{1:#06x}".format(group[0], group[-1])) else: - shortlist.append("0x{0:04x}".format(group[0])) + shortlist.append("{0:#06x}".format(group[0])) if not spec: return " ".join(shortlist) diff --git a/setools/terulequery.py b/setools/terulequery.py index 0af6b70..a2d59ae 100644 --- a/setools/terulequery.py +++ b/setools/terulequery.py @@ -107,14 +107,13 @@ class TERuleQuery(mixins.MatchObjClass, mixins.MatchPermission, query.PolicyQuer for low, high in value: if not (0 <= low <= 0xffff): - raise ValueError("{0:04x} is not a valid ioctl.".format(low)) + raise ValueError("{0:#07x} is not a valid ioctl.".format(low)) if not (0 <= high <= 0xffff): - raise ValueError("{0:04x} is not a valid ioctl.".format(high)) + raise ValueError("{0:#07x} is not a valid ioctl.".format(high)) if high < low: - raise ValueError("0x{0:04x}-0x{1:04x} is not a valid ioctl range.". - format(low, high)) + high, low = low, high pending_xperms.update(i for i in range(low, high+1))