From: Russ Combs (rucombs) Date: Fri, 23 Mar 2018 19:11:34 +0000 (-0400) Subject: Merge pull request #1158 in SNORT/snort3 from const_cast to master X-Git-Tag: 3.0.0-245~70 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0bd16ff37421b88c27427bed371ccac464d17bcd;p=thirdparty%2Fsnort3.git Merge pull request #1158 in SNORT/snort3 from const_cast to master Squashed commit of the following: commit 14b0e97fa6060bf9dd88db1f3e10aa59aeea4523 Author: Russ Combs Date: Fri Mar 23 10:25:16 2018 -0400 build: fix various drops const qualifier cases --- diff --git a/src/codecs/link/cd_ppp_encap.cc b/src/codecs/link/cd_ppp_encap.cc index 9a6a571b2..5bd04ce5d 100644 --- a/src/codecs/link/cd_ppp_encap.cc +++ b/src/codecs/link/cd_ppp_encap.cc @@ -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(raw.data + codec.lyr_len); + const_cast(iph)->set_proto(IpProtocol::TCP); + } /* fall through */ case PPP_IP: diff --git a/src/decompress/file_decomp.h b/src/decompress/file_decomp.h index a186fb2c0..032dc9c5e 100644 --- a/src/decompress/file_decomp.h +++ b/src/decompress/file_decomp.h @@ -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(SessionPtr->Next_In); \ (dest)->avail_in = SessionPtr->Avail_In; \ (dest)->total_in = SessionPtr->Total_In; \ (dest)->next_out = SessionPtr->Next_Out; \ diff --git a/src/main/policy.cc b/src/main/policy.cc index aa152d17c..d6806f79d 100644 --- a/src/main/policy.cc +++ b/src/main/policy.cc @@ -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(e.get_packet())); } }; InspectionPolicy::InspectionPolicy(PolicyId id) diff --git a/src/managers/so_manager.cc b/src/managers/so_manager.cc index 1188303ea..5415feb44 100644 --- a/src/managers/so_manager.cc +++ b/src/managers/so_manager.cc @@ -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(reinterpret_cast(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(data); stream.avail_in = (uInt)len; stream.next_out = (Bytef*)so_buf; diff --git a/src/network_inspectors/appid/appid_inspector.cc b/src/network_inspectors/appid/appid_inspector.cc index 965f77387..40629c279 100644 --- a/src/network_inspectors/appid/appid_inspector.cc +++ b/src/network_inspectors/appid/appid_inspector.cc @@ -104,7 +104,7 @@ bool AppIdInspector::configure(SnortConfig* sc) { assert(!active_config); - active_config = new AppIdConfig((AppIdModuleConfig*)config); + active_config = new AppIdConfig(const_cast(config)); DataBus::subscribe(HTTP_REQUEST_HEADER_EVENT_KEY, new HttpEventHandler( HttpEventHandler::REQUEST_EVENT)); diff --git a/src/service_inspectors/http_inspect/http_stream_splitter_reassemble.cc b/src/service_inspectors/http_inspect/http_stream_splitter_reassemble.cc index d869d9af9..e5cbca2bc 100644 --- a/src/service_inspectors/http_inspect/http_stream_splitter_reassemble.cc +++ b/src/service_inspectors/http_inspect/http_stream_splitter_reassemble.cc @@ -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(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(zlib_header); compress_stream->avail_in = sizeof(zlib_header); inflate(compress_stream, Z_SYNC_FLUSH);