]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
NoNewGlobals for ProxyProtocol::*::Magic (#1791)
authorFrancesco Chemolli <5175948+kinkie@users.noreply.github.com>
Fri, 26 Apr 2024 13:14:19 +0000 (13:14 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Fri, 26 Apr 2024 16:59:59 +0000 (16:59 +0000)
Detected by Coverity. CID 1554652: Initialization or destruction
ordering is unspecified (GLOBAL_INIT_ORDER).

src/proxyp/Parser.cc

index 0e9b2c94eac1236f97c6f787e682797358b0059e..4ba40f206b3ae7d3a6411d894631ac60f2746317 100644 (file)
 namespace ProxyProtocol {
 namespace One {
 /// magic octet prefix for PROXY protocol version 1
-static const SBuf Magic("PROXY", 5);
+static const auto &
+Magic()
+{
+    static const auto magic = new SBuf("PROXY", 5);
+    return *magic;
+}
 /// extracts PROXY protocol v1 header from the given buffer
 static Parsed Parse(const SBuf &buf);
 
@@ -41,7 +46,12 @@ static void ParseAddresses(Parser::Tokenizer &tok, Header::Pointer &header);
 
 namespace Two {
 /// magic octet prefix for PROXY protocol version 2
-static const SBuf Magic("\x0D\x0A\x0D\x0A\x00\x0D\x0A\x51\x55\x49\x54\x0A", 12);
+static const auto &
+Magic()
+{
+    static const auto magic = new SBuf("\x0D\x0A\x0D\x0A\x00\x0D\x0A\x51\x55\x49\x54\x0A", 12);
+    return *magic;
+}
 /// extracts PROXY protocol v2 header from the given buffer
 static Parsed Parse(const SBuf &buf);
 
@@ -115,7 +125,7 @@ ProxyProtocol::One::Parse(const SBuf &buf)
     Parser::Tokenizer tok(buf);
 
     static const SBuf::size_type maxHeaderLength = 107; // including CRLF
-    static const auto maxInteriorLength = maxHeaderLength - Magic.length() - 2;
+    static const auto maxInteriorLength = maxHeaderLength - Magic().length() - 2;
     static const auto interiorChars = CharacterSet::CR.complement().rename("non-CR");
     SBuf interior;
 
@@ -244,8 +254,8 @@ ProxyProtocol::Parse(const SBuf &buf)
     Parser::Tokenizer magicTok(buf);
 
     const auto parser =
-        magicTok.skip(Two::Magic) ? &Two::Parse :
-        magicTok.skip(One::Magic) ? &One::Parse :
+        magicTok.skip(Two::Magic()) ? &Two::Parse :
+        magicTok.skip(One::Magic()) ? &One::Parse :
         nullptr;
 
     if (parser) {
@@ -254,7 +264,7 @@ ProxyProtocol::Parse(const SBuf &buf)
     }
 
     // detect and terminate other protocols
-    if (buf.length() >= Two::Magic.length()) {
+    if (buf.length() >= Two::Magic().length()) {
         // PROXY/1.0 magic is shorter, so we know that
         // the input does not start with any PROXY magic
         throw TexcHere("PROXY protocol error: invalid magic");