Skip to content

Commit 5226c42

Browse files
WGH-zimmerle
authored andcommitted
1 parent 1e14d64 commit 5226c42

16 files changed

+51
-192
lines changed

CHANGES

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
v3.x.y - YYYY-MMM-DD (to be released)
22
-------------------------------------
3-
3+
4+
- Removed unnecessary while processing the transformations.
5+
[#2368 - @WGH-, @zimmerle]
46
- auditlog: Computes whether or not to save while loading the rules.
57
[@zimmerle]
68
- actions: Computes Rule association while loading the rules given a

src/actions/transformations/css_decode.cc

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,10 @@ namespace transformations {
3232
void CssDecode::execute(const Transaction *t,
3333
const ModSecString &in,
3434
ModSecString &out) noexcept {
35-
size_t s = in.size();
36-
37-
char *tmp = reinterpret_cast<char *>(
38-
malloc(sizeof(char) * s + 1));
39-
memcpy(tmp, in.c_str(), s + 1);
40-
tmp[s] = '\0';
41-
42-
size_t r = CssDecode::css_decode_inplace(
43-
reinterpret_cast<unsigned char *>(tmp),
44-
s);
45-
46-
out.assign(tmp, r);
47-
free(tmp);
35+
out.assign(in);
36+
auto size = CssDecode::css_decode_inplace(
37+
reinterpret_cast<unsigned char *>(&out[0]), out.size());
38+
out.resize(size);
4839
}
4940

5041

src/actions/transformations/escape_seq_decode.cc

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,11 @@ int EscapeSeqDecode::ansi_c_sequences_decode_inplace(unsigned char *input,
135135
void EscapeSeqDecode::execute(const Transaction *t,
136136
const ModSecString &in,
137137
ModSecString &out) noexcept {
138-
unsigned char *tmp = (unsigned char *) malloc(sizeof(char)
139-
* in.size() + 1);
140-
memcpy(tmp, in.c_str(), in.size() + 1);
141-
tmp[in.size()] = '\0';
142-
143-
int size = ansi_c_sequences_decode_inplace(tmp, in.size());
144-
out.assign(reinterpret_cast<char *>(tmp), size);
145-
free(tmp);
138+
139+
out.assign(in);
140+
auto size = ansi_c_sequences_decode_inplace(
141+
reinterpret_cast<unsigned char *>(&out[0]), out.size());
142+
out.resize(size);
146143
}
147144

148145
} // namespace transformations

src/actions/transformations/hex_decode.cc

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,10 @@ namespace transformations {
3434
void HexDecode::execute(const Transaction *t,
3535
const ModSecString &in,
3636
ModSecString &out) noexcept {
37-
unsigned char *input;
38-
int size = 0;
39-
40-
input = reinterpret_cast<unsigned char *>
41-
(malloc(sizeof(char) * in.length()+1));
42-
43-
if (input == NULL) {
44-
return;
45-
}
46-
47-
memcpy(input, in.c_str(), in.length()+1);
48-
49-
size = inplace(input, in.length());
50-
51-
out.assign(reinterpret_cast<char *>(input), size);
52-
free(input);
37+
out.assign(in);
38+
auto size = inplace(reinterpret_cast<unsigned char *>(
39+
&out[0]), out.length());
40+
out.resize(size);
5341
}
5442

5543

src/actions/transformations/html_entity_decode.cc

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,10 @@ namespace transformations {
3232
void HtmlEntityDecode::execute(const Transaction *t,
3333
const ModSecString &in,
3434
ModSecString &out) noexcept {
35-
unsigned char *input;
36-
37-
input = reinterpret_cast<unsigned char *>
38-
(malloc(sizeof(char) * in.length()+1));
39-
40-
if (input == NULL) {
41-
return;
42-
}
43-
44-
memcpy(input, in.c_str(), in.length()+1);
45-
46-
size_t i = inplace(input, in.length());
47-
48-
out.assign(reinterpret_cast<char *>(input), i);
49-
free(input);
35+
out.assign(in);
36+
auto i = inplace(reinterpret_cast<unsigned char *>(
37+
&out[0]), out.length());
38+
out.resize(i);
5039
}
5140

5241

src/actions/transformations/js_decode.cc

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,11 @@ namespace transformations {
3232
void JsDecode::execute(const Transaction *t,
3333
const ModSecString &in,
3434
ModSecString &out) noexcept {
35-
unsigned char *input;
3635

37-
input = reinterpret_cast<unsigned char *>
38-
(malloc(sizeof(char) * in.length()+1));
39-
40-
if (input == NULL) {
41-
return;
42-
}
43-
44-
memcpy(input, in.c_str(), in.length()+1);
45-
46-
size_t i = inplace(input, in.length());
47-
48-
out.assign(reinterpret_cast<char *>(input), i);
49-
free(input);
36+
out.assign(in);
37+
auto i = inplace(reinterpret_cast<unsigned char *>(
38+
&out[0]), out.length());
39+
out.resize(i);
5040
}
5141

5242

src/actions/transformations/normalise_path.cc

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,9 @@ void NormalisePath::execute(const Transaction *t,
3131
const ModSecString &in,
3232
ModSecString &out) noexcept {
3333
int changed = 0;
34-
35-
char *tmp = reinterpret_cast<char *>(
36-
malloc(sizeof(char) * in.size() + 1));
37-
memcpy(tmp, in.c_str(), in.size() + 1);
38-
tmp[in.size()] = '\0';
39-
40-
int i = normalize_path_inplace((unsigned char *)tmp,
41-
in.size(), 0, &changed);
42-
43-
std::string ret("");
44-
out.assign(tmp, i);
45-
free(tmp);
34+
out.assign(in);
35+
auto size = normalize_path_inplace(reinterpret_cast<unsigned char *>(&out[0]), out.length(), 0, &changed);
36+
out.resize(size);
4637
}
4738

4839

src/actions/transformations/normalise_path_win.cc

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,10 @@ void NormalisePathWin::execute(const Transaction *t,
3636
ModSecString &out) noexcept {
3737
int changed;
3838

39-
char *tmp = reinterpret_cast<char *>(
40-
malloc(sizeof(char) * in.size() + 1));
41-
memcpy(tmp, in.c_str(), in.size() + 1);
42-
tmp[in.size()] = '\0';
43-
44-
int i = NormalisePath::normalize_path_inplace(
45-
reinterpret_cast<unsigned char *>(tmp),
46-
in.size(), 1, &changed);
47-
48-
std::string ret("");
49-
out.assign(tmp, i);
50-
free(tmp);
39+
out.assign(in);
40+
auto size = NormalisePath::normalize_path_inplace(
41+
reinterpret_cast<unsigned char *>(&out[0]), out.length(), 1, &changed);
42+
out.resize(size);
5143
}
5244

5345

src/actions/transformations/parity_even_7bit.cc

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,8 @@ namespace transformations {
3030
void ParityEven7bit::execute(const Transaction *t,
3131
const ModSecString &in,
3232
ModSecString &out) noexcept {
33-
unsigned char *input;
34-
35-
input = reinterpret_cast<unsigned char *>
36-
(malloc(sizeof(char) * in.length()+1));
37-
38-
if (input == NULL) {
39-
return;
40-
}
41-
42-
std::memcpy(input, in.c_str(), in.length()+1);
43-
44-
inplace(input, in.length());
45-
46-
out.assign(reinterpret_cast<char *>(input), in.length());
47-
free(input);
33+
out.assign(in);
34+
inplace(reinterpret_cast<unsigned char*>(&out[0]), out.size());
4835
}
4936

5037

src/actions/transformations/parity_odd_7bit.cc

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,8 @@ namespace transformations {
3030
void ParityOdd7bit::execute(const Transaction *t,
3131
const ModSecString &in,
3232
ModSecString &out) noexcept {
33-
unsigned char *input;
34-
35-
input = reinterpret_cast<unsigned char *>
36-
(malloc(sizeof(char) * in.length()+1));
37-
38-
if (input == NULL) {
39-
return;
40-
}
41-
42-
memcpy(input, in.c_str(), in.length()+1);
43-
44-
inplace(input, in.length());
45-
46-
out.assign(reinterpret_cast<char *>(input), in.length());
47-
free(input);
33+
out.assign(in);
34+
inplace(reinterpret_cast<unsigned char *>(&out[0]), out.length());
4835
}
4936

5037

0 commit comments

Comments
 (0)