Skip to content

Commit

Permalink
Be less strict with parameter lengths (#5225)
Browse files Browse the repository at this point in the history
* Refs #21537. Add regression test for interoperability issue.

Signed-off-by: Miguel Company <miguelcompany@eprosima.com>

* Refs #21537. Add regression test for big parameters.

Signed-off-by: Miguel Company <miguelcompany@eprosima.com>

* Refs #21537. Fix builtin deserialization length checks.

Signed-off-by: Miguel Company <miguelcompany@eprosima.com>

* Refs #21537. Special cases in test.

Signed-off-by: Miguel Company <miguelcompany@eprosima.com>

* Refs #21537. Extend test to full non-custom range.

Signed-off-by: Miguel Company <miguelcompany@eprosima.com>

* Refs #21537. Extend parameter size to 64K.

Signed-off-by: Miguel Company <miguelcompany@eprosima.com>

* Refs #21537. Uncrustify.

Signed-off-by: Miguel Company <miguelcompany@eprosima.com>

* Refs #21638. Fix windows warning.

Signed-off-by: Miguel Company <miguelcompany@eprosima.com>

---------

Signed-off-by: Miguel Company <miguelcompany@eprosima.com>
(cherry picked from commit 7b111f9)

# Conflicts:
#	src/cpp/fastdds/core/policy/ParameterSerializer.hpp
#	test/unittest/rtps/builtin/BuiltinDataSerializationTests.cpp
  • Loading branch information
MiguelCompany authored and mergify[bot] committed Sep 20, 2024
1 parent 6f85f6a commit bd7d15b
Show file tree
Hide file tree
Showing 3 changed files with 626 additions and 32 deletions.
113 changes: 97 additions & 16 deletions src/cpp/fastdds/core/policy/ParameterSerializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ inline bool ParameterSerializer<ParameterLocator_t>::read_content_from_cdr_messa
fastrtps::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length != PARAMETER_LOCATOR_LENGTH)
if (parameter_length < PARAMETER_LOCATOR_LENGTH)
{
return false;
}
Expand All @@ -273,7 +273,7 @@ inline bool ParameterSerializer<ParameterKey_t>::read_content_from_cdr_message(
fastrtps::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length != PARAMETER_KEY_HASH_LENGTH)
if (parameter_length < PARAMETER_KEY_HASH_LENGTH)
{
return false;
}
Expand Down Expand Up @@ -343,7 +343,7 @@ inline bool ParameterSerializer<ParameterPort_t>::read_content_from_cdr_message(
fastrtps::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length != PARAMETER_PORT_LENGTH)
if (parameter_length < PARAMETER_PORT_LENGTH)
{
return false;
}
Expand All @@ -367,7 +367,7 @@ inline bool ParameterSerializer<ParameterGuid_t>::read_content_from_cdr_message(
fastrtps::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length != PARAMETER_GUID_LENGTH)
if (parameter_length < PARAMETER_GUID_LENGTH)
{
return false;
}
Expand All @@ -394,7 +394,7 @@ inline bool ParameterSerializer<ParameterProtocolVersion_t>::read_content_from_c
fastrtps::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length != PARAMETER_PROTOCOL_LENGTH)
if (parameter_length < PARAMETER_PROTOCOL_LENGTH)
{
return false;
}
Expand Down Expand Up @@ -422,7 +422,7 @@ inline bool ParameterSerializer<ParameterVendorId_t>::read_content_from_cdr_mess
fastrtps::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length != PARAMETER_VENDOR_LENGTH)
if (parameter_length < PARAMETER_VENDOR_LENGTH)
{
return false;
}
Expand All @@ -434,6 +434,61 @@ inline bool ParameterSerializer<ParameterVendorId_t>::read_content_from_cdr_mess
}

