mirror of
https://gitlab.com/apparmor/apparmor.git
synced 2025-03-04 08:24:42 +01:00
parser: Fix invalid reference to transitions when building the chfa
States are not guaranteed to have transitions, but when inserting
a state into the chfa table there is an unconditional dereference
to the states first transition.
This will result in a bad reference and could result in an OOB
flag being set on the state when it shouldn't be.
Fixes: 16b67ddbd
("add ability to use out of band transitions"
Closes: https://gitlab.com/apparmor/apparmor/-/issues/290
Reported-by: Nobel Barakat <nobelbarakat@google.com>
Reported-by: Oleksandr Tymoshenko <ovt@google.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
This commit is contained in:
parent
2bd9962611
commit
27d738c874
1 changed files with 11 additions and 3 deletions
|
@ -193,9 +193,8 @@ void CHFA::insert_state(vector<pair<size_t, size_t> > &free_list,
|
|||
State *default_state = dfa.nonmatching;
|
||||
ssize_t base = 0;
|
||||
int resize;
|
||||
|
||||
StateTrans &trans = from->trans;
|
||||
ssize_t c = trans.begin()->first.c;
|
||||
ssize_t c;
|
||||
ssize_t prev = 0;
|
||||
ssize_t x = first_free;
|
||||
|
||||
|
@ -204,6 +203,7 @@ void CHFA::insert_state(vector<pair<size_t, size_t> > &free_list,
|
|||
if (trans.empty())
|
||||
goto do_insert;
|
||||
|
||||
c = trans.begin()->first.c;
|
||||
repeat:
|
||||
resize = 0;
|
||||
/* get the first free entry that won't underflow */
|
||||
|
@ -251,10 +251,18 @@ repeat:
|
|||
first_free = next;
|
||||
}
|
||||
|
||||
do_insert:
|
||||
/* these flags will only be set on states that have transitions */
|
||||
if (c < 0) {
|
||||
base |= MATCH_FLAG_OOB_TRANSITION;
|
||||
}
|
||||
do_insert:
|
||||
/* While a state without transitions could have the diff encode
|
||||
* flag set, it would be pointless resulting in just an extra
|
||||
* state transition in the encoding chain, and so it should be
|
||||
* considered an error
|
||||
* TODO: add check that state without transitions isn't being
|
||||
* given a diffencode flag
|
||||
*/
|
||||
if (from->flags & DiffEncodeFlag)
|
||||
base |= DiffEncodeBit32;
|
||||
default_base.push_back(make_pair(default_state, base));
|
||||
|
|
Loading…
Add table
Reference in a new issue