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
This commit is contained in:
Chris PeBenito 2016-04-01 15:20:57 -04:00
parent 1370cfd20f
commit 02f5b9a329
2 changed files with 5 additions and 6 deletions

View File

@ -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)

View File

@ -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))