mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-11-18 02:10:36 +03:00
Remove unnecessary copying in transformations
In C++11, string data is always null-terminated[1], and can be freely modified[2]. [1] https://stackoverflow.com/questions/6077189/will-stdstring-always-be-null-terminated-in-c11 [2] https://stackoverflow.com/questions/38875623/is-it-permitted-to-modify-the-internal-stdstring-buffer-returned-by-operator
This commit is contained in:
@@ -30,21 +30,8 @@ namespace transformations {
|
||||
void ParityZero7bit::execute(const Transaction *t,
|
||||
const ModSecString &in,
|
||||
ModSecString &out) noexcept {
|
||||
unsigned char *input;
|
||||
|
||||
input = reinterpret_cast<unsigned char *>
|
||||
(malloc(sizeof(char) * in.length()+1));
|
||||
|
||||
if (input == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(input, in.c_str(), in.length()+1);
|
||||
|
||||
inplace(input, in.length());
|
||||
|
||||
out.assign(reinterpret_cast<char *>(input), in.length());
|
||||
free(input);
|
||||
out.assign(in);
|
||||
inplace(reinterpret_cast<unsigned char *>(&out[0]), out.length());
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user