mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 05:45:59 +03:00
Not using pcrecpp on verifycc anymore
This commit is contained in:
parent
4168ebc2b3
commit
2a062b7fe2
@ -15,8 +15,9 @@
|
||||
|
||||
#include "operators/verify_cc.h"
|
||||
|
||||
#include <pcrecpp.h>
|
||||
#include <iostream>
|
||||
#include <pcre.h>
|
||||
#include <cstring>
|
||||
|
||||
#include "operators/operator.h"
|
||||
|
||||
@ -66,16 +67,47 @@ int VerifyCC::luhnVerify(const char *ccnumber, int len) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool VerifyCC::init(const std::string ¶m2, const char **error) {
|
||||
std::vector<std::string> vec;
|
||||
const char *errptr = NULL;
|
||||
int erroffset = 0;
|
||||
|
||||
m_pc = pcre_compile(param.c_str(), PCRE_DOTALL|PCRE_MULTILINE,
|
||||
&errptr, &erroffset, NULL);
|
||||
m_pce = pcre_study(m_pc, PCRE_STUDY_JIT_COMPILE, &errptr);
|
||||
|
||||
if ((m_pc == NULL) || (m_pce == NULL)) {
|
||||
*error = errptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool VerifyCC::evaluate(Assay *assay, const std::string &i) {
|
||||
int offset = 0;
|
||||
bool is_cc = false;
|
||||
int target_length = i.length();
|
||||
|
||||
for (offset = 0; offset < target_length; offset++) {
|
||||
std::string shiftedString(i, offset, i.length() - offset);
|
||||
std::string match;
|
||||
pcrecpp::StringPiece input(shiftedString);
|
||||
while (m_re.FindAndConsume(&input, &match)) {
|
||||
int ovector[33];
|
||||
memset(ovector, 0, sizeof(ovector));
|
||||
int ret = pcre_exec(m_pc, m_pce, i.c_str(), i.size(), offset,
|
||||
0, ovector, 33) > 0;
|
||||
|
||||
/* If there was no match, then we are done. */
|
||||
if (ret == PCRE_ERROR_NOMATCH) {
|
||||
break;
|
||||
}
|
||||
if (ret < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ret > 0) {
|
||||
match = std::string(i, ovector[0], ovector[1] - ovector[0]);
|
||||
is_cc = luhnVerify(match.c_str(), match.size());
|
||||
if (is_cc) {
|
||||
if (assay) {
|
||||
|
@ -16,9 +16,8 @@
|
||||
#ifndef SRC_OPERATORS_VERIFY_CC_H_
|
||||
#define SRC_OPERATORS_VERIFY_CC_H_
|
||||
|
||||
#include <pcrecpp.h>
|
||||
|
||||
#include <string>
|
||||
#include <pcre.h>
|
||||
|
||||
#include "operators/operator.h"
|
||||
|
||||
@ -29,14 +28,14 @@ class VerifyCC : public Operator {
|
||||
public:
|
||||
/** @ingroup ModSecurity_Operator */
|
||||
VerifyCC(std::string op, std::string param, bool negation)
|
||||
: Operator(op, param, negation),
|
||||
m_re(param, pcrecpp::RE_Options()) { }
|
||||
: Operator(op, param, negation) { }
|
||||
|
||||
int luhnVerify(const char *ccnumber, int len);
|
||||
bool evaluate(Assay *assay, const std::string &input) override;
|
||||
|
||||
bool init(const std::string ¶m, const char **error) override;
|
||||
private:
|
||||
pcrecpp::RE m_re;
|
||||
pcre *m_pc;
|
||||
pcre_extra *m_pce;
|
||||
};
|
||||
|
||||
} // namespace operators
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit e363aa647abebe1be523f9bdd5ba4466ba20256e
|
||||
Subproject commit 37cf32eb8f939c06923a9ab24dd56a0975c36d4a
|
Loading…
x
Reference in New Issue
Block a user