[apparmor] parser: [patch 3/3] parser: allow alternation comma in LIST_VAL_ID
john.johansen at canonical.com
john.johansen at canonical.com
Thu Nov 6 01:19:43 UTC 2014
currently , is not a valid character in a LIST_VAL_ID because it is
also used as a id seperator.
ie. one,two,three are separate list value items
however this means that an aare alternation is not a valid list item
unless it is quoted
{one,two},three
vs.
"{one,two}",three
we can "fix" this by tracking that the id is in an alternation and only
using the comma as a separator if the id is not currently in an alternation.
This does have the downside that if an alternation is not properly closed
then the list val id becomes all the characters until the id is ended
by ws, however this is no worse than failing to close quotes.
Signed-off-by: John Johansen <john.johansen at canonical.com>
---
parser/parser_lex.l | 38 +++++++++++++++++++++++++++++++++++++-
1 file changed, 37 insertions(+), 1 deletion(-)
--- 3.0-diff.orig/parser/parser_lex.l
+++ 3.0-diff/parser/parser_lex.l
@@ -113,6 +113,7 @@
#define STATE_TABLE_ENT(X) {X, #X }
extern unordered_map<int, string> state_names;
+int altdepth;
struct cb_struct {
const char *fullpath;
@@ -211,7 +212,7 @@
IDS {ID}+
POST_VAR_ID_CHARS [^ \t\n"!,]{-}[=\+]
POST_VAR_ID {POST_VAR_ID_CHARS}|(,{POST_VAR_ID_CHARS}|\\[ ]|\\\t|\\\"|\\!|\\,|\\\(|\\\))
-LIST_VALUE_ID_CHARS ([^ \t\n"!,]{-}[()]|\\[ ]|\\\t|\\\"|\\!|\\,|\\\(|\\\))
+LIST_VALUE_ID_CHARS ([^ \t\n"!,{]{-}[()]|\\[ ]|\\\t|\\\"|\\!|\\,|\\\(|\\\)|\\\{|{SET_VARIABLE}|{BOOL_VARIABLE})
LIST_VALUE_ID {LIST_VALUE_ID_CHARS}+
ID_CHARS_NOEQ [^ \t\n"!,]{-}[=]
LEADING_ID_CHARS_NOEQ [^ \t\n"!,]{-}[=()+&]
@@ -247,6 +248,7 @@
%x EXTCOND_MODE
%x EXTCONDLIST_MODE
%x NETWORK_MODE
+%x LIST_VAL_ID_ALTERNATION
%x LIST_VAL_MODE
%x LIST_COND_MODE
%x LIST_COND_VAL
@@ -362,7 +364,34 @@
in { RETURN_TOKEN(TOK_IN); }
}
+<LIST_VAL_ID_ALTERNATION>{
+ {LIST_VALUE_ID}-{CLOSE_BRACE} { yymore(); }
+ {OPEN_BRACE} { altdepth++; yymore(); }
+ {CLOSE_BRACE} {
+ if (altdepth > 0)
+ altdepth--;
+ yymore();
+ }
+ {COMMA} {
+ if (altdepth > 0) {
+ yymore();
+ } else {
+ yyless(1);
+ POP_AND_RETURN(TOK_VALUE);
+ }
+ }
+ . {
+ yyless(1);
+ POP_AND_RETURN(TOK_VALUE);
+ }
+}
+
<LIST_COND_VAL>{
+ {OPEN_BRACE}|{LIST_VALUE_ID}/{OPEN_BRACE} {
+ yymore();
+ altdepth = 1;
+ BEGIN(LIST_VAL_ID_ALTERNATION);
+ }
({LIST_VALUE_ID}|{QUOTED_ID}) {
yylval.id = processid(yytext, yyleng);
POP_AND_RETURN(TOK_VALUE);
@@ -374,6 +403,12 @@
}
<LIST_VAL_MODE,LIST_COND_PAREN_VAL>{
+ {OPEN_BRACE}|{LIST_VALUE_ID}/{OPEN_BRACE} {
+ yymore();
+ altdepth = 1;
+ /* so that POP_AND_RETURN acts like RETURN_TOKEN */
+ PUSH(LIST_VAL_ID_ALTERNATION);
+ }
({LIST_VALUE_ID}|{QUOTED_ID}) {
yylval.id = processid(yytext, yyleng);
RETURN_TOKEN(TOK_VALUE);
@@ -646,6 +681,7 @@
STATE_TABLE_ENT(EXTCOND_MODE),
STATE_TABLE_ENT(EXTCONDLIST_MODE),
STATE_TABLE_ENT(NETWORK_MODE),
+ STATE_TABLE_ENT(LIST_VAL_ID_ALTERNATION),
STATE_TABLE_ENT(LIST_VAL_MODE),
STATE_TABLE_ENT(LIST_COND_MODE),
STATE_TABLE_ENT(LIST_COND_VAL),
More information about the AppArmor
mailing list