regex checked by hyperscan directly with error messages
This commit is contained in:
@@ -50,6 +50,21 @@ void config_updater (){
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
|
||||
char * test_regex = getenv("FIREGEX_TEST_REGEX");
|
||||
if (test_regex != nullptr){
|
||||
cerr << "[info] [main] Testing regex: " << test_regex << endl;
|
||||
try{
|
||||
RegexRules::compile_regex(test_regex);
|
||||
cerr << "[info] [main] Test passed" << endl;
|
||||
return 0;
|
||||
}catch(const std::exception& e){
|
||||
cerr << "[error] [updater] Test failed" << endl;
|
||||
cout << e.what() << flush;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int n_of_threads = 1;
|
||||
char * n_threads_str = getenv("NTHREADS");
|
||||
if (n_threads_str != nullptr) n_of_threads = ::atoi(n_threads_str);
|
||||
|
||||
@@ -59,6 +59,26 @@ class RegexRules{
|
||||
public:
|
||||
regex_ruleset output_ruleset, input_ruleset;
|
||||
|
||||
static void compile_regex(char* regex){
|
||||
hs_database_t* db = nullptr;
|
||||
hs_compile_error_t *compile_err = nullptr;
|
||||
if (
|
||||
hs_compile(
|
||||
regex,
|
||||
HS_FLAG_SINGLEMATCH | HS_FLAG_ALLOWEMPTY,
|
||||
HS_MODE_BLOCK,
|
||||
nullptr, &db, &compile_err
|
||||
) != HS_SUCCESS
|
||||
) {
|
||||
string err = string(compile_err->message);
|
||||
hs_free_compile_error(compile_err);
|
||||
throw runtime_error(err);
|
||||
}else{
|
||||
hs_free_database(db);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
static inline u_int16_t glob_seq = 0;
|
||||
u_int16_t version;
|
||||
@@ -77,6 +97,8 @@ class RegexRules{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void fill_ruleset(vector<pair<string, decoded_regex>> & decoded, regex_ruleset & ruleset){
|
||||
size_t n_of_regex = decoded.size();
|
||||
if (n_of_regex == 0){
|
||||
|
||||
Reference in New Issue
Block a user