Correctly handle comments in sepolicy.rule

This commit is contained in:
LoveSy 2024-07-24 17:45:08 +08:00 committed by John Wu
parent f488e9df8f
commit 9cc50b20d8
2 changed files with 4 additions and 8 deletions

View File

@ -118,10 +118,6 @@ impl SepolicyExt for sepolicy {
fn load_rules_from_reader<T: BufRead>(mut self: Pin<&mut sepolicy>, reader: &mut T) { fn load_rules_from_reader<T: BufRead>(mut self: Pin<&mut sepolicy>, reader: &mut T) {
reader.foreach_lines(|line| { reader.foreach_lines(|line| {
let line = line.trim();
if line.is_empty() {
return true;
}
parse_statement(self.as_mut(), line); parse_statement(self.as_mut(), line);
true true
}); });

View File

@ -3,7 +3,6 @@ use std::io::stderr;
use std::{iter::Peekable, pin::Pin, vec::IntoIter}; use std::{iter::Peekable, pin::Pin, vec::IntoIter};
use base::{error, warn, FmtAdaptor}; use base::{error, warn, FmtAdaptor};
use crate::ffi::Xperm; use crate::ffi::Xperm;
use crate::sepolicy; use crate::sepolicy;
@ -436,15 +435,16 @@ fn extract_token<'a>(s: &'a str, tokens: &mut Vec<Token<'a>>) {
fn tokenize_statement(statement: &str) -> Vec<Token> { fn tokenize_statement(statement: &str) -> Vec<Token> {
let mut tokens = Vec::new(); let mut tokens = Vec::new();
for s in statement.split_whitespace() { for s in statement.split_whitespace() {
if s.starts_with('#') {
break;
}
extract_token(s, &mut tokens); extract_token(s, &mut tokens);
} }
tokens tokens
} }
pub fn parse_statement(sepolicy: Pin<&mut sepolicy>, statement: &str) { pub fn parse_statement(sepolicy: Pin<&mut sepolicy>, statement: &str) {
let statement = statement.trim();
if statement.is_empty() || statement.starts_with('#') {
return;
}
let mut tokens = tokenize_statement(statement).into_iter().peekable(); let mut tokens = tokenize_statement(statement).into_iter().peekable();
let result = exec_statement(sepolicy, &mut tokens); let result = exec_statement(sepolicy, &mut tokens);
if let Err(e) = result { if let Err(e) = result {