From: James Carter <jwcart2@gmail.com>
To: selinux@vger.kernel.org
Cc: nicolas.iooss@m4x.org, James Carter <jwcart2@gmail.com>
Subject: [PATCH 4/7 v4] libsepol/cil: Push line mark state first when processing a line mark
Date: Mon, 16 Aug 2021 15:57:49 -0400 [thread overview]
Message-ID: <20210816195752.923028-5-jwcart2@gmail.com> (raw)
In-Reply-To: <20210816195752.923028-1-jwcart2@gmail.com>
CIL line mark rules are used to annotate the original line and file
of a rule. It is mostly used for neverallow rules that have been
converted to CIL.
Pushing the current line mark state after processing a line mark
section does not make sense since that information is never used.
When the line mark section ends the information is just popped and
discarded. It also makes pop_hll_info() more complicated than it
needs to be.
Push the line mark state first and simplfy pop_hll_info().
Signed-off-by: James Carter <jwcart2@gmail.com>
---
libsepol/cil/src/cil_parser.c | 22 +++++++++-------------
1 file changed, 9 insertions(+), 13 deletions(-)
diff --git a/libsepol/cil/src/cil_parser.c b/libsepol/cil/src/cil_parser.c
index 24386f60..d36ffc49 100644
--- a/libsepol/cil/src/cil_parser.c
+++ b/libsepol/cil/src/cil_parser.c
@@ -66,19 +66,15 @@ static void push_hll_info(struct cil_stack *stack, uint32_t hll_lineno, uint32_t
static void pop_hll_info(struct cil_stack *stack, uint32_t *hll_lineno, uint32_t *hll_expand)
{
struct cil_stack_item *curr = cil_stack_pop(stack);
- struct cil_stack_item *prev = cil_stack_peek(stack);
- struct hll_info *old;
+ struct hll_info *info;
- free(curr->data);
-
- if (!prev) {
- *hll_lineno = 0;
- *hll_expand = 0;
- } else {
- old = prev->data;
- *hll_lineno = old->hll_lineno;
- *hll_expand = old->hll_expand;
+ if (!curr) {
+ return;
}
+ info = curr->data;
+ *hll_expand = info->hll_expand;
+ *hll_lineno = info->hll_lineno;
+ free(curr->data);
}
static void create_node(struct cil_tree_node **node, struct cil_tree_node *current, uint32_t line, uint32_t hll_line, void *value)
@@ -128,6 +124,8 @@ static int add_hll_linemark(struct cil_tree_node **current, uint32_t *hll_lineno
pop_hll_info(stack, hll_lineno, hll_expand);
*current = (*current)->parent;
} else {
+ push_hll_info(stack, *hll_lineno, *hll_expand);
+
create_node(&node, *current, tok.line, *hll_lineno, NULL);
insert_node(node, *current);
*current = node;
@@ -158,8 +156,6 @@ static int add_hll_linemark(struct cil_tree_node **current, uint32_t *hll_lineno
*hll_lineno = val;
*hll_expand = (hll_type == CIL_KEY_HLL_LMX) ? 1 : 0;
- push_hll_info(stack, *hll_lineno, *hll_expand);
-
cil_lexer_next(&tok);
if (tok.type != SYMBOL && tok.type != QSTRING) {
cil_log(CIL_ERR, "Invalid line mark syntax\n");
--
2.31.1
next prev parent reply other threads:[~2021-08-16 19:58 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-16 19:57 [PATCH 0/7 v2] libsepol/cil: Line mark cleanup and fix James Carter
2021-08-16 19:57 ` [PATCH 1/7 v2] libsepol/cil: Check syntax of src_info statement James Carter
2021-08-16 19:57 ` [PATCH 2/7 v2] libsepol/cil: Check the token type after getting the next token James Carter
2021-08-16 19:57 ` [PATCH 3/7 v2] libsepol/cil: Check for valid line mark type immediately James Carter
2021-08-16 19:57 ` James Carter [this message]
2021-08-16 19:57 ` [PATCH 5/7 v2] libsepol/cil: Create common string-to-unsigned-integer functions James Carter
2021-08-16 19:57 ` [PATCH 6/7 v2] libsepol/cil: Add line mark kind and line number to src info James Carter
2021-08-16 19:57 ` [PATCH 7/7 v2] libsepol/cil: Report correct high-level language line numbers James Carter
2021-08-17 19:34 ` [PATCH 0/7 v2] libsepol/cil: Line mark cleanup and fix Nicolas Iooss
2021-08-17 20:15 ` James Carter
2021-08-17 20:43 ` Nicolas Iooss
2021-08-19 19:20 ` James Carter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210816195752.923028-5-jwcart2@gmail.com \
--to=jwcart2@gmail.com \
--cc=nicolas.iooss@m4x.org \
--cc=selinux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox