All of lore.kernel.org
 help / color / mirror / Atom feed
From: James Carter <jwcart2@gmail.com>
To: selinux@vger.kernel.org
Cc: James Carter <jwcart2@gmail.com>
Subject: [PATCH 3/8] libsepol/cil: Check for valid line mark type immediately
Date: Tue, 10 Aug 2021 14:05:32 -0400	[thread overview]
Message-ID: <20210810180537.669439-4-jwcart2@gmail.com> (raw)
In-Reply-To: <20210810180537.669439-1-jwcart2@gmail.com>

It clearer to check that the line mark type is a valid option right
after getting the token.

Check that the line mark type is one of the expected values right
awasy.

Signed-off-by: James Carter <jwcart2@gmail.com>
---
 libsepol/cil/src/cil_parser.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/libsepol/cil/src/cil_parser.c b/libsepol/cil/src/cil_parser.c
index fc90caec..24386f60 100644
--- a/libsepol/cil/src/cil_parser.c
+++ b/libsepol/cil/src/cil_parser.c
@@ -116,6 +116,10 @@ static int add_hll_linemark(struct cil_tree_node **current, uint32_t *hll_lineno
 		goto exit;
 	}
 	hll_type = cil_strpool_add(tok.value);
+	if (hll_type != CIL_KEY_HLL_LME && hll_type != CIL_KEY_HLL_LMS && hll_type != CIL_KEY_HLL_LMX) {
+		cil_log(CIL_ERR, "Invalid line mark syntax\n");
+		goto exit;
+	}
 	if (hll_type == CIL_KEY_HLL_LME) {
 		if (cil_stack_is_empty(stack)) {
 			cil_log(CIL_ERR, "Line mark end without start\n");
@@ -134,15 +138,6 @@ static int add_hll_linemark(struct cil_tree_node **current, uint32_t *hll_lineno
 		create_node(&node, *current, tok.line, *hll_lineno, CIL_KEY_SRC_HLL);
 		insert_node(node, *current);
 
-		if (hll_type == CIL_KEY_HLL_LMS) {
-			*hll_expand = 0;
-		} else if (hll_type == CIL_KEY_HLL_LMX) {
-			*hll_expand = 1;
-		} else {
-			cil_log(CIL_ERR, "Invalid line mark syntax\n");
-			goto exit;
-		}
-
 		cil_lexer_next(&tok);
 		if (tok.type != SYMBOL) {
 			cil_log(CIL_ERR, "Invalid line mark syntax\n");
@@ -161,6 +156,7 @@ static int add_hll_linemark(struct cil_tree_node **current, uint32_t *hll_lineno
 		}
 #endif
 		*hll_lineno = val;
+		*hll_expand = (hll_type == CIL_KEY_HLL_LMX) ? 1 : 0;
 
 		push_hll_info(stack, *hll_lineno, *hll_expand);
 
-- 
2.31.1


  parent reply	other threads:[~2021-08-10 18:21 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-10 18:05 [PATCH 0/8] libsepol/cil: Line mark cleanup and fix James Carter
2021-08-10 18:05 ` [PATCH 1/8] libsepol/cil: Check syntax of src_info statement James Carter
2021-08-10 18:05 ` [PATCH 2/8] libsepol/cil: Check the token type after getting the next token James Carter
2021-08-10 18:05 ` James Carter [this message]
2021-08-10 18:05 ` [PATCH 4/8] libsepol/cil: Push line mark state first when processing a line mark James Carter
2021-08-10 18:05 ` [PATCH 5/8] libsepol/cil: Create common string-to-unsigned-integer functions James Carter
2021-08-10 18:05 ` [PATCH 6/8] libsepol/cil: Add line mark kind and line number to src info James Carter
2021-08-16  9:38   ` Nicolas Iooss
2021-08-16 14:44     ` James Carter
2021-08-10 18:05 ` [PATCH 7/8] libsepol/cil: Report correct high-level language line numbers James Carter
2021-08-16  9:23   ` Nicolas Iooss
2021-08-16 14:40     ` James Carter
2021-08-10 18:05 ` [PATCH 8/8] libsepol/cil: When writing AST use line marks for src_info nodes 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=20210810180537.669439-4-jwcart2@gmail.com \
    --to=jwcart2@gmail.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.