]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #1158 in SNORT/snort3 from const_cast to master
authorRuss Combs (rucombs) <rucombs@cisco.com>
Fri, 23 Mar 2018 19:11:34 +0000 (15:11 -0400)
committerRuss Combs (rucombs) <rucombs@cisco.com>
Fri, 23 Mar 2018 19:11:34 +0000 (15:11 -0400)
Squashed commit of the following:

commit 14b0e97fa6060bf9dd88db1f3e10aa59aeea4523
Author: Russ Combs <rucombs@cisco.com>
Date:   Fri Mar 23 10:25:16 2018 -0400

    build: fix various drops const qualifier cases

src/codecs/link/cd_ppp_encap.cc
src/decompress/file_decomp.h
src/main/policy.cc
src/managers/so_manager.cc
src/network_inspectors/appid/appid_inspector.cc
src/service_inspectors/http_inspect/http_stream_splitter_reassemble.cc

index 9a6a571b2914386f1c47921e9e6ff6f69a46fbb8..5bd04ce5d21708502a3b84a4fbc2fb96dd16234d 100644 (file)
@@ -92,8 +92,12 @@ bool PppEncap::decode(const RawData& raw, CodecData& codec, DecodeData&)
             return false;
         }
 
-        // FIXIT-M X This is broken - it should not modify the packet data (which should be const).
-        ((ip::IP4Hdr*)(raw.data + codec.lyr_len))->set_proto(IpProtocol::TCP);
+        {
+            // FIXIT-M X This is broken - it should not modify the packet data
+            // (which should be const).
+            const ip::IP4Hdr* iph = reinterpret_cast<const ip::IP4Hdr*>(raw.data + codec.lyr_len);
+            const_cast<ip::IP4Hdr*>(iph)->set_proto(IpProtocol::TCP);
+        }
     /* fall through */
 
     case PPP_IP:
index a186fb2c09e07598a4ec10181aae59ec2dbb8b23..032dc9c5e23cc07339f209fef11fca12d5cf1207 100644 (file)
@@ -138,7 +138,7 @@ struct fd_session_t
    of the underlying decompression engine context. */
 #ifndef SYNC_IN
 #define SYNC_IN(dest) \
-    dest->next_in = (Bytef*)(SessionPtr->Next_In); \
+    dest->next_in = const_cast<Bytef*>(SessionPtr->Next_In); \
     (dest)->avail_in = SessionPtr->Avail_In; \
     (dest)->total_in = SessionPtr->Total_In; \
     (dest)->next_out = SessionPtr->Next_Out; \
index aa152d17c4b16d1e0021ead3ebf712c607d4dab1..d6806f79da622c6b6af3a9251be45a21dc3a838d 100644 (file)
@@ -63,7 +63,7 @@ public:
     AltPktHandler() = default;
 
     void handle(DataEvent& e, Flow*) override
-    { DetectionEngine::detect((Packet*)e.get_packet()); }  // FIXIT-L not const!
+    { DetectionEngine::detect(const_cast<Packet*>(e.get_packet())); }
 };
 
 InspectionPolicy::InspectionPolicy(PolicyId id)
index 1188303ea8c1192049f2d312c9d73559aa46fcf3..5415feb44a08676bf58bea28b6638c7bc827c423 100644 (file)
@@ -88,7 +88,7 @@ static const uint8_t* compress(const string& text, unsigned& len)
     if ( ret != Z_OK )
         return nullptr;
 
-    stream.next_in = (Bytef*)s;
+    stream.next_in = const_cast<Bytef*>(reinterpret_cast<const uint8_t*>(s));
     stream.avail_in = text.size();
 
     stream.next_out = so_buf;
@@ -121,7 +121,7 @@ static const char* expand(const uint8_t* data, unsigned len)
     if ( inflateInit2(&stream, window_bits) != Z_OK )
         return nullptr;
 
-    stream.next_in = (Bytef*)data;
+    stream.next_in = const_cast<Bytef*>(data);
     stream.avail_in = (uInt)len;
 
     stream.next_out = (Bytef*)so_buf;
index 965f7738745c1c5e203f55f2f99b967602ba2bfe..40629c2799f45eccff5fd7bb6e2f55e9feb47cec 100644 (file)
@@ -104,7 +104,7 @@ bool AppIdInspector::configure(SnortConfig* sc)
 {
     assert(!active_config);
 
-    active_config = new AppIdConfig((AppIdModuleConfig*)config);
+    active_config = new AppIdConfig(const_cast<AppIdModuleConfig*>(config));
 
     DataBus::subscribe(HTTP_REQUEST_HEADER_EVENT_KEY, new HttpEventHandler(
         HttpEventHandler::REQUEST_EVENT));
index d869d9af9daf8d58fe02572e92dbcd28f822b52f..e5cbca2bc3f8ee3d5cd238fd89d9ad6f979b661f 100644 (file)
@@ -143,7 +143,7 @@ void HttpStreamSplitter::decompress_copy(uint8_t* buffer, uint32_t& offset, cons
 {
     if ((compression == CMP_GZIP) || (compression == CMP_DEFLATE))
     {
-        compress_stream->next_in = (Bytef*)data;
+        compress_stream->next_in = const_cast<Bytef*>(data);
         compress_stream->avail_in = length;
         compress_stream->next_out = buffer + offset;
         compress_stream->avail_out = MAX_OCTETS - offset;
@@ -184,10 +184,10 @@ void HttpStreamSplitter::decompress_copy(uint8_t* buffer, uint32_t& offset, cons
         {
             // Some incorrect implementations of deflate don't use the expected header. Feed a
             // dummy header to zlib and retry the inflate.
-            static constexpr char zlib_header[2] = { 0x78, 0x01 };
+            static constexpr uint8_t zlib_header[2] = { 0x78, 0x01 };
 
             inflateReset(compress_stream);
-            compress_stream->next_in = (Bytef*)zlib_header;
+            compress_stream->next_in = const_cast<Bytef*>(zlib_header);
             compress_stream->avail_in = sizeof(zlib_header);
             inflate(compress_stream, Z_SYNC_FLUSH);