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 <john.johansen@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
This commit is contained in:
John Johansen 2018-09-19 23:14:14 -07:00
parent eff672b2eb
commit 04beee7633

View file

@ -278,26 +278,14 @@ LT_EQUAL <=
}
<INCLUDE,INCLUDE_EXISTS>{
(\<([^"\>\t\r\n]+)\>|{QUOTED_ID}) { /* <filename> | "filename" */
autofree char *filename = strndup(yytext, yyleng - 1);
(\<(([^"\>\t\r\n]+)|{QUOTED_ID})\>|{QUOTED_ID}|{IDS}) { /* <filename> | <"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();
}
}