template<>
<<<<<<< HEAD
=======
inline bool ParameterSerializer<ParameterProductVersion_t>::add_content_to_cdr_message(
const ParameterProductVersion_t& parameter,
rtps::CDRMessage_t* cdr_message)
{
bool valid = rtps::CDRMessage::addOctet(cdr_message, parameter.version.major);
valid &= rtps::CDRMessage::addOctet(cdr_message, parameter.version.minor);
valid &= rtps::CDRMessage::addOctet(cdr_message, parameter.version.patch);
valid &= rtps::CDRMessage::addOctet(cdr_message, parameter.version.tweak);
return valid;
}

template<>
inline bool ParameterSerializer<ParameterProductVersion_t>::read_content_from_cdr_message(
ParameterProductVersion_t& parameter,
rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length < PARAMETER_PRODUCT_VERSION_LENGTH)
{
return false;
}
parameter.length = parameter_length;
bool valid = rtps::CDRMessage::readOctet(cdr_message, &parameter.version.major);
valid &= rtps::CDRMessage::readOctet(cdr_message, &parameter.version.minor);
valid &= rtps::CDRMessage::readOctet(cdr_message, &parameter.version.patch);
valid &= rtps::CDRMessage::readOctet(cdr_message, &parameter.version.tweak);
return valid;
}

template<>
inline bool ParameterSerializer<ParameterDomainId_t>::add_content_to_cdr_message(
const ParameterDomainId_t& parameter,
fastdds::rtps::CDRMessage_t* cdr_message)
{
return fastdds::rtps::CDRMessage::addUInt32(cdr_message, parameter.domain_id);
}

template<>
inline bool ParameterSerializer<ParameterDomainId_t>::read_content_from_cdr_message(
ParameterDomainId_t& parameter,
fastdds::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length < PARAMETER_DOMAINID_LENGTH)
{
return false;
}
parameter.length = parameter_length;
return fastdds::rtps::CDRMessage::readUInt32(cdr_message, &parameter.domain_id);
}

template<>
>>>>>>> 7b111f911 (Be less strict with parameter lengths (#5225))
inline bool ParameterSerializer<ParameterIP4Address_t>::add_content_to_cdr_message(
const ParameterIP4Address_t& parameter,
fastrtps::rtps::CDRMessage_t* cdr_message)
Expand All @@ -447,7 +502,7 @@ inline bool ParameterSerializer<ParameterIP4Address_t>::read_content_from_cdr_me
fastrtps::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length != PARAMETER_IP4_LENGTH)
if (parameter_length < PARAMETER_IP4_LENGTH)
{
return false;
}
Expand All @@ -473,7 +528,7 @@ inline bool ParameterSerializer<ParameterBool_t>::read_content_from_cdr_message(
fastrtps::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length != PARAMETER_BOOL_LENGTH)
if (parameter_length < PARAMETER_BOOL_LENGTH)
{
return false;
}
Expand Down Expand Up @@ -501,7 +556,7 @@ inline bool ParameterSerializer<ParameterStatusInfo_t>::read_content_from_cdr_me
fastrtps::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length != PARAMETER_STATUS_INFO_LENGTH)
if (parameter_length < PARAMETER_STATUS_INFO_LENGTH)
{
return false;
}
Expand Down Expand Up @@ -530,7 +585,7 @@ inline bool ParameterSerializer<ParameterCount_t>::read_content_from_cdr_message
fastrtps::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length != PARAMETER_COUNT_LENGTH)
if (parameter_length < PARAMETER_COUNT_LENGTH)
{
return false;
}
Expand All @@ -552,7 +607,7 @@ inline bool ParameterSerializer<ParameterEntityId_t>::read_content_from_cdr_mess
fastrtps::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length != PARAMETER_ENTITYID_LENGTH)
if (parameter_length < PARAMETER_ENTITYID_LENGTH)
{
return false;
}
Expand All @@ -576,7 +631,7 @@ inline bool ParameterSerializer<ParameterTime_t>::read_content_from_cdr_message(
fastrtps::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length != PARAMETER_TIME_LENGTH)
if (parameter_length < PARAMETER_TIME_LENGTH)
{
return false;
}
Expand Down Expand Up @@ -604,12 +659,38 @@ inline bool ParameterSerializer<ParameterBuiltinEndpointSet_t>::read_content_fro
fastrtps::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length != PARAMETER_BUILTINENDPOINTSET_LENGTH)
if (parameter_length < PARAMETER_BUILTINENDPOINTSET_LENGTH)
{
return false;
}
parameter.length = parameter_length;
<<<<<<< HEAD
return fastrtps::rtps::CDRMessage::readUInt32(cdr_message, &parameter.endpointSet);
=======
return rtps::CDRMessage::readUInt32(cdr_message, &parameter.endpointSet);
}

