Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
07d7c15
Fix sign-compare warning in anchored set variable translation proxy
mikelolasagasti May 15, 2026
24082e4
Fix unused-function warnings for intervention helpers in header
mikelolasagasti May 15, 2026
31e7891
Fix sign-compare warning in utils::string::limitTo
mikelolasagasti May 15, 2026
60be1f8
Fix -Wreorder in VariableDictElement constructor
mikelolasagasti May 15, 2026
7e6a012
Fix -Wreorder in VariableRegex constructor
mikelolasagasti May 15, 2026
df27bbb
Fix sign-compare warning in InitCol::init
mikelolasagasti May 15, 2026
9e463d0
Fix sign-compare warnings in ModSecurity::processContentOffset
mikelolasagasti May 15, 2026
1d7a263
Fix -Wreorder in Rx and RxGlobal constructor
mikelolasagasti May 15, 2026
dde96c3
Fix sign-compare warning in RulesSet::evaluate
mikelolasagasti May 15, 2026
2024bb5
Remove unused variables in seclang parser runtime-var rules
mikelolasagasti May 15, 2026
fc0f225
Fix compiler warnings in msc_tree.cc
mikelolasagasti May 15, 2026
d57f8a2
Fix snprintf and sign-compare warnings in utf8_to_unicode
mikelolasagasti May 15, 2026
3805e4f
Fix sign-compare warning in html_entity_decode
mikelolasagasti May 15, 2026
f8f0638
Fix sign-compare warning in CompressWhitespace::transform
mikelolasagasti May 15, 2026
3d553e5
Fix sign-compare warning in Multipart::process_part_data
mikelolasagasti May 15, 2026
85aefe6
Fix sign-compare warnings in ValidateUrlEncoding
mikelolasagasti May 15, 2026
371bcd9
Fix sign-compare warning in PmFromFile::isComment
mikelolasagasti May 15, 2026
a4e56e5
Fix sign-compare warning in Driver::addSecRule
mikelolasagasti May 15, 2026
90be376
Fix -Wreorder in Transaction constructor
mikelolasagasti May 15, 2026
b09eb4b
Fix sign-compare in Transaction::processRequestBody
mikelolasagasti May 15, 2026
eb777f4
Avoid undefined behavior in PmFromFile::isComment
mikelolasagasti Jun 30, 2026
193e52f
Free YAJL generator on processContentOffset errors
mikelolasagasti Jun 30, 2026
7e7a96e
Refactor UTF-8 Unicode escape emission
mikelolasagasti Jul 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class AnchoredSetVariableTranslationProxy {
m_fount(fount)
{
m_translate = [](const std::string *name, std::vector<const VariableValue *> *l) {
for (int i = 0; i < l->size(); ++i) {
for (std::vector<const VariableValue *>::size_type i = 0;
i < l->size(); ++i) {
VariableValue *newVariableValue = new VariableValue(name, &l->at(i)->getKey(), &l->at(i)->getKey());
const VariableValue *oldVariableValue = l->at(i);
l->at(i) = newVariableValue;
Expand Down
10 changes: 5 additions & 5 deletions headers/modsecurity/intervention.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,33 @@ typedef struct ModSecurityIntervention_t {

#ifdef __cplusplus
namespace intervention {
static void reset(ModSecurityIntervention_t *i) {
inline void reset(ModSecurityIntervention_t *i) {
i->status = 200;
i->pause = 0;
i->disruptive = 0;
}

static void clean(ModSecurityIntervention_t *i) {
inline void clean(ModSecurityIntervention_t *i) {
i->url = NULL;
i->log = NULL;
reset(i);
}

static void freeUrl(ModSecurityIntervention_t *i) {
inline void freeUrl(ModSecurityIntervention_t *i) {
if (i->url) {
free(i->url);
i->url = NULL;
}
}

static void freeLog(ModSecurityIntervention_t *i) {
inline void freeLog(ModSecurityIntervention_t *i) {
if (i->log) {
free(i->log);
i->log = NULL;
}
}

static void free(ModSecurityIntervention_t *i) {
inline void free(ModSecurityIntervention_t *i) {
freeUrl(i);
freeLog(i);
}
Expand Down
2 changes: 1 addition & 1 deletion src/actions/init_col.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace actions {


bool InitCol::init(std::string *error) {
int posEquals = m_parser_payload.find("=");
const std::string::size_type posEquals = m_parser_payload.find("=");

if (m_parser_payload.size() < 2) {
error->assign("Something wrong with initcol format: too small");
Expand Down
4 changes: 2 additions & 2 deletions src/actions/transformations/compress_whitespace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ bool CompressWhitespace::transform(std::string &value, const Transaction *trans)
}
}

const auto new_len = d - value.c_str();
const auto changed = new_len != value.length();
const auto new_len = static_cast<std::string::size_type>(d - value.data());
const bool changed = new_len != value.length();
value.resize(new_len);
return changed;
}
Expand Down
2 changes: 1 addition & 1 deletion src/actions/transformations/html_entity_decode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ static inline bool inplace(std::string &value) {

HTML_ENT_OUT:

for (auto z = 0; z < copy; z++) {
for (std::string::size_type z = 0; z < copy; z++) {
*d++ = input[i++];
}
}
Expand Down
122 changes: 46 additions & 76 deletions src/actions/transformations/utf8_to_unicode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#include "utf8_to_unicode.h"

#include <cstring>
#include <cstdio>

#include "src/utils/string.h"

Expand All @@ -27,6 +27,42 @@ constexpr int UNICODE_ERROR_INVALID_ENCODING = -2;
namespace modsecurity::actions::transformations {


static inline bool writeUnicodeEscape(char *&data, char *unicode,
size_t unicode_size, unsigned int d) {
*data++ = '%';
*data++ = 'u';
const int written = std::snprintf(unicode, unicode_size, "%x", d);
if (written < 0 || static_cast<size_t>(written) >= unicode_size) {
return false;
}

const auto length = static_cast<size_t>(written);
switch (length) {
case 1:
*data++ = '0';
*data++ = '0';
*data++ = '0';
break;
case 2:
*data++ = '0';
*data++ = '0';
break;
case 3:
*data++ = '0';
break;
case 4:
case 5:
break;
}

for (size_t j = 0; j < length; j++) {
*data++ = unicode[j];
}

return true;
}


static inline bool encode(std::string &value) {
auto input = reinterpret_cast<unsigned char*>(value.data());
const auto input_len = value.length();
Expand Down Expand Up @@ -78,33 +114,11 @@ static inline bool encode(std::string &value) {
unicode_len = 2;
count += 6;
if (count <= len) {
int length = 0;
/* compute character number */
d = ((c & 0x1F) << 6) | (*(utf + 1) & 0x3F);
*data++ = '%';
*data++ = 'u';
length = snprintf(unicode, sizeof(unicode), "%x", d);

switch (length) {
case 1:
*data++ = '0';
*data++ = '0';
*data++ = '0';
break;
case 2:
*data++ = '0';
*data++ = '0';
break;
case 3:
*data++ = '0';
break;
case 4:
case 5:
break;
}

for (int j = 0; j < length; j++) {
*data++ = unicode[j];
if (writeUnicodeEscape(data, unicode,
sizeof(unicode), d) == false) {
return changed;
}

changed = true;
Expand All @@ -125,35 +139,13 @@ static inline bool encode(std::string &value) {
unicode_len = 3;
count+=6;
if (count <= len) {
int length = 0;
/* compute character number */
d = ((c & 0x0F) << 12)
| ((*(utf + 1) & 0x3F) << 6)
| (*(utf + 2) & 0x3F);
*data++ = '%';
*data++ = 'u';
length = snprintf(unicode, sizeof(unicode), "%x", d);

switch (length) {
case 1:
*data++ = '0';
*data++ = '0';
*data++ = '0';
break;
case 2:
*data++ = '0';
*data++ = '0';
break;
case 3:
*data++ = '0';
break;
case 4:
case 5:
break;
}

for (int j = 0; j < length; j++) {
*data++ = unicode[j];
if (writeUnicodeEscape(data, unicode,
sizeof(unicode), d) == false) {
return changed;
}

changed = true;
Expand Down Expand Up @@ -183,36 +175,14 @@ static inline bool encode(std::string &value) {
unicode_len = 4;
count+=7;
if (count <= len) {
int length = 0;
/* compute character number */
d = ((c & 0x07) << 18)
| ((*(utf + 1) & 0x3F) << 12)
| ((*(utf + 2) & 0x3F) << 6)
| (*(utf + 3) & 0x3F);
*data++ = '%';
*data++ = 'u';
length = snprintf(unicode, sizeof(unicode), "%x", d);

switch (length) {
case 1:
*data++ = '0';
*data++ = '0';
*data++ = '0';
break;
case 2:
*data++ = '0';
*data++ = '0';
break;
case 3:
*data++ = '0';
break;
case 4:
case 5:
break;
}

for (int j = 0; j < length; j++) {
*data++ = unicode[j];
if (writeUnicodeEscape(data, unicode,
sizeof(unicode), d) == false) {
return changed;
}

changed = true;
Expand Down
6 changes: 4 additions & 2 deletions src/modsecurity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,9 @@ int ModSecurity::processContentOffset(const char *content, size_t len,
size.size());
yajl_gen_map_close(g);

if (stoi(startingAt) >= len) {
if (static_cast<size_t>(stoi(startingAt)) >= len) {
*err = "Offset is out of the content limits.";
yajl_gen_free(g);
return -1;
}

Expand Down Expand Up @@ -347,8 +348,9 @@ int ModSecurity::processContentOffset(const char *content, size_t len,
size.size());
yajl_gen_map_close(g);

if (stoi(startingAt) >= varValue.size()) {
if (static_cast<size_t>(stoi(startingAt)) >= varValue.size()) {
*err = "Offset is out of the variable limits.";
yajl_gen_free(g);
return -1;
}
yajl_gen_string(g,
Expand Down
4 changes: 2 additions & 2 deletions src/operators/pm_from_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ bool PmFromFile::isComment(const std::string &s) {
}
size_t pos = s.find("#");
if (pos != std::string::npos) {
for (int i = 0; i < pos; i++) {
if (!std::isspace(s[i])) {
for (size_t i = 0; i < pos; i++) {
if (!std::isspace(static_cast<unsigned char>(s[i]))) {
return false;
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/operators/rx.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ class Rx : public Operator {
public:
/** @ingroup ModSecurity_Operator */
explicit Rx(std::unique_ptr<RunTimeString> param)
: m_re(nullptr),
Operator("Rx", std::move(param)) {
: Operator("Rx", std::move(param)) {
m_couldContainsMacro = true;
}

Expand All @@ -59,7 +58,7 @@ class Rx : public Operator {
bool init(const std::string &arg, std::string *error) override;

private:
Regex *m_re;
Regex *m_re = nullptr;
};


Expand Down
5 changes: 2 additions & 3 deletions src/operators/rx_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ class RxGlobal : public Operator {
public:
/** @ingroup ModSecurity_Operator */
explicit RxGlobal(std::unique_ptr<RunTimeString> param)
: m_re(nullptr),
Operator("RxGlobal", std::move(param)) {
: Operator("RxGlobal", std::move(param)) {
m_couldContainsMacro = true;
}

Expand All @@ -59,7 +58,7 @@ class RxGlobal : public Operator {
bool init(const std::string &arg, std::string *error) override;

private:
Regex *m_re;
Regex *m_re = nullptr;
};


Expand Down
3 changes: 1 addition & 2 deletions src/operators/validate_url_encoding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ namespace operators {

int ValidateUrlEncoding::validate_url_encoding(const char *input,
uint64_t input_length, size_t *offset) {
int i;
uint64_t i = 0;
*offset = 0;

if ((input == NULL) || (input_length == 0)) {
return -1;
}

i = 0;
while (i < input_length) {
if (input[i] == '%') {
if (i + 2 >= input_length) {
Expand Down
2 changes: 1 addition & 1 deletion src/parser/driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ int Driver::addSecRule(std::unique_ptr<RuleWithActions> r) {

for (int i = 0; i < modsecurity::Phases::NUMBER_OF_PHASES; i++) {
const Rules *rules = m_rulesSetPhases[i];
for (int j = 0; j < rules->size(); j++) {
for (size_t j = 0; j < rules->size(); j++) {
const RuleWithOperator *lr = dynamic_cast<RuleWithOperator *>(rules->at(j).get());
if (lr && lr->m_ruleId == rule->m_ruleId) {
m_parserError << "Rule id: " << std::to_string(rule->m_ruleId) \
Expand Down
Loading
Loading