mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-13 21:36:00 +03:00
Adds missing file: rules_exceptions
This commit is contained in:
parent
f723870f18
commit
7f7bd99843
97
src/rules_exceptions.cc
Normal file
97
src/rules_exceptions.cc
Normal file
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* ModSecurity, http://www.modsecurity.org/
|
||||
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
|
||||
*
|
||||
* You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* If any of the files related to licensing are missing or if you have any
|
||||
* other questions related to licensing please contact Trustwave Holdings, Inc.
|
||||
* directly using the email address security@modsecurity.org.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "modsecurity/rules_exceptions.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/utils.h"
|
||||
|
||||
namespace modsecurity {
|
||||
|
||||
|
||||
bool RulesExceptions::load(const std::string &a, std::string *error) {
|
||||
std::vector<std::string> toRemove = modsecurity::split(a, ' ');
|
||||
for (std::string &a : toRemove) {
|
||||
std::string b = removeBracketsIfNeeded(a);
|
||||
|
||||
size_t dash = b.find('-');
|
||||
if (dash != std::string::npos) {
|
||||
std::string n1s = std::string(b, 0, dash);
|
||||
std::string n2s = std::string(b, dash + 1, b.size() - (dash + 1));
|
||||
int n1n = 0;
|
||||
int n2n = 0;
|
||||
try {
|
||||
n1n = std::stoi(n1s);
|
||||
} catch (...) {
|
||||
error->assign("Not a number: " + n1s);
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
n2n = std::stoi(n2s);
|
||||
} catch (...) {
|
||||
error->assign("Not a number: " + n2s);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (n1s > n2s) {
|
||||
error->assign("Invalid range: " + b);
|
||||
return false;
|
||||
}
|
||||
addRange(n1n, n2n);
|
||||
} else {
|
||||
try {
|
||||
int num = std::stoi(b);
|
||||
addNumber(num);
|
||||
} catch (...) {
|
||||
error->assign("Not a number or range: " + b);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool RulesExceptions::addNumber(int a) {
|
||||
m_numbers.push_back(a);
|
||||
}
|
||||
|
||||
|
||||
bool RulesExceptions::addRange(int a, int b) {
|
||||
m_ranges.push_back(std::make_pair(a, b));
|
||||
}
|
||||
|
||||
|
||||
bool RulesExceptions::contains(int a) {
|
||||
for (int z : m_numbers) {
|
||||
if (a == z) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto z : m_ranges) {
|
||||
if (z.first <= a && z.second >= a) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
} // namespace modsecurity
|
||||
|
Loading…
x
Reference in New Issue
Block a user