Skip to content

Commit 9ce8550

Browse files
committed
sonarqubecloud error corrected
1 parent ffdc044 commit 9ce8550

18 files changed

+135
-174
lines changed

src/operators/validate_byte_range.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,10 @@ bool ValidateByteRange::init(const std::string &file,
145145

146146
while (true) {
147147
const std::string::size_type nextPos = m_param.find(',', pos);
148-
const std::string token = nextPos == std::string::npos
149-
? m_param.substr(pos)
150-
: m_param.substr(pos, nextPos - pos);
151-
152-
if (getRange(token, &parsedTable, error) == false) {
148+
if (const std::string token = nextPos == std::string::npos
149+
? m_param.substr(pos)
150+
: m_param.substr(pos, nextPos - pos);
151+
getRange(token, &parsedTable, error) == false) {
153152
/*
154153
* Keep byte 0 allowed on invalid parameters so callers that
155154
* continue after init() failure keep legacy behaviour.

src/request_body_processor/json.cc

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
#include "src/request_body_processor/json_instrumentation.h"
2828

2929

30-
namespace modsecurity {
31-
namespace RequestBodyProcessor {
30+
namespace modsecurity::RequestBodyProcessor {
3231

3332
static const double json_depth_limit_default = 10000.0;
3433
static const char* json_depth_limit_exceeded_msg = ". Parsing depth limit exceeded";
@@ -126,10 +125,8 @@ bool JSON::complete(std::string *err) {
126125
}
127126

128127
JSONAdapter adapter;
129-
JsonParseResult result = adapter.parse(m_data,
130-
static_cast<JsonEventSink *>(this));
131-
132-
if (!result.ok()) {
128+
if (JsonParseResult result = adapter.parse(m_data,
129+
static_cast<JsonEventSink *>(this)); !result.ok()) {
133130
if (result.sink_status == JsonSinkStatus::DepthLimitExceeded) {
134131
m_depth_limit_exceeded = true;
135132
}
@@ -285,5 +282,4 @@ void JSON::clearContainers() {
285282
}
286283
}
287284

288-
} // namespace RequestBodyProcessor
289-
} // namespace modsecurity
285+
} // namespace modsecurity::RequestBodyProcessor

src/request_body_processor/json.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
#include "src/request_body_processor/json_backend.h"
2525

2626

27-
namespace modsecurity {
28-
namespace RequestBodyProcessor {
27+
namespace modsecurity::RequestBodyProcessor {
2928

3029

3130
class JSONContainer {
@@ -114,7 +113,6 @@ class JSON : public JsonEventSink {
114113
};
115114

116115

117-
} // namespace RequestBodyProcessor
118-
} // namespace modsecurity
116+
} // namespace modsecurity::RequestBodyProcessor
119117

120118
#endif // SRC_REQUEST_BODY_PROCESSOR_JSON_H_

src/request_body_processor/json_adapter.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919

2020
#include "src/config.h"
2121

22-
namespace modsecurity {
23-
namespace RequestBodyProcessor {
22+
namespace modsecurity::RequestBodyProcessor {
2423
namespace {
2524

2625
JsonParseResult makeResult(JsonParseStatus parse_status,
@@ -100,5 +99,4 @@ JsonParseResult JSONAdapter::parse(const std::string &input,
10099
#endif
101100
}
102101

103-
} // namespace RequestBodyProcessor
104-
} // namespace modsecurity
102+
} // namespace modsecurity::RequestBodyProcessor

src/request_body_processor/json_adapter.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020

2121
#include "src/request_body_processor/json_backend.h"
2222

23-
namespace modsecurity {
24-
namespace RequestBodyProcessor {
23+
namespace modsecurity::RequestBodyProcessor {
2524

2625
class JSONAdapter {
2726
public:
@@ -32,7 +31,6 @@ class JSONAdapter {
3231
const JsonBackendParseOptions &options = JsonBackendParseOptions()) const;
3332
};
3433

35-
} // namespace RequestBodyProcessor
36-
} // namespace modsecurity
34+
} // namespace modsecurity::RequestBodyProcessor
3735

3836
#endif // SRC_REQUEST_BODY_PROCESSOR_JSON_ADAPTER_H_

src/request_body_processor/json_backend.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
#include <string>
2020
#include <string_view>
2121

22-
namespace modsecurity {
23-
namespace RequestBodyProcessor {
22+
namespace modsecurity::RequestBodyProcessor {
2423

2524
enum class JsonParseStatus {
2625
Ok,
@@ -77,7 +76,6 @@ JsonParseResult parseDocumentWithSimdjson(std::string &input,
7776
JsonParseResult parseDocumentWithJsoncons(const std::string &input,
7877
JsonEventSink *sink, const JsonBackendParseOptions &options);
7978

80-
} // namespace RequestBodyProcessor
81-
} // namespace modsecurity
79+
} // namespace modsecurity::RequestBodyProcessor
8280

8381
#endif // SRC_REQUEST_BODY_PROCESSOR_JSON_BACKEND_H_

src/request_body_processor/json_backend_jsoncons.cc

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333
#include <jsoncons/json_options.hpp>
3434
#include <jsoncons/semantic_tag.hpp>
3535

36-
namespace modsecurity {
37-
namespace RequestBodyProcessor {
36+
namespace modsecurity::RequestBodyProcessor {
3837
namespace {
3938

4039
JsonParseResult makeResult(JsonParseStatus parse_status,
@@ -305,8 +304,8 @@ class RawJsonTokenCursor {
305304

306305
void skipInsignificantAt(std::size_t *offset) const {
307306
while (*offset < m_input.size()) {
308-
char current = m_input[*offset];
309-
if (isWhitespace(current) || current == ',' || current == ':') {
307+
if (char current = m_input[*offset];
308+
isWhitespace(current) || current == ',' || current == ':') {
310309
(*offset)++;
311310
continue;
312311
}
@@ -382,8 +381,7 @@ class RawJsonTokenCursor {
382381
return false;
383382
}
384383

385-
char escaped = m_input[(*offset)++];
386-
if (escaped == 'u') {
384+
if (char escaped = m_input[(*offset)++]; escaped == 'u') {
387385
for (int i = 0; i < 4; i++) {
388386
if (*offset >= m_input.size()
389387
|| !isHexDigit(m_input[*offset])) {
@@ -546,9 +544,8 @@ std::string_view rawNumberFromContext(const std::string &input,
546544
jsoncons::staj_event_type event_type, const jsoncons::ser_context &context,
547545
const jsoncons::staj_event &event, std::string_view scanned_token) {
548546
const std::size_t begin = context.begin_position();
549-
const std::size_t end = context.end_position();
550-
551-
if (begin < end && end <= input.size()) {
547+
if (const std::size_t end = context.end_position();
548+
begin < end && end <= input.size()) {
552549
std::string_view candidate(input.data() + begin, end - begin);
553550
if (tokenMatchesNumericEvent(event_type, candidate)) {
554551
return candidate;
@@ -625,8 +622,8 @@ JsonParseResult emitEvent(const std::string &input, JsonEventSink *sink,
625622
return fromJsonconsError(error, context);
626623
}
627624
if (isNumericStringEvent(event)) {
628-
const std::string_view decoded_number(decoded.data(), decoded.size());
629-
if (isValidJsonNumber(decoded_number)
625+
if (const std::string_view decoded_number(decoded.data(),
626+
decoded.size()); isValidJsonNumber(decoded_number)
630627
&& token_cursor->advanceExactNumber(decoded_number,
631628
&sync_detail)) {
632629
recordJsonconsTokenExactAdvanceStep();
@@ -756,9 +753,8 @@ JsonParseResult parseDocumentWithJsoncons(const std::string &input,
756753
#endif
757754

758755
while (!cursor.done()) {
759-
JsonParseResult result = emitEvent(input, sink, &token_cursor,
760-
cursor.current(), cursor.context());
761-
if (!result.ok()) {
756+
if (JsonParseResult result = emitEvent(input, sink, &token_cursor,
757+
cursor.current(), cursor.context()); !result.ok()) {
762758
#ifdef MSC_JSON_AUDIT_INSTRUMENTATION
763759
record_event_loop();
764760
#endif
@@ -788,5 +784,4 @@ JsonParseResult parseDocumentWithJsoncons(const std::string &input,
788784
return makeResult(JsonParseStatus::Ok);
789785
}
790786

791-
} // namespace RequestBodyProcessor
792-
} // namespace modsecurity
787+
} // namespace modsecurity::RequestBodyProcessor

src/request_body_processor/json_backend_simdjson.cc

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
#include "src/request_body_processor/json_instrumentation.h"
3030
#include "simdjson.h"
3131

32-
namespace modsecurity {
33-
namespace RequestBodyProcessor {
32+
namespace modsecurity::RequestBodyProcessor {
3433
namespace {
3534

3635
JsonParseResult makeResult(JsonParseStatus parse_status,
@@ -97,8 +96,8 @@ std::size_t effectiveTechnicalMaxDepth(
9796

9897
std::string_view trimTrailingJsonWhitespace(std::string_view token) {
9998
while (!token.empty()) {
100-
const char tail = token.back();
101-
if (tail != ' ' && tail != '\t' && tail != '\n' && tail != '\r') {
99+
if (const char tail = token.back();
100+
tail != ' ' && tail != '\t' && tail != '\n' && tail != '\r') {
102101
break;
103102
}
104103
token.remove_suffix(1);
@@ -220,8 +219,8 @@ class JsonBackendWalker {
220219
return result;
221220
}
222221

223-
JsonSinkStatus sink_status = m_sink->on_string(decoded);
224-
if (sink_status != JsonSinkStatus::Continue) {
222+
if (JsonSinkStatus sink_status = m_sink->on_string(decoded);
223+
sink_status != JsonSinkStatus::Continue) {
225224
return stopTraversal(sink_status, "handling a root string");
226225
}
227226
return makeResult(JsonParseStatus::Ok);
@@ -233,9 +232,9 @@ class JsonBackendWalker {
233232
return result;
234233
}
235234

236-
JsonSinkStatus sink_status = m_sink->on_number(
237-
trimTrailingJsonWhitespace(raw_number));
238-
if (sink_status != JsonSinkStatus::Continue) {
235+
if (JsonSinkStatus sink_status = m_sink->on_number(
236+
trimTrailingJsonWhitespace(raw_number));
237+
sink_status != JsonSinkStatus::Continue) {
239238
return stopTraversal(sink_status, "handling a root number");
240239
}
241240
return makeResult(JsonParseStatus::Ok);
@@ -247,8 +246,9 @@ class JsonBackendWalker {
247246
return result;
248247
}
249248

250-
JsonSinkStatus sink_status = m_sink->on_boolean(boolean_value);
251-
if (sink_status != JsonSinkStatus::Continue) {
249+
if (JsonSinkStatus sink_status = m_sink->on_boolean(
250+
boolean_value);
251+
sink_status != JsonSinkStatus::Continue) {
252252
return stopTraversal(sink_status, "handling a root boolean");
253253
}
254254
return makeResult(JsonParseStatus::Ok);
@@ -264,8 +264,8 @@ class JsonBackendWalker {
264264
"Root scalar classified as null but failed validation.");
265265
}
266266

267-
JsonSinkStatus sink_status = m_sink->on_null();
268-
if (sink_status != JsonSinkStatus::Continue) {
267+
if (JsonSinkStatus sink_status = m_sink->on_null();
268+
sink_status != JsonSinkStatus::Continue) {
269269
return stopTraversal(sink_status, "handling a root null");
270270
}
271271
return makeResult(JsonParseStatus::Ok);
@@ -286,8 +286,8 @@ class JsonBackendWalker {
286286
JsonParseResult walkValue(simdjson::ondemand::value value) {
287287
simdjson::ondemand::json_type type;
288288

289-
JsonParseResult result = getResult(value.type(), &type);
290-
if (!result.ok()) {
289+
if (JsonParseResult result = getResult(value.type(), &type);
290+
!result.ok()) {
291291
return result;
292292
}
293293

@@ -309,8 +309,8 @@ class JsonBackendWalker {
309309
case simdjson::ondemand::json_type::boolean:
310310
return walkBoolean(value);
311311
case simdjson::ondemand::json_type::null: {
312-
JsonSinkStatus sink_status = m_sink->on_null();
313-
if (sink_status != JsonSinkStatus::Continue) {
312+
if (JsonSinkStatus sink_status = m_sink->on_null();
313+
sink_status != JsonSinkStatus::Continue) {
314314
return stopTraversal(sink_status, "handling a null value");
315315
}
316316
return makeResult(JsonParseStatus::Ok);
@@ -408,13 +408,13 @@ class JsonBackendWalker {
408408

409409
JsonParseResult walkString(simdjson::ondemand::value value) {
410410
std::string_view decoded;
411-
JsonParseResult result = getResult(value.get_string(), &decoded);
412-
if (!result.ok()) {
411+
if (JsonParseResult result = getResult(value.get_string(), &decoded);
412+
!result.ok()) {
413413
return result;
414414
}
415415

416-
JsonSinkStatus sink_status = m_sink->on_string(decoded);
417-
if (sink_status != JsonSinkStatus::Continue) {
416+
if (JsonSinkStatus sink_status = m_sink->on_string(decoded);
417+
sink_status != JsonSinkStatus::Continue) {
418418
return stopTraversal(sink_status, "handling a string");
419419
}
420420

@@ -424,9 +424,8 @@ class JsonBackendWalker {
424424
JsonParseResult walkNumber(simdjson::ondemand::value value) {
425425
std::string_view raw_number = trimTrailingJsonWhitespace(
426426
value.raw_json_token());
427-
JsonSinkStatus sink_status = m_sink->on_number(raw_number);
428-
429-
if (sink_status != JsonSinkStatus::Continue) {
427+
if (JsonSinkStatus sink_status = m_sink->on_number(raw_number);
428+
sink_status != JsonSinkStatus::Continue) {
430429
return stopTraversal(sink_status, "handling a number");
431430
}
432431

@@ -435,13 +434,13 @@ class JsonBackendWalker {
435434

436435
JsonParseResult walkBoolean(simdjson::ondemand::value value) {
437436
bool boolean_value = false;
438-
JsonParseResult result = getResult(value.get_bool(), &boolean_value);
439-
if (!result.ok()) {
437+
if (JsonParseResult result = getResult(value.get_bool(),
438+
&boolean_value); !result.ok()) {
440439
return result;
441440
}
442441

443-
JsonSinkStatus sink_status = m_sink->on_boolean(boolean_value);
444-
if (sink_status != JsonSinkStatus::Continue) {
442+
if (JsonSinkStatus sink_status = m_sink->on_boolean(boolean_value);
443+
sink_status != JsonSinkStatus::Continue) {
445444
return stopTraversal(sink_status, "handling a boolean");
446445
}
447446

@@ -563,5 +562,4 @@ JsonParseResult parseDocumentWithSimdjson(const std::string &input,
563562
return parsePreparedDocumentWithSimdjson(prepared.view, sink, options);
564563
}
565564

566-
} // namespace RequestBodyProcessor
567-
} // namespace modsecurity
565+
} // namespace modsecurity::RequestBodyProcessor

src/request_body_processor/json_instrumentation.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
#include <chrono>
88

9-
namespace modsecurity {
10-
namespace RequestBodyProcessor {
9+
namespace modsecurity::RequestBodyProcessor {
1110
namespace {
1211

1312
thread_local JsonInstrumentationMetrics g_metrics;
@@ -120,5 +119,4 @@ void recordJsonconsTokenExactAdvanceStep() noexcept {
120119
#endif
121120
}
122121

123-
} // namespace RequestBodyProcessor
124-
} // namespace modsecurity
122+
} // namespace modsecurity::RequestBodyProcessor

src/request_body_processor/json_instrumentation.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
#include <sstream>
77
#include <string>
88

9-
namespace modsecurity {
10-
namespace RequestBodyProcessor {
9+
namespace modsecurity::RequestBodyProcessor {
1110

1211
struct JsonInstrumentationMetrics {
1312
std::uint64_t request_body_snapshot_count{0};
@@ -50,7 +49,6 @@ void recordJsonconsEventLoop(std::uint64_t elapsed_ns) noexcept;
5049
void recordJsonconsTokenSyncStep() noexcept;
5150
void recordJsonconsTokenExactAdvanceStep() noexcept;
5251

53-
} // namespace RequestBodyProcessor
54-
} // namespace modsecurity
52+
} // namespace modsecurity::RequestBodyProcessor
5553

5654
#endif // SRC_REQUEST_BODY_PROCESSOR_JSON_INSTRUMENTATION_H_

0 commit comments

Comments
 (0)