File tree Expand file tree Collapse file tree 2 files changed +12
-34
lines changed
src/actions/transformations Expand file tree Collapse file tree 2 files changed +12
-34
lines changed Original file line number Diff line number Diff line change 21
21
namespace modsecurity ::actions::transformations {
22
22
23
23
24
- bool HexDecode::transform (std::string &value, const Transaction *trans) const {
25
- std::string ret;
26
- unsigned char *input;
27
- int size = 0 ;
24
+ static inline int inplace (std::string &value) {
25
+ if (value.empty ()) return false ;
28
26
29
- input = reinterpret_cast <unsigned char *>
30
- (malloc (sizeof (char ) * value.length ()+1 ));
27
+ const auto len = value.length ();
28
+ auto d = reinterpret_cast <unsigned char *>(value.data ());
29
+ const auto data = d;
31
30
32
- if (input == NULL ) {
33
- return " " ;
31
+ for ( int i = 0 ; i <= len - 2 ; i += 2 ) {
32
+ *d++ = utils::string::x2c (&data[i]) ;
34
33
}
35
34
36
- memcpy (input, value.c_str (), value.length ()+1 );
37
-
38
- size = inplace (input, value.length ());
39
-
40
- ret.assign (reinterpret_cast <char *>(input), size);
41
- free (input);
35
+ *d = ' \0 ' ;
42
36
43
- const auto changed = ret != value;
44
- value = ret;
45
- return changed;
37
+ value.resize (d - data);
38
+ return true ;
46
39
}
47
40
48
41
49
- int HexDecode::inplace (unsigned char *data, int len) {
50
- unsigned char *d = data;
51
- int count = 0 ;
52
-
53
- if ((data == NULL ) || (len == 0 )) {
54
- return 0 ;
55
- }
56
-
57
- for (int i = 0 ;i <= len - 2 ;i += 2 ) {
58
- *d++ = utils::string::x2c (&data[i]);
59
- count++;
60
- }
61
- *d = ' \0 ' ;
62
-
63
- return count;
42
+ bool HexDecode::transform (std::string &value, const Transaction *trans) const {
43
+ return inplace (value);
64
44
}
65
45
66
46
Original file line number Diff line number Diff line change @@ -26,8 +26,6 @@ class HexDecode : public Transformation {
26
26
: Transformation(action) { }
27
27
28
28
bool transform (std::string &value, const Transaction *trans) const override ;
29
-
30
- static int inplace (unsigned char *data, int len);
31
29
};
32
30
33
31
} // namespace modsecurity::actions::transformations
You can’t perform that action at this time.
0 commit comments