From: Oleksii Shumeiko -X (oshumeik - SOFTSERVE INC at Cisco) Date: Tue, 26 Jul 2022 15:01:55 +0000 (+0000) Subject: Pull request #3520: Fix tsan warning X-Git-Tag: 3.1.38.0~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fbc77be6706b7c0047020a1bc5d8eb1884f56465;p=thirdparty%2Fsnort3.git Pull request #3520: Fix tsan warning Merge in SNORT/snort3 from ~VHORBAN/snort3:fix_tsan_warning to master Squashed commit of the following: commit 2b4ebd297a3b7088f6b4ba46e1b12698d876423f Author: Oleksandr Serhiienko Date: Sat Jul 16 18:41:34 2022 +0300 utils: add static initialization of norm_names commit 217831f9c1de3ea40bde105c7efc92e742447941 Author: Volodymyr Horban Date: Mon Jul 18 15:20:58 2022 +0300 http_inspect: remove dependency of JS normalization depth on HTTP depth --- diff --git a/src/service_inspectors/http_inspect/http_js_norm.cc b/src/service_inspectors/http_inspect/http_js_norm.cc index d9e9b4792..ce7a7c09d 100644 --- a/src/service_inspectors/http_inspect/http_js_norm.cc +++ b/src/service_inspectors/http_inspect/http_js_norm.cc @@ -83,7 +83,6 @@ HttpJsNorm::HttpJsNorm(const HttpParaList::UriParam& uri_param_, const HttpParaList::JsNormParam& js_norm_param_) : uri_param(uri_param_), js_norm_param(js_norm_param_), - detection_depth(UINT64_MAX), mpse_otag(nullptr), mpse_attr(nullptr), mpse_type(nullptr) @@ -252,7 +251,7 @@ void HttpJsNorm::do_external(const Field& input, Field& output, debug_logf(4, http_trace, TRACE_JS_PROC, current_packet, "input data was %s\n", final_portion ? "last one in PDU" : "a part of PDU"); - uint32_t data_len = std::min(detection_depth, js_ctx.script_size()); + uint32_t data_len = js_ctx.script_size(); if (data_len) { @@ -402,7 +401,7 @@ void HttpJsNorm::do_inline(const Field& input, Field& output, "input data was %s\n", final_portion ? "last one in PDU" : "a part of PDU"); auto js_ctx = ssn->js_normalizer; - uint32_t data_len = std::min(detection_depth, js_ctx->script_size()); + uint32_t data_len = js_ctx->script_size(); if (data_len) { diff --git a/src/service_inspectors/http_inspect/http_js_norm.h b/src/service_inspectors/http_inspect/http_js_norm.h index d8550a157..90094afc3 100644 --- a/src/service_inspectors/http_inspect/http_js_norm.h +++ b/src/service_inspectors/http_inspect/http_js_norm.h @@ -40,9 +40,6 @@ public: const HttpParaList::JsNormParam& js_norm_param_); ~HttpJsNorm(); - void set_detection_depth(size_t depth) - { detection_depth = depth; } - void do_legacy(const Field& input, Field& output, HttpInfractions*, HttpEventGen*, int max_javascript_whitespaces) const; void do_inline(const Field& input, Field& output, HttpInfractions*, HttpFlowData*, bool) const; @@ -63,7 +60,6 @@ private: const HttpParaList::UriParam& uri_param; const HttpParaList::JsNormParam& js_norm_param; - size_t detection_depth; bool configure_once = false; snort::SearchTool* mpse_otag; diff --git a/src/service_inspectors/http_inspect/http_msg_body.cc b/src/service_inspectors/http_inspect/http_msg_body.cc index 97b8bd140..8de6f2055 100644 --- a/src/service_inspectors/http_inspect/http_msg_body.cc +++ b/src/service_inspectors/http_inspect/http_msg_body.cc @@ -81,8 +81,6 @@ void HttpMsgBody::publish() void HttpMsgBody::bookkeeping_regular_flush(uint32_t& partial_detect_length, uint8_t*& partial_detect_buffer, uint32_t& partial_js_detect_length, int32_t detect_length) { - params->js_norm_param.js_norm->set_detection_depth(session_data->detect_depth_remaining[source_id]); - session_data->detect_depth_remaining[source_id] -= detect_length; partial_detect_buffer = nullptr; partial_detect_length = 0; diff --git a/src/service_inspectors/http_inspect/http_msg_header.cc b/src/service_inspectors/http_inspect/http_msg_header.cc index 3e9de4699..e6053a6f4 100755 --- a/src/service_inspectors/http_inspect/http_msg_header.cc +++ b/src/service_inspectors/http_inspect/http_msg_header.cc @@ -453,7 +453,6 @@ void HttpMsgHeader::prepare_body() const int64_t& depth = (source_id == SRC_CLIENT) ? params->request_depth : params->response_depth; session_data->detect_depth_remaining[source_id] = (depth != -1) ? depth : INT64_MAX; - params->js_norm_param.js_norm->set_detection_depth(session_data->detect_depth_remaining[source_id]); } else { diff --git a/src/utils/js_identifier_ctx.cc b/src/utils/js_identifier_ctx.cc index aa6e36a96..b172d6494 100644 --- a/src/utils/js_identifier_ctx.cc +++ b/src/utils/js_identifier_ctx.cc @@ -56,13 +56,6 @@ static char norm_names[NORM_NAME_SIZE * NORM_NAME_CNT]; static void init_norm_names() { - static bool once = false; - - if (once) - return; - - once = true; - char* c = norm_names; const char hex[] = "0123456789abcdef"; @@ -82,14 +75,14 @@ static void init_norm_names() assert(sizeof(norm_names) == c - norm_names); } +static int _init_norm_names __attribute__((unused)) = (init_norm_names(), 0); + JSIdentifierCtx::JSIdentifierCtx(int32_t depth, uint32_t max_scope_depth, const std::unordered_set& ignored_ids_list, const std::unordered_set& ignored_props_list) : ignored_ids_list(ignored_ids_list), ignored_props_list(ignored_props_list), max_scope_depth(max_scope_depth) { - init_norm_names(); - norm_name = norm_names; norm_name_end = norm_names + NORM_NAME_SIZE * std::min(depth, NORM_NAME_CNT); scopes.emplace_back(JSProgramScopeType::GLOBAL);