mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 05:45:59 +03:00
Use internal PCRE based implementation of regular expressions instead of std C++ regex library.
C++ regex library proven to be unusable for gcc 4.8 and earlier version, so reimplement code using PCRE library in order to build workable version of unit_test executable for CentOS 7, RHEL 7, Ubuntu 14 and SUSE Linux 12.
This commit is contained in:
parent
21777aec41
commit
647019a804
@ -43,6 +43,7 @@ class SMatch {
|
||||
public:
|
||||
SMatch() : size_(0) { }
|
||||
size_t size() { return size_; }
|
||||
std::string str() { return match; }
|
||||
int size_;
|
||||
std::string match;
|
||||
};
|
||||
|
@ -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 {
|
||||
|
||||
@ -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) {
|
||||
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user