]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Initialize all HttpStateData data members (#1029)
authorFrancesco Chemolli <kinkie@squid-cache.org>
Wed, 27 Apr 2022 15:41:26 +0000 (15:41 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Wed, 27 Apr 2022 15:46:09 +0000 (15:46 +0000)
If fwd->serverConnection is null, _peer is read before being
initialized. We now make sure all HttpStateData data members are
initialized (using in-class member initialization).

Detected by Coverity. CID 1494356: Uninitialized pointer read (UNINIT).

Also removed HttpStateData::read_sz as unused.

src/http.cc
src/http.h

index 027514032d33775cba7a8064bc63449deb14cc39..b8a5072fea5e263203b575ce67dd26abb8b9bc64 100644 (file)
@@ -76,16 +76,9 @@ static void copyOneHeaderFromClientsideRequestToUpstreamRequest(const HttpHeader
 
 HttpStateData::HttpStateData(FwdState *theFwdState) :
     AsyncJob("HttpStateData"),
-    Client(theFwdState),
-    lastChunk(0),
-    httpChunkDecoder(NULL),
-    payloadSeen(0),
-    payloadTruncated(0),
-    sawDateGoBack(false)
+    Client(theFwdState)
 {
     debugs(11,5, "HttpStateData " << this << " created");
-    ignoreCacheControl = false;
-    surrogateNoStore = false;
     serverConnection = fwd->serverConnection();
 
     if (fwd->serverConnection() != NULL)
index e70cd7e037f0836d34d0ea6ad1ff69fc6ab232a0..c4161211f86ed68ec4d33a596c0f59af6d82601a 100644 (file)
@@ -61,14 +61,13 @@ public:
     // Checks whether the response is cacheable/shareable.
     ReuseDecision::Answers reusableReply(ReuseDecision &decision);
 
-    CachePeer *_peer;       /* CachePeer request made to */
-    int eof;            /* reached end-of-object? */
-    int lastChunk;      /* reached last chunk of a chunk-encoded reply */
+    CachePeer *_peer = nullptr;       /* CachePeer request made to */
+    int eof = 0;            /* reached end-of-object? */
+    int lastChunk = 0;      /* reached last chunk of a chunk-encoded reply */
     Http::StateFlags flags;
-    size_t read_sz;
     SBuf inBuf;                ///< I/O buffer for receiving server responses
-    bool ignoreCacheControl;
-    bool surrogateNoStore;
+    bool ignoreCacheControl = false;
+    bool surrogateNoStore = false;
 
     /// Upgrade header value sent to the origin server or cache peer.
     String *upgradeHeaderOut = nullptr;
@@ -147,16 +146,16 @@ private:
 
     /// Parser being used at present to parse the HTTP/ICY server response.
     Http1::ResponseParserPointer hp;
-    Http1::TeChunkedParser *httpChunkDecoder;
+    Http1::TeChunkedParser *httpChunkDecoder = nullptr;
 
     /// amount of message payload/body received so far.
-    int64_t payloadSeen;
+    int64_t payloadSeen = 0;
     /// positive when we read more than we wanted
-    int64_t payloadTruncated;
+    int64_t payloadTruncated = 0;
 
     /// Whether we received a Date header older than that of a matching
     /// cached response.
-    bool sawDateGoBack;
+    bool sawDateGoBack = false;
 };
 
 std::ostream &operator <<(std::ostream &os, const HttpStateData::ReuseDecision &d);