template<>
inline bool ParameterSerializer<ParameterNetworkConfigSet_t>::add_content_to_cdr_message(
const ParameterNetworkConfigSet_t& parameter,
rtps::CDRMessage_t* cdr_message)
{
return rtps::CDRMessage::addUInt32(cdr_message, parameter.netconfigSet);
}

template<>
inline bool ParameterSerializer<ParameterNetworkConfigSet_t>::read_content_from_cdr_message(
ParameterNetworkConfigSet_t& parameter,
rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length < PARAMETER_NETWORKCONFIGSET_LENGTH)
{
return false;
}
parameter.length = parameter_length;
return rtps::CDRMessage::readUInt32(cdr_message, &parameter.netconfigSet);
>>>>>>> 7b111f911 (Be less strict with parameter lengths (#5225))
}

template<>
Expand Down Expand Up @@ -761,7 +842,7 @@ inline bool ParameterSerializer<ParameterSampleIdentity_t>::read_content_from_cd
fastrtps::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length != PARAMETER_SAMPLEIDENTITY_LENGTH)
if (parameter_length < PARAMETER_SAMPLEIDENTITY_LENGTH)
{
return false;
}
Expand Down Expand Up @@ -1039,7 +1120,7 @@ inline bool ParameterSerializer<ParameterParticipantSecurityInfo_t>::read_conten
fastrtps::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length != PARAMETER_PARTICIPANT_SECURITY_INFO_LENGTH)
if (parameter_length < PARAMETER_PARTICIPANT_SECURITY_INFO_LENGTH)
{
return false;
}
Expand All @@ -1065,7 +1146,7 @@ inline bool ParameterSerializer<ParameterEndpointSecurityInfo_t>::read_content_f
fastrtps::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length != PARAMETER_ENDPOINT_SECURITY_INFO_LENGTH)
if (parameter_length < PARAMETER_ENDPOINT_SECURITY_INFO_LENGTH)
{
return false;
}
Expand Down
32 changes: 16 additions & 16 deletions src/cpp/fastdds/core/policy/QosPoliciesSerializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ inline bool QosPoliciesSerializer<DurabilityQosPolicy>::read_content_from_cdr_me
fastrtps::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length != PARAMETER_KIND_LENGTH)
if (parameter_length < PARAMETER_KIND_LENGTH)
{
return false;
}
Expand Down Expand Up @@ -126,7 +126,7 @@ inline bool QosPoliciesSerializer<DeadlineQosPolicy>::read_content_from_cdr_mess
fastrtps::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length != PARAMETER_TIME_LENGTH)
if (parameter_length < PARAMETER_TIME_LENGTH)
{
return false;
}
Expand Down Expand Up @@ -155,7 +155,7 @@ inline bool QosPoliciesSerializer<LatencyBudgetQosPolicy>::read_content_from_cdr
fastrtps::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length != PARAMETER_TIME_LENGTH)
if (parameter_length < PARAMETER_TIME_LENGTH)
{
return false;
}
Expand Down Expand Up @@ -190,7 +190,7 @@ inline bool QosPoliciesSerializer<LivelinessQosPolicy>::read_content_from_cdr_me
fastrtps::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length != PARAMETER_KIND_LENGTH + PARAMETER_TIME_LENGTH)
if (parameter_length < PARAMETER_KIND_LENGTH + PARAMETER_TIME_LENGTH)
{
return false;
}
Expand Down Expand Up @@ -229,7 +229,7 @@ inline bool QosPoliciesSerializer<ReliabilityQosPolicy>::read_content_from_cdr_m
fastrtps::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length != PARAMETER_KIND_LENGTH + PARAMETER_TIME_LENGTH)
if (parameter_length < PARAMETER_KIND_LENGTH + PARAMETER_TIME_LENGTH)
{
return false;
}
Expand Down Expand Up @@ -263,7 +263,7 @@ inline bool QosPoliciesSerializer<OwnershipQosPolicy>::read_content_from_cdr_mes
fastrtps::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length != PARAMETER_KIND_LENGTH)
if (parameter_length < PARAMETER_KIND_LENGTH)
{
return false;
}
Expand Down Expand Up @@ -292,7 +292,7 @@ inline bool QosPoliciesSerializer<DestinationOrderQosPolicy>::read_content_from_
fastrtps::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length != PARAMETER_KIND_LENGTH)
if (parameter_length < PARAMETER_KIND_LENGTH)
{
return false;
}
Expand Down Expand Up @@ -323,7 +323,7 @@ inline bool QosPoliciesSerializer<ResourceLimitsQosPolicy>::read_content_from_cd
fastrtps::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length != 12)
if (parameter_length < 12)
{
return false;
}
Expand Down Expand Up @@ -357,7 +357,7 @@ inline bool QosPoliciesSerializer<TimeBasedFilterQosPolicy>::read_content_from_c
fastrtps::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length != PARAMETER_TIME_LENGTH)
if (parameter_length < PARAMETER_TIME_LENGTH)
{
return false;
}
Expand Down Expand Up @@ -397,7 +397,7 @@ inline bool QosPoliciesSerializer<PresentationQosPolicy>::read_content_from_cdr_
fastrtps::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length != PARAMETER_PRESENTATION_LENGTH)
if (parameter_length < PARAMETER_PRESENTATION_LENGTH)
{
return false;
}
Expand Down Expand Up @@ -516,7 +516,7 @@ inline bool QosPoliciesSerializer<HistoryQosPolicy>::read_content_from_cdr_messa
fastrtps::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length != PARAMETER_KIND_LENGTH + 4)
if (parameter_length < PARAMETER_KIND_LENGTH + 4)
{
return false;
}
Expand Down Expand Up @@ -553,7 +553,7 @@ inline bool QosPoliciesSerializer<DurabilityServiceQosPolicy>::read_content_from
fastrtps::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length != PARAMETER_TIME_LENGTH + PARAMETER_KIND_LENGTH + 16)
if (parameter_length < PARAMETER_TIME_LENGTH + PARAMETER_KIND_LENGTH + 16)
{
return false;
}
Expand Down Expand Up @@ -588,7 +588,7 @@ inline bool QosPoliciesSerializer<LifespanQosPolicy>::read_content_from_cdr_mess
fastrtps::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length != PARAMETER_TIME_LENGTH)
if (parameter_length < PARAMETER_TIME_LENGTH)
{
return false;
}
Expand All @@ -615,7 +615,7 @@ inline bool QosPoliciesSerializer<OwnershipStrengthQosPolicy>::read_content_from
fastrtps::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length != 4)
if (parameter_length < 4)
{
return false;
}
Expand All @@ -638,7 +638,7 @@ inline bool QosPoliciesSerializer<TransportPriorityQosPolicy>::read_content_from
fastrtps::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length != 4)
if (parameter_length < 4)
{
return false;
}
Expand Down Expand Up @@ -800,7 +800,7 @@ inline bool QosPoliciesSerializer<DisablePositiveACKsQosPolicy>::read_content_fr
fastrtps::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length != PARAMETER_BOOL_LENGTH)
if (parameter_length < PARAMETER_BOOL_LENGTH)
{
return false;
}
Expand Down
Loading

0 comments on commit bd7d15b

Please sign in to comment.