Skip to content

Commit

Permalink
Fixed validation on ParameterPropertyList_t (#2837)
Browse files Browse the repository at this point in the history
* Fixed validation on ParameterPropertyList_t

Signed-off-by: Miguel Company <[email protected]>

* Refs #15155. Added regression test.

Signed-off-by: Miguel Company <[email protected]>
  • Loading branch information
MiguelCompany authored Jul 20, 2022
1 parent ede9a12 commit 50c1ee5
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/cpp/fastdds/core/policy/ParameterSerializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ inline bool ParameterSerializer<ParameterPropertyList_t>::read_content_from_cdr_
//Nproperties_ = num_properties;

uint32_t length_diff = cdr_message->pos - pos_ref;
valid &= (parameter_length == length_diff);
valid &= (parameter_length >= length_diff);
return valid;
}

Expand Down
80 changes: 79 additions & 1 deletion test/unittest/rtps/builtin/BuiltinDataSerializationTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include <fastrtps/rtps/builtin/data/WriterProxyData.h>
#include <fastrtps/rtps/builtin/data/ParticipantProxyData.h>
#include <fastrtps/rtps/builtin/data/ReaderProxyData.h>
#include <fastrtps/rtps/builtin/data/WriterProxyData.h>
#include <fastrtps/rtps/network/NetworkFactory.h>
#include <fastdds/core/policy/ParameterSerializer.hpp>

Expand Down Expand Up @@ -347,6 +348,83 @@ TEST(BuiltinDataSerializationTests, ignore_unsupported_type_object)
}
}

TEST(BuiltinDataSerializationTests, property_list_with_binary_properties)
{
octet data_p_buffer[] =
{
// Encapsulation
0x00, 0x03, 0x00, 0x00,

// PID_PROPERTY_LIST
0x59, 0, 104, 0,
// 3 properties
0x03, 0x00, 0x00, 0x00,
// key-1
0x0e, 0x00, 0x00, 0x00,
0x5f, 0x5f, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x4e, 0x61, 0x6d, 0x65, 0x00, 0x00, 0x00,
// value-1
0x07, 0x00, 0x00, 0x00,
0x74, 0x61, 0x6c, 0x6b, 0x65, 0x72, 0x00, 0x00,
// key-2
0x06, 0x00, 0x00, 0x00,
0x5f, 0x5f, 0x50, 0x69, 0x64, 0x00, 0x00, 0x00,
// value-2
0x05, 0x00, 0x00, 0x00,
0x32, 0x35, 0x31, 0x39, 0x00, 0x00, 0x00, 0x00,
// key-3
0x0b, 0x00, 0x00, 0x00,
0x5f, 0x5f, 0x48, 0x6f, 0x73, 0x74, 0x6e, 0x61, 0x6d, 0x65, 0x00, 0x00,
// value-3
0x11, 0x00, 0x00, 0x00,
0x6e, 0x6f, 0x6e, 0x5f, 0x77, 0x6f, 0x72, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x68, 0x61, 0x73, 0x68,
0x00, 0x00, 0x00, 0x00,
// 0 binary properties
0x00, 0x00, 0x00, 0x00,

// PID_PROTOCOL_VERSION
0x15, 0, 4, 0,
2, 1, 0, 0,

// PID_VENDORID
0x16, 0, 4, 0,
1, 16, 0, 0,

// PID_PARTICIPANT_LEASE_DURATION
0x02, 0, 8, 0,
10, 0, 0, 0, 0, 0, 0, 0,

// PID_PARTICIPANT_GUID
0x50, 0, 16, 0,
1, 16, 54, 83, 136, 247, 149, 252, 47, 105, 174, 141, 0, 0, 1, 193,

// PID_BUILTIN_ENDPOINT_SET
0x58, 0, 4, 0,
63, 12, 0, 0,

// PID_DOMAIN_ID
0x0f, 0, 4, 0,
0, 0, 0, 0,

// PID_DEFAULT_UNICAST_LOCATOR
0x31, 0, 24, 0,
1, 0, 0, 0, 68, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 31, 133, 54,

// PID_METATRAFFIC_UNICAST_LOCATOR
0x32, 0, 24, 0,
1, 0, 0, 0, 68, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 31, 133, 54,

// PID_SENTINEL
0x01, 0, 0, 0
};

CDRMessage_t msg(0);
msg.init(data_p_buffer, static_cast<uint32_t>(sizeof(data_p_buffer)));
msg.length = msg.max_size;

ParticipantProxyData out(RTPSParticipantAllocationAttributes{});
EXPECT_NO_THROW(EXPECT_TRUE(out.readFromCDRMessage(&msg, true, network, false)));
}

/*!
* \test RTPS-CFT-CFP-01 Tests serialization of `ContentFilterProperty_t` works successfully without parameters.
*/
Expand Down
5 changes: 5 additions & 0 deletions test/unittest/rtps/builtin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ set(BUILTIN_DATA_SERIALIZATION_TESTS_SOURCE BuiltinDataSerializationTests.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/policy/ParameterList.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/publisher/qos/WriterQos.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/qos/ReaderQos.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/data/ParticipantProxyData.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/data/ReaderProxyData.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/data/WriterProxyData.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/FlowControllerConsts.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/resources/ResourceEvent.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/resources/TimedEvent.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/resources/TimedEventImpl.cpp

${PROJECT_SOURCE_DIR}/src/cpp/rtps/common/Time_t.cpp

Expand Down Expand Up @@ -54,6 +58,7 @@ set(BUILTIN_DATA_SERIALIZATION_TESTS_SOURCE BuiltinDataSerializationTests.cpp
${PROJECT_SOURCE_DIR}/src/cpp/utils/IPLocator.cpp
${PROJECT_SOURCE_DIR}/src/cpp/utils/md5.cpp
${PROJECT_SOURCE_DIR}/src/cpp/utils/string_convert.cpp
${PROJECT_SOURCE_DIR}/src/cpp/utils/TimedConditionVariable.cpp
)

if(WIN32)
Expand Down

0 comments on commit 50c1ee5

Please sign in to comment.