]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
NoNewGlobals for digestFieldsLookupTable (#1743)
authorFrancesco Chemolli <5175948+kinkie@users.noreply.github.com>
Wed, 20 Mar 2024 22:59:46 +0000 (22:59 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Wed, 20 Mar 2024 22:59:53 +0000 (22:59 +0000)
Detected by Coverity. CID 1554677: Initialization or destruction
ordering is unspecified (GLOBAL_INIT_ORDER).

src/auth/digest/Config.cc

index a3c9e938828ec2a5b24ea4782611cb73fded7d09..e00e15099b8665cf7bf1453c2f7111e90ab3c510 100644 (file)
@@ -66,22 +66,24 @@ enum http_digest_attr_type {
     DIGEST_INVALID_ATTR
 };
 
-static const LookupTable<http_digest_attr_type>::Record
-DigestAttrs[] = {
-    {"username", DIGEST_USERNAME},
-    {"realm", DIGEST_REALM},
-    {"qop", DIGEST_QOP},
-    {"algorithm", DIGEST_ALGORITHM},
-    {"uri", DIGEST_URI},
-    {"nonce", DIGEST_NONCE},
-    {"nc", DIGEST_NC},
-    {"cnonce", DIGEST_CNONCE},
-    {"response", DIGEST_RESPONSE},
-    {nullptr, DIGEST_INVALID_ATTR}
-};
-
-LookupTable<http_digest_attr_type>
-DigestFieldsLookupTable(DIGEST_INVALID_ATTR, DigestAttrs);
+static const auto &
+digestFieldsLookupTable()
+{
+    static const LookupTable<http_digest_attr_type>::Record DigestAttrs[] = {
+        {"username", DIGEST_USERNAME},
+        {"realm", DIGEST_REALM},
+        {"qop", DIGEST_QOP},
+        {"algorithm", DIGEST_ALGORITHM},
+        {"uri", DIGEST_URI},
+        {"nonce", DIGEST_NONCE},
+        {"nc", DIGEST_NC},
+        {"cnonce", DIGEST_CNONCE},
+        {"response", DIGEST_RESPONSE},
+        {nullptr, DIGEST_INVALID_ATTR}
+    };
+    static const auto table = new LookupTable<http_digest_attr_type>(DIGEST_INVALID_ATTR, DigestAttrs);
+    return *table;
+}
 
 /*
  *
@@ -774,7 +776,7 @@ Auth::Digest::Config::decode(char const *proxy_auth, const HttpRequest *request,
         }
 
         /* find type */
-        const http_digest_attr_type t = DigestFieldsLookupTable.lookup(keyName);
+        const auto t = digestFieldsLookupTable().lookup(keyName);
 
         switch (t) {
         case DIGEST_USERNAME: