2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-30 13:58:22 +00:00

Merge Fix lexer 2.13

This is a backport of the fix-lexer patch series for 2.13

Atm it has more patches than are strictly necessary. The open question is how much of that series do we actually want to bring back?

technically the only patch we need to keep CI working and fix the issues that have been discovered are

```
Remove TODO for half-quoted abi rule
parser: split newline and end of rule handling into separate rules
parser: update rule to process newlines to include states that eat WS
parser: add ABI_MODE to WS consumption state
```

However that would keep us from being able to catch other errors. If we want to be able to catch other potential lexer pass-through errors, at a minimum we need to include.

```
Error out on unhandled parts when parsing a profile
```

Which excludes only

```
parser: add missing states to the default rule and improve the error msg
```

While its nice to have better debug output, I am not sure it is worth backporting this patch
Summary of Discussion: The debug output is worth having

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/572
Acked-by: Steve Beattie <sbeattie@ubuntu.com>
This commit is contained in:
John Johansen
2020-07-21 22:53:20 +00:00
2 changed files with 19 additions and 7 deletions

View File

@@ -24,6 +24,7 @@
%option noyywrap
%option nounput
%option stack
%option nodefault
%{
#include <stdio.h>
@@ -240,7 +241,16 @@ ADD_ASSIGN \+=
ARROW ->
LT_EQUAL <=
/* IF adding new state please update state_names table at eof */
/* IF adding new state please update state_names table and default rule (just
* above the state_names table) at the eof.
*
* The nodefault option is set so missing adding to the default rule isn't
* fatal but can't take advantage of additional debug the default rule might
* have.
*
* If a state is not added to the default rule it can result in the message
* "flex scanner jammed"
*/
%x SUB_ID
%x SUB_ID_WS
%x SUB_VALUE
@@ -274,7 +284,7 @@ LT_EQUAL <=
}
%}
<INITIAL,SUB_ID_WS,INCLUDE,INCLUDE_EXISTS,LIST_VAL_MODE,EXTCOND_MODE,LIST_COND_VAL,LIST_COND_PAREN_VAL,LIST_COND_MODE,EXTCONDLIST_MODE,ASSIGN_MODE,NETWORK_MODE,CHANGE_PROFILE_MODE,RLIMIT_MODE,MOUNT_MODE,DBUS_MODE,SIGNAL_MODE,PTRACE_MODE,UNIX_MODE>{
<INITIAL,SUB_ID_WS,INCLUDE,INCLUDE_EXISTS,LIST_VAL_MODE,EXTCOND_MODE,LIST_COND_VAL,LIST_COND_PAREN_VAL,LIST_COND_MODE,EXTCONDLIST_MODE,ASSIGN_MODE,NETWORK_MODE,CHANGE_PROFILE_MODE,RLIMIT_MODE,MOUNT_MODE,DBUS_MODE,SIGNAL_MODE,PTRACE_MODE,UNIX_MODE,ABI_MODE>{
{WS}+ { DUMP_PREPROCESS; /* Ignoring whitespace */ }
}
@@ -469,6 +479,7 @@ LT_EQUAL <=
\\\n { DUMP_PREPROCESS; current_lineno++ ; }
\r?\n {
/* don't use shared rule because we need POP() here */
DUMP_PREPROCESS;
current_lineno++;
POP();
@@ -695,18 +706,20 @@ include/{WS} {
POP_NODUMP();
RETURN_TOKEN(TOK_END_OF_RULE);
}
}
\r?\n {
<INITIAL,SUB_ID_WS,INCLUDE,INCLUDE_EXISTS,LIST_VAL_MODE,EXTCOND_MODE,LIST_COND_VAL,LIST_COND_PAREN_VAL,LIST_COND_MODE,EXTCONDLIST_MODE,NETWORK_MODE,CHANGE_PROFILE_MODE,RLIMIT_MODE,MOUNT_MODE,DBUS_MODE,SIGNAL_MODE,PTRACE_MODE,UNIX_MODE,ABI_MODE>{
\r?\n {
DUMP_PREPROCESS;
current_lineno++;
}
}
<INITIAL,SUB_ID,SUB_ID_WS,SUB_VALUE,LIST_VAL_MODE,EXTCOND_MODE,LIST_COND_VAL,LIST_COND_PAREN_VAL,LIST_COND_MODE,EXTCONDLIST_MODE,ASSIGN_MODE,NETWORK_MODE,CHANGE_PROFILE_MODE,MOUNT_MODE,DBUS_MODE,SIGNAL_MODE,PTRACE_MODE,UNIX_MODE>{
[^\n] {
<INITIAL,SUB_ID,SUB_ID_WS,SUB_VALUE,LIST_VAL_MODE,EXTCOND_MODE,LIST_COND_VAL,LIST_COND_PAREN_VAL,LIST_COND_MODE,EXTCONDLIST_MODE,ASSIGN_MODE,NETWORK_MODE,CHANGE_PROFILE_MODE,MOUNT_MODE,DBUS_MODE,SIGNAL_MODE,PTRACE_MODE,UNIX_MODE,RLIMIT_MODEINCLUDE,INCLUDE_EXISTS,ABI_MODE>{
(.|\n) {
DUMP_PREPROCESS;
/* Something we didn't expect */
yyerror(_("Found unexpected character: '%s'"), yytext);
yyerror(_("Lexer found unexpected character: '%s' (0x%x) in state: %s"), yytext, yytext[0], state_names[YY_START].c_str());
}
}
%%

View File

@@ -1,7 +1,6 @@
#
#=DESCRIPTION abi testing - abi relative path in quotes
#=EXRESULT FAIL
#=TODO
abi "abi/4.19,