mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-22 01:57:43 +00:00
Add new processid fn that handles both quoted and unquoted ids
There is a lot of duplication of code calling processqunquoted and processquoted. Move all this code to use the new processid fn. Signed-off-by: John Johansen <john.johansen@canonical.com> Acked-by: Kees Cook <kees@ubuntu.com>
This commit is contained in:
parent
37e2975d4d
commit
7f9c79e345
@ -271,6 +271,7 @@ extern struct var_string *split_out_var(char *string);
|
||||
extern void free_var_string(struct var_string *var);
|
||||
|
||||
/* parser_misc.c */
|
||||
extern char *processid(char *string, int len);
|
||||
extern char *processquoted(char *string, int len);
|
||||
extern char *processunquoted(char *string, int len);
|
||||
extern int get_keyword_token(const char *keyword);
|
||||
|
@ -247,7 +247,7 @@ LT_EQUAL <=
|
||||
}
|
||||
|
||||
<SUB_NAME>{
|
||||
{ID}+ {
|
||||
({ID}+|{QUOTED_ID}) {
|
||||
/* Ugh, this is a gross hack. I used to use
|
||||
* {ID}+ to match all TOK_IDs, but that would
|
||||
* also match TOK_MODE + TOK_END_OF_RULE
|
||||
@ -256,25 +256,11 @@ LT_EQUAL <=
|
||||
* match any random string, I go into a
|
||||
* separate state. */
|
||||
DUMP_PREPROCESS;
|
||||
yylval.id = processunquoted(yytext, yyleng);
|
||||
yylval.id = processid(yytext, yyleng);
|
||||
PDEBUG("Found sub name: \"%s\"\n", yylval.id);
|
||||
yy_pop_state();
|
||||
return TOK_ID;
|
||||
}
|
||||
{QUOTED_ID} {
|
||||
/* Ugh, this is a gross hack. I used to use
|
||||
* {ID}+ to match all TOK_IDs, but that would
|
||||
* also match TOK_MODE + TOK_END_OF_RULE
|
||||
* without any spaces in between (because it's
|
||||
* a longer match). So now, when I want to
|
||||
* match any random string, I go into a
|
||||
* separate state. */
|
||||
DUMP_PREPROCESS;
|
||||
yylval.id = processquoted(yytext, yyleng);
|
||||
PDEBUG("Found sub name: \"%s\"\n", yylval.id);
|
||||
yy_pop_state();
|
||||
return TOK_ID;
|
||||
}
|
||||
|
||||
[^\n] {
|
||||
DUMP_PREPROCESS;
|
||||
@ -284,7 +270,7 @@ LT_EQUAL <=
|
||||
}
|
||||
|
||||
<SUB_NAME2>{
|
||||
{ID}+ {
|
||||
({ID}+|{QUOTED_ID}) {
|
||||
/* Ugh, this is a gross hack. I used to use
|
||||
* {ID}+ to match all TOK_IDs, but that would
|
||||
* also match TOK_MODE + TOK_END_OF_RULE
|
||||
@ -293,21 +279,7 @@ LT_EQUAL <=
|
||||
* match any random string, I go into a
|
||||
* separate state. */
|
||||
DUMP_PREPROCESS;
|
||||
yylval.id = processunquoted(yytext, yyleng);
|
||||
PDEBUG("Found sub name: \"%s\"\n", yylval.id);
|
||||
yy_pop_state();
|
||||
return TOK_ID;
|
||||
}
|
||||
{QUOTED_ID} {
|
||||
/* Ugh, this is a gross hack. I used to use
|
||||
* {ID}+ to match all TOK_IDs, but that would
|
||||
* also match TOK_MODE + TOK_END_OF_RULE
|
||||
* without any spaces in between (because it's
|
||||
* a longer match). So now, when I want to
|
||||
* match any random string, I go into a
|
||||
* separate state. */
|
||||
DUMP_PREPROCESS;
|
||||
yylval.id = processquoted(yytext, yyleng);
|
||||
yylval.id = processid(yytext, yyleng);
|
||||
PDEBUG("Found sub name: \"%s\"\n", yylval.id);
|
||||
yy_pop_state();
|
||||
return TOK_ID;
|
||||
@ -364,16 +336,9 @@ LT_EQUAL <=
|
||||
<ASSIGN_MODE>{
|
||||
{WS}+ { DUMP_PREPROCESS; /* Eat whitespace */ }
|
||||
|
||||
{ID}+ {
|
||||
({ID}+|{QUOTED_ID}) {
|
||||
DUMP_PREPROCESS;
|
||||
yylval.var_val = processunquoted(yytext, yyleng);
|
||||
PDEBUG("Found assignment value: \"%s\"\n", yylval.var_val);
|
||||
return TOK_VALUE;
|
||||
}
|
||||
|
||||
{QUOTED_ID} {
|
||||
DUMP_PREPROCESS;
|
||||
yylval.var_val = processquoted(yytext, yyleng);
|
||||
yylval.var_val = processid(yytext, yyleng);
|
||||
PDEBUG("Found assignment value: \"%s\"\n", yylval.var_val);
|
||||
return TOK_VALUE;
|
||||
}
|
||||
@ -431,7 +396,7 @@ LT_EQUAL <=
|
||||
return TOK_ARROW;
|
||||
}
|
||||
|
||||
{ID}+ {
|
||||
({ID}+|{QUOTED_ID}) {
|
||||
/* Ugh, this is a gross hack. I used to use
|
||||
* {ID}+ to match all TOK_IDs, but that would
|
||||
* also match TOK_MODE + TOK_END_OF_RULE
|
||||
@ -440,25 +405,11 @@ LT_EQUAL <=
|
||||
* match any random string, I go into a
|
||||
* separate state. */
|
||||
DUMP_PREPROCESS;
|
||||
yylval.id = processunquoted(yytext, yyleng);
|
||||
yylval.id = processid(yytext, yyleng);
|
||||
PDEBUG("Found change profile name: \"%s\"\n", yylval.id);
|
||||
yy_pop_state();
|
||||
return TOK_ID;
|
||||
}
|
||||
{QUOTED_ID} {
|
||||
/* Ugh, this is a gross hack. I used to use
|
||||
* {ID}+ to match all TOK_IDs, but that would
|
||||
* also match TOK_MODE + TOK_END_OF_RULE
|
||||
* without any spaces in between (because it's
|
||||
* a longer match). So now, when I want to
|
||||
* match any random string, I go into a
|
||||
* separate state. */
|
||||
DUMP_PREPROCESS;
|
||||
yylval.id = processquoted(yytext, yyleng);
|
||||
PDEBUG("Found change profile quoted name: \"%s\"\n", yylval.id);
|
||||
yy_pop_state();
|
||||
return TOK_ID;
|
||||
}
|
||||
|
||||
{WS}+ { DUMP_PREPROCESS; /* Ignoring whitespace */ }
|
||||
[^\n] {
|
||||
@ -568,16 +519,9 @@ LT_EQUAL <=
|
||||
return TOK_CLOSE;
|
||||
}
|
||||
|
||||
{PATHNAME} {
|
||||
({PATHNAME}|{QPATHNAME}) {
|
||||
DUMP_PREPROCESS;
|
||||
yylval.id = processunquoted(yytext, yyleng);
|
||||
PDEBUG("Found id: \"%s\"\n", yylval.id);
|
||||
return TOK_ID;
|
||||
}
|
||||
|
||||
{QPATHNAME} {
|
||||
DUMP_PREPROCESS;
|
||||
yylval.id = processquoted(yytext, yyleng);
|
||||
yylval.id = processid(yytext, yyleng);
|
||||
PDEBUG("Found id: \"%s\"\n", yylval.id);
|
||||
return TOK_ID;
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
/* assistance routines */
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -397,6 +398,16 @@ char *processunquoted(char *string, int len)
|
||||
return tmp;
|
||||
}
|
||||
|
||||
char *processid(char *string, int len)
|
||||
{
|
||||
/* lexer should never call this fn if len <= 0 */
|
||||
assert(len > 0);
|
||||
|
||||
if (*string == '"')
|
||||
return processquoted(string, len);
|
||||
return processunquoted(string, len);
|
||||
}
|
||||
|
||||
/* rewrite a quoted string substituting escaped characters for the
|
||||
* real thing. Strip the quotes around the string */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user