mirror of
https://gitlab.com/apparmor/apparmor.git
synced 2025-03-04 08:24:42 +01:00
Merge Fix parser lexer
The lexer is broken and passing echo input to stdout that it doesn't match in some states ignoring the error. First add `%option nodefault` to guarantee the lexer won't ever echo the unknown input to stdout, this will cause the parser to error out with ``` flex scanner jammed ``` and $?=2 if a profile contains unknown/invalid parts. That's not really a helpful error message, but still better than ignoring errors. Next improve the error message output, ``` AppArmor parser error for tst/simple_tests//vars/vars_simple_assignment_14.sd line 8: Lexer found unexpected character: ' ' (0xa) in state: SUB_ID_WS ``` using flex's error output only if there is an mistake made when introducing new states. Finally fix bugs that are found. MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/569 Acked-by: Steve Beattie <steve.beattie@canonical.com>
This commit is contained in:
commit
aeb1359b3d
2 changed files with 18 additions and 6 deletions
|
@ -25,6 +25,7 @@
|
|||
%option noyy_top_state
|
||||
%option nounput
|
||||
%option stack
|
||||
%option nodefault
|
||||
|
||||
%{
|
||||
#include <stdio.h>
|
||||
|
@ -264,7 +265,16 @@ LT_EQUAL <=
|
|||
LT <
|
||||
GT >
|
||||
|
||||
/* 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
|
||||
|
@ -466,6 +476,7 @@ GT >
|
|||
\\\n { DUMP_PREPROCESS; current_lineno++ ; }
|
||||
|
||||
\r?\n {
|
||||
/* don't use shared rule because we need POP() here */
|
||||
DUMP_PREPROCESS;
|
||||
current_lineno++;
|
||||
POP();
|
||||
|
@ -692,18 +703,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());
|
||||
}
|
||||
}
|
||||
%%
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#
|
||||
#=DESCRIPTION abi testing - abi relative path in quotes
|
||||
#=EXRESULT FAIL
|
||||
#=TODO
|
||||
|
||||
abi "simple_tests/includes/abi/4.19,
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue