Skip to content

Commit c81ef34

Browse files
Easton97-Jensjens
authored andcommitted
Update libinjection_adapter.cc
1 parent b6e629f commit c81ef34

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

src/operators/libinjection_adapter.cc

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,16 @@
88

99
namespace modsecurity::operators {
1010
namespace {
11+
1112
// Per-thread overrides avoid cross-thread interference during mtstress tests.
12-
thread_local DetectSQLiFn g_sqli_override = nullptr;
13-
thread_local DetectXSSFn g_xss_override = nullptr;
13+
// Intentional design:
14+
// - thread_local to isolate tests across threads
15+
// - function pointers to keep zero-overhead call path
16+
// - mutable for test injection hooks
17+
// NOSONAR: required for testing override mechanism (see set*OverrideForTesting)
18+
thread_local DetectSQLiFn g_sqli_override = nullptr; // NOSONAR
19+
thread_local DetectXSSFn g_xss_override = nullptr; // NOSONAR
20+
1421
}
1522

1623
injection_result_t runLibinjectionSQLi(const char *input, size_t len,
@@ -30,11 +37,15 @@ injection_result_t runLibinjectionXSS(const char *input, size_t len) {
3037
return libinjection_xss(input, len);
3138
}
3239

33-
void setLibinjectionSQLiOverrideForTesting(DetectSQLiFn fn) {
40+
// Test-only hook: allows injecting alternative detection functions
41+
// NOSONAR: function pointer is intentional (no std::function overhead)
42+
void setLibinjectionSQLiOverrideForTesting(DetectSQLiFn fn) { // NOSONAR
3443
g_sqli_override = fn;
3544
}
3645

37-
void setLibinjectionXSSOverrideForTesting(DetectXSSFn fn) {
46+
// Test-only hook: allows injecting alternative detection functions
47+
// NOSONAR: function pointer is intentional (no std::function overhead)
48+
void setLibinjectionXSSOverrideForTesting(DetectXSSFn fn) { // NOSONAR
3849
g_xss_override = fn;
3950
}
4051

0 commit comments

Comments
 (0)