mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 05:45:59 +03:00
cosmetic: Fix ValidateByteRange coding style.
This commit is contained in:
parent
8575c10781
commit
3a4cef6fb1
@ -32,7 +32,8 @@ bool ValidateByteRange::getRange(const std::string &rangeRepresentation,
|
||||
try {
|
||||
start = std::stoi(rangeRepresentation);
|
||||
} catch(...) {
|
||||
*error = ("Not able to convert '" + rangeRepresentation + "' into a number").c_str();
|
||||
*error = ("Not able to convert '" + rangeRepresentation +
|
||||
"' into a number").c_str();
|
||||
return false;
|
||||
}
|
||||
table[start >> 3] = (table[start >> 3] | (1 << (start & 0x7)));
|
||||
@ -42,7 +43,9 @@ bool ValidateByteRange::getRange(const std::string &rangeRepresentation,
|
||||
try {
|
||||
start = std::stoi(std::string(rangeRepresentation, 0, pos));
|
||||
} catch (...) {
|
||||
*error = ("Not able to convert '" + std::string(rangeRepresentation, 0, pos) + "' into a number").c_str();
|
||||
*error = ("Not able to convert '" +
|
||||
std::string(rangeRepresentation, 0, pos) +
|
||||
"' into a number").c_str();
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -50,13 +53,15 @@ bool ValidateByteRange::getRange(const std::string &rangeRepresentation,
|
||||
end = std::stoi(std::string(rangeRepresentation, pos + 1,
|
||||
rangeRepresentation.length() - (pos + 1)));
|
||||
} catch (...) {
|
||||
*error = ("Not able to convert '" + std::string(rangeRepresentation, pos + 1,
|
||||
rangeRepresentation.length() - (pos + 1)) + "' into a number").c_str();
|
||||
*error = ("Not able to convert '" + std::string(rangeRepresentation,
|
||||
pos + 1, rangeRepresentation.length() - (pos + 1)) +
|
||||
"' into a number").c_str();
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((start < 0) || (start > 255)) {
|
||||
*error = ("Invalid range start value: " + std::to_string(start)).c_str();
|
||||
*error = ("Invalid range start value: " +
|
||||
std::to_string(start)).c_str();
|
||||
return false;
|
||||
}
|
||||
if ((end < 0) || (end > 255)) {
|
||||
@ -69,7 +74,7 @@ bool ValidateByteRange::getRange(const std::string &rangeRepresentation,
|
||||
return false;
|
||||
}
|
||||
|
||||
while(start <= end) {
|
||||
while (start <= end) {
|
||||
table[start >> 3] = (table[start >> 3] | (1 << (start & 0x7)));
|
||||
start++;
|
||||
}
|
||||
@ -88,7 +93,8 @@ bool ValidateByteRange::init(const char **error) {
|
||||
while (pos != std::string::npos) {
|
||||
size_t next_pos = param.find_first_of(",", pos + 1);
|
||||
if (next_pos == std::string::npos) {
|
||||
getRange(std::string(param, pos + 1, param.length() - (pos + 1)), error);
|
||||
getRange(std::string(param, pos + 1, param.length() -
|
||||
(pos + 1)), error);
|
||||
} else {
|
||||
getRange(std::string(param, pos + 1, next_pos), error);
|
||||
}
|
||||
@ -97,24 +103,23 @@ bool ValidateByteRange::init(const char **error) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool ValidateByteRange::evaluate(Assay *assay, const std::string &input) {
|
||||
bool ret = true;
|
||||
|
||||
size_t count = 0;
|
||||
for(int i = 0; i < input.length(); i++) {
|
||||
for (int i = 0; i < input.length(); i++) {
|
||||
int x = input.at(i);
|
||||
if (!(table[x >> 3] & (1 << (x & 0x7)))) {
|
||||
//debug(9, "Value " + std::to_string(x) + " in " + input + " ouside range: " + param);
|
||||
// debug(9, "Value " + std::to_string(x) + " in " +
|
||||
// input + " ouside range: " + param);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
ret = (count != 0);
|
||||
//if (count == 0) return 0;
|
||||
|
||||
//debug(9, "Found %d byte(s) in %s outside range: %s.",
|
||||
//count, var->name, rule->op_param);
|
||||
// debug(9, "Found %d byte(s) in %s outside range: %s.",
|
||||
// count, var->name, rule->op_param);
|
||||
|
||||
if (negation) {
|
||||
return !ret;
|
||||
|
@ -17,6 +17,7 @@
|
||||
#define SRC_OPERATORS_VALIDATE_BYTE_RANGE_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "operators/operator.h"
|
||||
|
||||
@ -28,7 +29,7 @@ class ValidateByteRange : public Operator {
|
||||
public:
|
||||
/** @ingroup ModSecurity_Operator */
|
||||
ValidateByteRange(std::string op, std::string param, bool negation)
|
||||
: Operator(op, param, negation) { }
|
||||
: Operator(op, param, negation) { }
|
||||
|
||||
~ValidateByteRange() override { }
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user