mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-29 19:24:29 +03:00
Adds suppor for HyperScan in the bulid system
This commit is contained in:
@@ -25,14 +25,23 @@
|
||||
#include <list>
|
||||
#include <memory>
|
||||
|
||||
#ifdef WITH_HS
|
||||
#include <hs.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "src/operators/operator.h"
|
||||
#ifndef WITH_HS
|
||||
#include "src/utils/acmp.h"
|
||||
#endif
|
||||
#include "src/utils/string.h"
|
||||
|
||||
namespace modsecurity {
|
||||
namespace operators {
|
||||
|
||||
Pm::~Pm() {
|
||||
#ifdef WITH_HS
|
||||
#else
|
||||
acmp_node_t *root = m_p->root_node;
|
||||
|
||||
cleanup(root);
|
||||
@@ -42,9 +51,10 @@ Pm::~Pm() {
|
||||
#ifdef MODSEC_MUTEX_ON_PM
|
||||
pthread_mutex_destroy(&m_lock);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#ifndef WITH_HS
|
||||
void Pm::cleanup(acmp_node_t *n) {
|
||||
if (n == NULL) {
|
||||
return;
|
||||
@@ -67,8 +77,9 @@ void Pm::cleanup(acmp_node_t *n) {
|
||||
|
||||
free(n);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef WITH_HS
|
||||
void Pm::postOrderTraversal(acmp_btree_node_t *node) {
|
||||
if (node == NULL) {
|
||||
return;
|
||||
@@ -79,10 +90,14 @@ void Pm::postOrderTraversal(acmp_btree_node_t *node) {
|
||||
|
||||
free(node);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
bool Pm::evaluate(Transaction *transaction, RuleWithActions *rule,
|
||||
const std::string &input, std::shared_ptr<RuleMessage> ruleMessage) {
|
||||
#ifdef WITH_HS
|
||||
return 0;
|
||||
#else
|
||||
int rc;
|
||||
ACMPT pt;
|
||||
pt.parser = m_p;
|
||||
@@ -110,10 +125,16 @@ bool Pm::evaluate(Transaction *transaction, RuleWithActions *rule,
|
||||
}
|
||||
|
||||
return rc >= 0;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool Pm::init(const std::string &file, std::string *error) {
|
||||
#ifdef WITH_HS
|
||||
fprintf(stdout, "Sopport for HS is on the way: %s\n", hs_version());
|
||||
#else
|
||||
std::vector<std::string> vec;
|
||||
std::istringstream *iss;
|
||||
const char *err = NULL;
|
||||
@@ -146,7 +167,7 @@ bool Pm::init(const std::string &file, std::string *error) {
|
||||
}
|
||||
|
||||
delete iss;
|
||||
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -34,11 +34,17 @@ class Pm : public Operator {
|
||||
/** @ingroup ModSecurity_Operator */
|
||||
explicit Pm(std::unique_ptr<RunTimeString> param)
|
||||
: Operator("Pm", std::move(param)) {
|
||||
#ifdef WITH_HS
|
||||
#else
|
||||
m_p = acmp_create(0);
|
||||
#endif
|
||||
}
|
||||
explicit Pm(const std::string &n, std::unique_ptr<RunTimeString> param)
|
||||
: Operator(n, std::move(param)) {
|
||||
#ifdef WITH_HS
|
||||
#else
|
||||
m_p = acmp_create(0);
|
||||
#endif
|
||||
}
|
||||
~Pm();
|
||||
bool evaluate(Transaction *transaction, RuleWithActions *rule,
|
||||
@@ -47,17 +53,23 @@ class Pm : public Operator {
|
||||
|
||||
|
||||
bool init(const std::string &file, std::string *error) override;
|
||||
#ifndef WITH_HS
|
||||
void postOrderTraversal(acmp_btree_node_t *node);
|
||||
void cleanup(acmp_node_t *n);
|
||||
#endif
|
||||
|
||||
protected:
|
||||
#ifndef WITH_HS
|
||||
ACMP *m_p;
|
||||
|
||||
#ifdef MODSEC_MUTEX_ON_PM
|
||||
#endif
|
||||
|
||||
private:
|
||||
#ifndef WITH_HS
|
||||
#ifdef MODSEC_MUTEX_ON_PM
|
||||
pthread_mutex_t m_lock;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@@ -68,13 +68,18 @@ bool PmFromFile::init(const std::string &config, std::string *error) {
|
||||
|
||||
for (std::string line; std::getline(*iss, line); ) {
|
||||
if (isComment(line) == false) {
|
||||
#ifdef WITH_HS
|
||||
#else
|
||||
acmp_add_pattern(m_p, line.c_str(), NULL, NULL, line.length());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef WITH_HS
|
||||
while (m_p->is_failtree_done == 0) {
|
||||
acmp_prepare(m_p);
|
||||
}
|
||||
#endif
|
||||
|
||||
delete iss;
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user