Skip to content

Use internal PCRE based implementation of regular expressions instead of std C++ regex library. #1164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/multithread_c/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ multi_SOURCES = \
multi_LDADD = \
-L$(top_builddir)/src/.libs/ \
-lmodsecurity \
-lpthread \
$(YAJL_LDFLAGS) \
$(GEOIP_LDFLAGS) \
$(GLOBAL_LDADD)
Expand Down
2 changes: 2 additions & 0 deletions src/actions/ctl_audit_log_parts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ bool CtlAuditLogParts::init(std::string *error) {
} else {
mPartsAction = 1;
}

return true;
}

bool CtlAuditLogParts::evaluate(Rule *rule, Transaction *transaction) {
Expand Down
2 changes: 1 addition & 1 deletion src/actions/transformations/cmd_line.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ std::string CmdLine::evaluate(std::string value,
/* copy normal characters */
default :
char b = std::tolower(a);
ret.append(&b);
ret.append(&b, 1);
space = 0;
break;
}
Expand Down
1 change: 1 addition & 0 deletions src/parser/driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ int Driver::addSecMarker(std::string marker) {
rule->phase = i;
rules[i].push_back(rule);
}
return 0;
}


Expand Down
2 changes: 1 addition & 1 deletion src/parser/seclang-parser.yy
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
%skeleton "lalr1.cc" /* -*- C++ -*- */
%require "3.0"
%require "3.0.4"
%defines
%define parser_class_name {seclang_parser}
%define api.token.constructor
Expand Down
1 change: 1 addition & 0 deletions src/utils/regex.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class SMatch {
public:
SMatch() : size_(0) { }
size_t size() { return size_; }
std::string str() { return match; }
int size_;
std::string match;
};
Expand Down
14 changes: 7 additions & 7 deletions test/unit/unit_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
#include <string>
#include <iostream>
#include <iterator>
#include <regex>
#include <string>

#include "common/colors.h"
#include "src/utils.h"
#include "src/utils/regex.h"

namespace modsecurity_test {

Expand All @@ -44,7 +44,6 @@ std::string string_to_hex(const std::string& input) {
return output;
}


void replaceAll(std::string *s, const std::string &search,
const char replace) {
for (size_t pos = 0; ; pos += 0) {
Expand All @@ -59,18 +58,19 @@ void replaceAll(std::string *s, const std::string &search,


void json2bin(std::string *str) {
std::regex re("\\\\x([a-z0-9A-Z]{2})");
std::regex re2("\\\\u([a-z0-9A-Z]{4})");
std::smatch match;
modsecurity::Utils::Regex re("\\\\x([a-z0-9A-Z]{2})");
modsecurity::Utils::Regex re2("\\\\u([a-z0-9A-Z]{4})");
modsecurity::Utils::SMatch match;

while (std::regex_search(*str, match, re) && match.size() > 1) {
while (modsecurity::Utils::regex_search(*str, &match, re) && match.size() > 0) {
unsigned int p;
std::string toBeReplaced = match.str();
toBeReplaced.erase(0, 2);
sscanf(toBeReplaced.c_str(), "%x", &p);
replaceAll(str, match.str(), p);
}
while (std::regex_search(*str, match, re2) && match.size() > 1) {

while (modsecurity::Utils::regex_search(*str, &match, re2) && match.size() > 0) {
unsigned int p;
std::string toBeReplaced = match.str();
toBeReplaced.erase(0, 2);
Expand Down