mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-30 11:44:32 +03:00
Cosmetic changes: applies changes suggested by static analysis
This commit is contained in:
@@ -35,21 +35,36 @@ class Action {
|
||||
public:
|
||||
explicit Action(const std::string& _action)
|
||||
: action_kind(2),
|
||||
m_isNone(false),
|
||||
m_name(""),
|
||||
m_parser_payload(""),
|
||||
m_isNone(false),
|
||||
temporaryAction(false) {
|
||||
set_name_and_payload(_action);
|
||||
}
|
||||
explicit Action(const std::string& _action, int kind)
|
||||
: action_kind(kind),
|
||||
m_isNone(false),
|
||||
m_name(""),
|
||||
m_parser_payload(""),
|
||||
m_isNone(false),
|
||||
temporaryAction(false) {
|
||||
set_name_and_payload(_action);
|
||||
}
|
||||
|
||||
virtual ~Action() { }
|
||||
|
||||
virtual std::string evaluate(std::string exp,
|
||||
Transaction *transaction);
|
||||
virtual bool evaluate(Rule *rule, Transaction *transaction);
|
||||
virtual bool evaluate(Rule *rule, Transaction *transaction,
|
||||
RuleMessage *ruleMessage) {
|
||||
return evaluate(rule, transaction);
|
||||
}
|
||||
virtual bool init(std::string *error) { return true; }
|
||||
virtual bool isDisruptive() { return false; }
|
||||
virtual void fillIntervention(ModSecurityIntervention *intervention);
|
||||
static Action *instantiate(const std::string& name);
|
||||
|
||||
|
||||
void set_name_and_payload(const std::string& data) {
|
||||
size_t pos = data.find(":");
|
||||
std::string t = "t:";
|
||||
@@ -72,7 +87,12 @@ class Action {
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~Action() { }
|
||||
bool m_isNone;
|
||||
bool temporaryAction;
|
||||
int action_kind;
|
||||
std::string m_name;
|
||||
std::string m_parser_payload;
|
||||
|
||||
/**
|
||||
*
|
||||
* Define the action kind regarding to the execution time.
|
||||
@@ -106,27 +126,6 @@ class Action {
|
||||
};
|
||||
|
||||
|
||||
virtual std::string evaluate(std::string exp,
|
||||
Transaction *transaction);
|
||||
virtual bool evaluate(Rule *rule, Transaction *transaction);
|
||||
virtual bool evaluate(Rule *rule, Transaction *transaction,
|
||||
RuleMessage *ruleMessage) {
|
||||
return evaluate(rule, transaction);
|
||||
}
|
||||
|
||||
virtual bool init(std::string *error) { return true; }
|
||||
|
||||
virtual bool isDisruptive() { return false; }
|
||||
|
||||
virtual void fillIntervention(ModSecurityIntervention *intervention);
|
||||
|
||||
static Action *instantiate(const std::string& name);
|
||||
|
||||
bool temporaryAction;
|
||||
std::string m_name;
|
||||
std::string m_parser_payload;
|
||||
bool m_isNone;
|
||||
int action_kind;
|
||||
};
|
||||
|
||||
|
||||
|
@@ -47,9 +47,8 @@ namespace actions {
|
||||
|
||||
|
||||
bool Msg::evaluate(Rule *rule, Transaction *transaction) {
|
||||
std::string msg = MacroExpansion::expand(m_parser_payload, transaction);
|
||||
|
||||
#ifndef NO_LOGS
|
||||
std::string msg = MacroExpansion::expand(m_parser_payload, transaction);
|
||||
transaction->debug(9, "Saving msg: " + msg);
|
||||
#endif
|
||||
|
||||
|
@@ -100,9 +100,8 @@ int HtmlEntityDecode::inplace(unsigned char *input, u_int64_t input_len) {
|
||||
if (j > k) { /* Do we have at least one digit? */
|
||||
/* Decode the entity. */
|
||||
char *x = NULL;
|
||||
x = reinterpret_cast<char *>(malloc(sizeof(char) *
|
||||
x = reinterpret_cast<char *>(calloc(sizeof(char),
|
||||
((j - k) + 1)));
|
||||
memset(x, '\0', (j - k) + 1);
|
||||
memcpy(x, (const char *)&input[k], j - k);
|
||||
*d++ = (unsigned char)strtol(x, NULL, 16);
|
||||
free(x);
|
||||
@@ -127,9 +126,8 @@ int HtmlEntityDecode::inplace(unsigned char *input, u_int64_t input_len) {
|
||||
if (j > k) { /* Do we have at least one digit? */
|
||||
/* Decode the entity. */
|
||||
char *x = NULL;
|
||||
x = reinterpret_cast<char *>(malloc(sizeof(char) *
|
||||
x = reinterpret_cast<char *>(calloc(sizeof(char),
|
||||
((j - k) + 1)));
|
||||
memset(x, '\0', (j - k) + 1);
|
||||
memcpy(x, (const char *)&input[k], j - k);
|
||||
*d++ = (unsigned char)strtol(x, NULL, 10);
|
||||
free(x);
|
||||
@@ -154,9 +152,8 @@ int HtmlEntityDecode::inplace(unsigned char *input, u_int64_t input_len) {
|
||||
}
|
||||
if (j > k) { /* Do we have at least one digit? */
|
||||
char *x = NULL;
|
||||
x = reinterpret_cast<char *>(malloc(sizeof(char) *
|
||||
x = reinterpret_cast<char *>(calloc(sizeof(char),
|
||||
((j - k) + 1)));
|
||||
memset(x, '\0', (j - k) + 1);
|
||||
memcpy(x, (const char *)&input[k], j - k);
|
||||
|
||||
/* Decode the entity. */
|
||||
|
@@ -47,14 +47,12 @@ std::string RemoveComments::evaluate(std::string value,
|
||||
|
||||
u_int64_t input_len = value.size();
|
||||
u_int64_t i, j, incomment;
|
||||
int changed = 0;
|
||||
|
||||
i = j = incomment = 0;
|
||||
while (i < input_len) {
|
||||
if (incomment == 0) {
|
||||
if ((input[i] == '/') && (i + 1 < input_len)
|
||||
&& (input[i + 1] == '*')) {
|
||||
changed = 1;
|
||||
incomment = 1;
|
||||
i += 2;
|
||||
} else if ((input[i] == '<') && (i + 1 < input_len)
|
||||
@@ -62,15 +60,12 @@ std::string RemoveComments::evaluate(std::string value,
|
||||
&& (input[i+2] == '-') && (i + 3 < input_len)
|
||||
&& (input[i + 3] == '-') && (incomment == 0)) {
|
||||
incomment = 1;
|
||||
changed = 1;
|
||||
i += 4;
|
||||
} else if ((input[i] == '-') && (i + 1 < input_len)
|
||||
&& (input[i + 1] == '-') && (incomment == 0)) {
|
||||
changed = 1;
|
||||
input[i] = ' ';
|
||||
break;
|
||||
} else if (input[i] == '#' && (incomment == 0)) {
|
||||
changed = 1;
|
||||
input[i] = ' ';
|
||||
break;
|
||||
} else {
|
||||
|
@@ -59,10 +59,10 @@ std::string Utf8ToUnicode::evaluate(std::string value,
|
||||
|
||||
char *Utf8ToUnicode::inplace(unsigned char *input,
|
||||
uint64_t input_len, int *changed) {
|
||||
int unicode_len = 0, length = 0;
|
||||
unsigned int d = 0, count = 0;
|
||||
unsigned char c, *utf;
|
||||
char *rval, *data;
|
||||
int length = 0;
|
||||
unsigned int count = 0;
|
||||
unsigned char c;
|
||||
char *data;
|
||||
unsigned int i, len, j;
|
||||
unsigned int bytes_left = input_len;
|
||||
unsigned char unicode[8];
|
||||
@@ -75,12 +75,14 @@ char *Utf8ToUnicode::inplace(unsigned char *input,
|
||||
}
|
||||
|
||||
if (input == NULL) {
|
||||
free(data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < bytes_left;) {
|
||||
unicode_len = 0; d = 0;
|
||||
utf = (unsigned char *)&input[i];
|
||||
int unicode_len = 0;
|
||||
unsigned int d = 0;
|
||||
unsigned char *utf = (unsigned char *)&input[i];
|
||||
|
||||
c = *utf;
|
||||
|
||||
@@ -293,7 +295,7 @@ char *Utf8ToUnicode::inplace(unsigned char *input,
|
||||
|
||||
*data ='\0';
|
||||
|
||||
return NULL;
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user