From 125ea60a086af3277bf2fc825776f9074d6a3725 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Thu, 26 Sep 2024 09:46:26 +0200 Subject: [PATCH] Refs #21751. Added static assertions for structure sizes. Signed-off-by: Miguel Company --- .../common/BlackboxTestsTransportUDP.cpp | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/test/blackbox/common/BlackboxTestsTransportUDP.cpp b/test/blackbox/common/BlackboxTestsTransportUDP.cpp index 616cdcba52f..fdd5a8cdce4 100644 --- a/test/blackbox/common/BlackboxTestsTransportUDP.cpp +++ b/test/blackbox/common/BlackboxTestsTransportUDP.cpp @@ -645,10 +645,16 @@ static void KeyOnlyBigPayloadIgnored( { struct KeyOnlyBigPayloadDatagram { - std::array rtps_id{ {'R', 'T', 'P', 'S'} }; - std::array protocol_version{ {2, 3} }; - std::array vendor_id{ {0x01, 0x0F} }; - GuidPrefix_t sender_prefix{}; + struct RTPSHeader + { + std::array rtps_id{ {'R', 'T', 'P', 'S'} }; + std::array protocol_version{ {2, 3} }; + std::array vendor_id{ {0x01, 0x0F} }; + GuidPrefix_t sender_prefix{}; + } + header; + + static_assert(sizeof(RTPSHeader) == RTPSMESSAGE_HEADER_SIZE, "Unexpected size for RTPS header"); struct DataSubMsg { @@ -668,6 +674,8 @@ static void KeyOnlyBigPayloadIgnored( SequenceNumber_t sn{ 2 }; }; + static_assert(sizeof(Header) == RTPSMESSAGE_DATA_MIN_LENGTH, "Unexpected size for DATA header"); + struct InlineQoS { // PID_STATUS_INFO (unregistered + disposed) @@ -688,6 +696,8 @@ static void KeyOnlyBigPayloadIgnored( Sentinel sentinel; }; + static_assert(sizeof(InlineQoS) == 8 + 4, "Unexpected size for InlineQoS"); + struct SerializedData { std::array encapsulation {{0}}; @@ -695,13 +705,25 @@ static void KeyOnlyBigPayloadIgnored( std::array data {{0}}; }; + static_assert(sizeof(SerializedData) == 0x24 + 2 + 2, "Unexpected size for SerializedData"); + Header header; InlineQoS qos; SerializedData payload; } data; + + static_assert( + sizeof(DataSubMsg) == + sizeof(DataSubMsg::Header) + sizeof(DataSubMsg::InlineQoS) + sizeof(DataSubMsg::SerializedData), + "Unexpected size for DataSubMsg"); }; + static_assert( + sizeof(KeyOnlyBigPayloadDatagram) == + sizeof(KeyOnlyBigPayloadDatagram::RTPSHeader) + sizeof(KeyOnlyBigPayloadDatagram::DataSubMsg), + "Unexpected size for KeyOnlyBigPayloadDatagram"); + UDPMessageSender fake_msg_sender; // Force using UDP transport @@ -743,7 +765,7 @@ static void KeyOnlyBigPayloadIgnored( auto writer_guid = writer.datawriter_guid(); KeyOnlyBigPayloadDatagram malicious_packet{}; - malicious_packet.sender_prefix = writer_guid.guidPrefix; + malicious_packet.header.sender_prefix = writer_guid.guidPrefix; malicious_packet.data.header.writer_id = writer_guid.entityId; malicious_packet.data.header.reader_id = reader.datareader_guid().entityId; malicious_packet.data.payload.encapsulation[1] = CDR_LE;