From 04beee76330a3d54f7259694023a16808c74df2b Mon Sep 17 00:00:00 2001 From: John Johansen Date: Wed, 19 Sep 2018 23:14:14 -0700 Subject: [PATCH] parser: combine INCLUDE cases together and support escape sequences We can reduce the INCLUDE/INCLUDE_EXISTS code dup by using a variable for whether the name was enclosed by '<' and using processid() to handle the whether the id is quoted or not. In addition using processid allows include names to contain escaoe sequences like \n and have them handled correctly. PR: https://gitlab.com/apparmor/apparmor/merge_requests/196 Signed-off-by: John Johansen Acked-by: Seth Arnold --- parser/parser_lex.l | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/parser/parser_lex.l b/parser/parser_lex.l index 9294c4ab1..a218a8810 100644 --- a/parser/parser_lex.l +++ b/parser/parser_lex.l @@ -278,26 +278,14 @@ LT_EQUAL <= } { - (\<([^"\>\t\r\n]+)\>|{QUOTED_ID}) { /* | "filename" */ - autofree char *filename = strndup(yytext, yyleng - 1); + (\<(([^"\>\t\r\n]+)|{QUOTED_ID})\>|{QUOTED_ID}|{IDS}) { /* | <"filename"> | "filename" | filename */ + int lt = *yytext == '<' ? 1 : 0; + autofree char *filename = processid(yytext + lt, yyleng - lt*2); bool exists = YYSTATE == INCLUDE_EXISTS; - include_filename(filename + 1, *filename == '<', exists); - POP_NODUMP(); - } - - (\<{QUOTED_ID}\>) { /* <"filename"> */ - autofree char *filename = strndup(yytext, yyleng - 2); - bool exists = YYSTATE == INCLUDE_EXISTS; - - include_filename(filename + 2, true, exists); - POP_NODUMP(); - } - - ({IDS}|{QUOTED_ID}) { /* filename */ - bool exists = YYSTATE == INCLUDE_EXISTS; - - include_filename(yytext, false, exists); + if (!filename) + yyerror(_("Failed to process filename\n")); + include_filename(filename, lt, exists); POP_NODUMP(); } }