]> granicus.if.org Git - icinga2/commitdiff
Add validation for HTTP connection sizes
authorGunnar Beutner <gunnar.beutner@icinga.com>
Wed, 31 Jan 2018 06:59:49 +0000 (07:59 +0100)
committerJean Flach <jean-marcel.flach@icinga.com>
Fri, 23 Feb 2018 07:31:28 +0000 (08:31 +0100)
lib/remote/httpchunkedencoding.cpp
lib/remote/httprequest.cpp

index 8903a4305718f6d6873f011fec73b2dd3afed81d..32d7c199cd9131a7ab0fc692691c0dfd8d074774 100644 (file)
@@ -37,6 +37,8 @@ StreamReadStatus HttpChunkedEncoding::ReadChunkFromStream(const Stream::Ptr& str
                msgbuf << std::hex << line;
                msgbuf >> context.LengthIndicator;
 
+               if (context.LengthIndicator < 0)
+                       BOOST_THROW_EXCEPTION(std::invalid_argument("HTTP chunk length must not be negative."));
        }
 
        StreamReadContext& scontext = context.StreamContext;
index 43918c3223fa4c422f32b4a110e68822a914a635..0a2f161abd62cbe3e32dc7ebd5a7d0dd7775c48f 100644 (file)
@@ -131,7 +131,12 @@ bool HttpRequest::Parse(StreamReadContext& src, bool may_wait)
                                src.MustRead = false;
                        }
 
-                       size_t length_indicator = Convert::ToLong(Headers->Get("content-length"));
+                       long length_indicator_signed = Convert::ToLong(Headers->Get("content-length"));
+
+                       if (length_indicator_signed < 0)
+                               BOOST_THROW_EXCEPTION(std::invalid_argument("Content-Length must not be negative."));
+
+                       size_t length_indicator = length_indicator_signed;
 
                        if (src.Size < length_indicator) {
                                src.MustRead = true;