mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-22 10:07:12 +00:00
Add basic string matching to the hfa
Add the ability to match strings directly from the hfa instead of needing to build a cfha. Signed-off-by: John Johansen <john.johansen@canonical.com> Acked-By: Steve Beattie <sbeattie@ubuntu.com>
This commit is contained in:
parent
47280bb483
commit
3ff8b4d19a
@ -30,6 +30,7 @@
|
|||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "expr-tree.h"
|
#include "expr-tree.h"
|
||||||
#include "hfa.h"
|
#include "hfa.h"
|
||||||
@ -267,6 +268,19 @@ DFA::~DFA()
|
|||||||
delete *i;
|
delete *i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
State *DFA::match_len(State *state, const char *str, size_t len)
|
||||||
|
{
|
||||||
|
for (; len > 0; ++str, --len)
|
||||||
|
state = state->next(*str);
|
||||||
|
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
State *DFA::match(const char *str)
|
||||||
|
{
|
||||||
|
return match_len(start, str, strlen(str));
|
||||||
|
}
|
||||||
|
|
||||||
void DFA::dump_uniq_perms(const char *s)
|
void DFA::dump_uniq_perms(const char *s)
|
||||||
{
|
{
|
||||||
set<pair<uint32_t, uint32_t> > uniq;
|
set<pair<uint32_t, uint32_t> > uniq;
|
||||||
|
@ -275,6 +275,13 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
State *next(uchar c) {
|
||||||
|
StateTrans::iterator i = trans.find(c);
|
||||||
|
if (i != trans.end())
|
||||||
|
return i->second;
|
||||||
|
return otherwise;
|
||||||
|
};
|
||||||
|
|
||||||
int label;
|
int label;
|
||||||
uint32_t audit, accept;
|
uint32_t audit, accept;
|
||||||
StateTrans trans;
|
StateTrans trans;
|
||||||
@ -341,6 +348,9 @@ public:
|
|||||||
DFA(Node *root, dfaflags_t flags);
|
DFA(Node *root, dfaflags_t flags);
|
||||||
virtual ~DFA();
|
virtual ~DFA();
|
||||||
|
|
||||||
|
State *match_len(State *state, const char *str, size_t len);
|
||||||
|
State *match(const char *str);
|
||||||
|
|
||||||
void remove_unreachable(dfaflags_t flags);
|
void remove_unreachable(dfaflags_t flags);
|
||||||
bool same_mappings(State *s1, State *s2);
|
bool same_mappings(State *s1, State *s2);
|
||||||
size_t hash_trans(State *s);
|
size_t hash_trans(State *s);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user