From a9ee2d7d188b4b58c6682e89e7b0bfbf3c7e73bf Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Wed, 20 Mar 2024 23:13:54 -0700 Subject: [PATCH] Fix xperm parsing logic --- native/src/sepolicy/lib.rs | 8 ++++++-- native/src/sepolicy/statement.rs | 8 ++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/native/src/sepolicy/lib.rs b/native/src/sepolicy/lib.rs index a3036c140..ccd72f99c 100644 --- a/native/src/sepolicy/lib.rs +++ b/native/src/sepolicy/lib.rs @@ -164,7 +164,11 @@ fn xperm_to_string(perm: &ffi::Xperm) -> String { if perm.reset { s.push('~'); } - s.write_fmt(format_args!("{{ {:#06x}-{:#06x} }}", perm.low, perm.high)) - .ok(); + if perm.low == perm.high { + s.write_fmt(format_args!("{{ {:#06X} }}", perm.low)).ok(); + } else { + s.write_fmt(format_args!("{{ {:#06X}-{:#06X} }}", perm.low, perm.high)) + .ok(); + } s } diff --git a/native/src/sepolicy/statement.rs b/native/src/sepolicy/statement.rs index 2168fee17..c1b026904 100644 --- a/native/src/sepolicy/statement.rs +++ b/native/src/sepolicy/statement.rs @@ -87,7 +87,7 @@ fn parse_terms<'a>(tokens: &mut Tokens<'a>) -> LoggedResult> { } } -// xperm ::= HX(low) { Xperm{low, high: 0, reset: false} }; +// xperm ::= HX(low) { Xperm{low, high: low, reset: false} }; // xperm ::= HX(low) HP HX(high) { Xperm{low, high, reset: false} }; fn parse_xperm(tokens: &mut Tokens) -> LoggedResult { let low = match tokens.next() { @@ -102,7 +102,7 @@ fn parse_xperm(tokens: &mut Tokens) -> LoggedResult { _ => throw!(), } } - _ => 0, + _ => low, }; Ok(Xperm { low, @@ -111,7 +111,7 @@ fn parse_xperm(tokens: &mut Tokens) -> LoggedResult { }) } -// xperms ::= HX(low) { if low > 0 { vec![Xperm{low, high: 0, reset: false}] } else { vec![Xperm{low: 0x0000, high: 0xFFFF, reset: true}] }}; +// xperms ::= HX(low) { if low > 0 { vec![Xperm{low, high: low, reset: false}] } else { vec![Xperm{low: 0x0000, high: 0xFFFF, reset: true}] }}; // xperms ::= LB xperm_list(l) RB { l }; // xperms ::= TL LB xperm_list(mut l) RB { l.iter_mut().for_each(|x| { x.reset = true; }); l }; // xperms ::= ST { vec![Xperm{low: 0x0000, high: 0xFFFF, reset: false}] }; @@ -154,7 +154,7 @@ fn parse_xperms(tokens: &mut Tokens) -> LoggedResult> { if low > 0 { xperms.push(Xperm { low, - high: 0, + high: low, reset, }); } else {