-
Notifications
You must be signed in to change notification settings - Fork 793
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bad-free when receiving malformed DATA submessage (#3861)
* Refs #16784. Added basic custom chaining transport. Signed-off-by: Miguel Company <MiguelCompany@eprosima.com> * Refs #16784. Use custom transport to get list of receiver interfaces. Signed-off-by: Miguel Company <MiguelCompany@eprosima.com> * Refs #16784. Added regression file. Signed-off-by: Miguel Company <MiguelCompany@eprosima.com> * Refs #16784. Processing regression files. Signed-off-by: Miguel Company <MiguelCompany@eprosima.com> * Refs #16784. Separation of transport and descriptor. Signed-off-by: Miguel Company <MiguelCompany@eprosima.com> * Refs #16784. Small refactor. Signed-off-by: Miguel Company <MiguelCompany@eprosima.com> * Refs #16784. Fix issue. Signed-off-by: Miguel Company <MiguelCompany@eprosima.com> * Refs #19416. Fix build error in Mac. Signed-off-by: Miguel Company <MiguelCompany@eprosima.com> * Refs #19416. Fix include order. Signed-off-by: Miguel Company <MiguelCompany@eprosima.com> --------- Signed-off-by: Miguel Company <MiguelCompany@eprosima.com> (cherry picked from commit 47fe5d7) Co-authored-by: Miguel Company <miguelcompany@eprosima.com>
- Loading branch information
1 parent
208ca45
commit e197fff
Showing
6 changed files
with
203 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "./DatagramInjectionTransport.hpp" | ||
|
||
namespace eprosima { | ||
namespace fastdds { | ||
namespace rtps { | ||
|
||
DatagramInjectionTransportDescriptor::DatagramInjectionTransportDescriptor( | ||
std::shared_ptr<TransportDescriptorInterface> low_level) | ||
: ChainingTransportDescriptor(low_level) | ||
{ | ||
} | ||
|
||
TransportInterface* DatagramInjectionTransportDescriptor::create_transport() const | ||
{ | ||
return new DatagramInjectionTransport(const_cast<DatagramInjectionTransportDescriptor*>(this)); | ||
} | ||
|
||
void DatagramInjectionTransportDescriptor::add_receiver( | ||
TransportReceiverInterface* receiver_interface) | ||
{ | ||
std::lock_guard<std::mutex> guard(mtx_); | ||
receivers_.insert(receiver_interface); | ||
} | ||
|
||
std::set<TransportReceiverInterface*> DatagramInjectionTransportDescriptor::get_receivers() | ||
{ | ||
std::lock_guard<std::mutex> guard(mtx_); | ||
return receivers_; | ||
} | ||
|
||
} // namespace rtps | ||
} // namespace fastdds | ||
} // namespace eprosima |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <mutex> | ||
#include <set> | ||
|
||
#include <fastdds/rtps/transport/ChainingTransport.h> | ||
#include <fastdds/rtps/transport/ChainingTransportDescriptor.h> | ||
|
||
namespace eprosima { | ||
namespace fastdds { | ||
namespace rtps { | ||
|
||
class DatagramInjectionTransportDescriptor : public ChainingTransportDescriptor | ||
{ | ||
|
||
public: | ||
|
||
DatagramInjectionTransportDescriptor( | ||
std::shared_ptr<TransportDescriptorInterface> low_level); | ||
|
||
TransportInterface* create_transport() const override; | ||
|
||
void add_receiver( | ||
TransportReceiverInterface* receiver_interface); | ||
|
||
std::set<TransportReceiverInterface*> get_receivers(); | ||
|
||
private: | ||
|
||
std::mutex mtx_; | ||
std::set<TransportReceiverInterface*> receivers_; | ||
}; | ||
|
||
class DatagramInjectionTransport : public ChainingTransport | ||
{ | ||
public: | ||
|
||
DatagramInjectionTransport( | ||
DatagramInjectionTransportDescriptor* parent) | ||
: ChainingTransport(*parent) | ||
, parent_(parent) | ||
{ | ||
} | ||
|
||
TransportDescriptorInterface* get_configuration() override | ||
{ | ||
return parent_; | ||
} | ||
|
||
bool send( | ||
eprosima::fastrtps::rtps::SenderResource* /*low_sender_resource*/, | ||
const eprosima::fastrtps::rtps::octet* /*send_buffer*/, | ||
uint32_t /*send_buffer_size*/, | ||
eprosima::fastrtps::rtps::LocatorsIterator* /*destination_locators_begin*/, | ||
eprosima::fastrtps::rtps::LocatorsIterator* /*destination_locators_end*/, | ||
const std::chrono::steady_clock::time_point& /*timeout*/) override | ||
{ | ||
return true; | ||
} | ||
|
||
void receive( | ||
TransportReceiverInterface* /*next_receiver*/, | ||
const eprosima::fastrtps::rtps::octet* /*receive_buffer*/, | ||
uint32_t /*receive_buffer_size*/, | ||
const eprosima::fastrtps::rtps::Locator_t& /*local_locator*/, | ||
const eprosima::fastrtps::rtps::Locator_t& /*remote_locator*/) override | ||
{ | ||
} | ||
|
||
bool OpenInputChannel( | ||
const eprosima::fastrtps::rtps::Locator_t& loc, | ||
TransportReceiverInterface* receiver_interface, | ||
uint32_t max_message_size) override | ||
{ | ||
bool ret_val = ChainingTransport::OpenInputChannel(loc, receiver_interface, max_message_size); | ||
if (ret_val) | ||
{ | ||
parent_->add_receiver(receiver_interface); | ||
} | ||
return ret_val; | ||
} | ||
|
||
private: | ||
|
||
DatagramInjectionTransportDescriptor* parent_ = nullptr; | ||
}; | ||
|
||
} // namespace rtps | ||
} // namespace fastdds | ||
} // namespace eprosima |
Binary file not shown.