]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
NoNewGlobals for Adaptation::Config::metaHeaders (#1747)
authorFrancesco Chemolli <5175948+kinkie@users.noreply.github.com>
Thu, 28 Mar 2024 23:02:14 +0000 (23:02 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Thu, 28 Mar 2024 23:02:18 +0000 (23:02 +0000)
Detected by Coverity. CID 1554662: Initialization or destruction
ordering is unspecified (GLOBAL_INIT_ORDER).

src/adaptation/Config.cc
src/adaptation/Config.h
src/adaptation/icap/ModXact.cc
src/cf.data.pre
src/log/access_log.cc

index 61383f895623f67057ba1fab7617f23d2214d4bb..bf98b18e8433b2d28e2e89b511ca982b221cd745 100644 (file)
@@ -30,24 +30,30 @@ int Adaptation::Config::service_iteration_limit = 16;
 int Adaptation::Config::send_client_ip = false;
 int Adaptation::Config::send_username = false;
 int Adaptation::Config::use_indirect_client = true;
-static const char *protectedFieldNamesRaw[] = {
-    "Allow",
-    "Date",
-    "Encapsulated",
-    "ISTag",
-    "Max-Connections",
-    "Methods",
-    "Opt-body-type",
-    "Options-TTL",
-    "Preview",
-    "Service",
-    "Service-ID",
-    "Transfer-Complete",
-    "Transfer-Ignore",
-    "Transfer-Preview"
-};
-static const Notes::Keys protectedFieldNames(std::begin(protectedFieldNamesRaw), std::end(protectedFieldNamesRaw));
-Notes Adaptation::Config::metaHeaders("ICAP header", &protectedFieldNames);
+
+Notes&
+Adaptation::Config::metaHeaders()
+{
+    static const auto protectedFieldNamesRaw = {
+        "Allow",
+        "Date",
+        "Encapsulated",
+        "ISTag",
+        "Max-Connections",
+        "Methods",
+        "Opt-body-type",
+        "Options-TTL",
+        "Preview",
+        "Service",
+        "Service-ID",
+        "Transfer-Complete",
+        "Transfer-Ignore",
+        "Transfer-Preview"
+    };
+    static const Notes::Keys protectedFieldNames(std::begin(protectedFieldNamesRaw), std::end(protectedFieldNamesRaw));
+    static const auto metaHeaders = new Notes("ICAP header", &protectedFieldNames);
+    return *metaHeaders;
+}
 bool Adaptation::Config::needHistory = false;
 
 Adaptation::ServiceConfig*
index 4081aab08e6dbbf12fef4283a0810025cbb56a89..159b95b03d239568c3e7bc972000f93c5cb8b665 100644 (file)
@@ -55,7 +55,7 @@ public:
     time_t oldest_service_failure;
     int service_revival_delay;
 
-    static Notes metaHeaders; ///< The list of configured meta headers
+    static Notes& metaHeaders(); ///< The list of configured meta headers
 
     static bool needHistory; ///< HttpRequest adaptation history should recorded
 
index 0568d242f6519d935b56f5f5bc80dfcc0bf224dd..5c25b9ae245c94c0923e5e4520e94a1405921e53 100644 (file)
@@ -1482,7 +1482,7 @@ void Adaptation::Icap::ModXact::makeRequestHeaders(MemBuf &buf)
         makeUsernameHeader(request, buf);
 
     // Adaptation::Config::metaHeaders
-    for (auto h: Adaptation::Config::metaHeaders) {
+    for (const auto &h: Adaptation::Config::metaHeaders()) {
         HttpRequest *r = virgin.cause ?
                          virgin.cause : dynamic_cast<HttpRequest*>(virgin.header);
         Must(r);
index 48e40882ab11b585813298e92d761afcce65dc1e..62130996f0789aa05939d7d95adf993d1ccf61bd 100644 (file)
@@ -9959,7 +9959,7 @@ DOC_END
 NAME: adaptation_meta
 TYPE: note
 IFDEF: USE_ADAPTATION
-LOC: Adaptation::Config::metaHeaders
+LOC: Adaptation::Config::metaHeaders()
 DEFAULT: none
 DOC_START
        This option allows Squid administrator to add custom ICAP request
index 4dcc6f659a92b7098f73664bd92b182fcbe43931..ff01005f4658230fc266bc5c4b84de4c84de9219 100644 (file)
@@ -338,7 +338,7 @@ accessLogInit(void)
                     curr_token->type == Format::LFT_ADAPTATION_LAST_HEADER ||
                     curr_token->type == Format::LFT_ADAPTATION_LAST_HEADER_ELEM ||
                     curr_token->type == Format::LFT_ADAPTATION_LAST_ALL_HEADERS||
-                    (curr_token->type == Format::LFT_NOTE && !Adaptation::Config::metaHeaders.empty())) {
+                    (curr_token->type == Format::LFT_NOTE && !Adaptation::Config::metaHeaders().empty())) {
                 Log::TheConfig.hasAdaptToken = true;
             }
 #if ICAP_CLIENT