Skip to content

Commit

Permalink
vsomeip 3.3.8
Browse files Browse the repository at this point in the history
Notes:
- Check buffer size when serializing/deserializing event registrations
- Remove leftovers from shm usage
- Avoid using uninitialized variable
- Displays lib version when starting any app
  • Loading branch information
DiogoPedrozza committed Jun 5, 2023
1 parent 2ea712c commit 0746484
Show file tree
Hide file tree
Showing 17 changed files with 106 additions and 65 deletions.
2 changes: 1 addition & 1 deletion Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ cc_library_shared {

cflags: [
"-DWITHOUT_SYSTEMD",
"-DVSOMEIP_COMPAT_VERSION=\"3.3.7\"",
"-DVSOMEIP_COMPAT_VERSION=\"3.3.8\"",
"-DVSOMEIP_BASE_PATH=\"/vendor/run/someip/\"",
"-DUSE_DLT",
],
Expand Down
8 changes: 4 additions & 4 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ LOCAL_CFLAGS := \
-frtti \
-fexceptions \
-DWITHOUT_SYSTEMD \
-DVSOMEIP_VERSION=\"3.3.7\" \
-DVSOMEIP_VERSION=\"3.3.8\" \
-DVSOMEIP_BASE_PATH=\"/vendor/run/someip/\" \
-Wno-unused-parameter \
-Wno-non-virtual-dtor \
Expand Down Expand Up @@ -147,7 +147,7 @@ LOCAL_CFLAGS := \
-frtti \
-fexceptions \
-DWITHOUT_SYSTEMD \
-DVSOMEIP_VERSION=\"3.3.7\" \
-DVSOMEIP_VERSION=\"3.3.8\" \
-DVSOMEIP_BASE_PATH=\"/vendor/run/someip/\" \
-Wno-unused-parameter \
-Wno-non-virtual-dtor \
Expand Down Expand Up @@ -194,8 +194,8 @@ LOCAL_CFLAGS := \
-frtti \
-fexceptions \
-DWITHOUT_SYSTEMD \
-DVSOMEIP_VERSION=\"3.3.7\" \
-DVSOMEIP_COMPAT_VERSION=\"3.3.7\" \
-DVSOMEIP_VERSION=\"3.3.8\" \
-DVSOMEIP_COMPAT_VERSION=\"3.3.8\" \
-DVSOMEIP_BASE_PATH=\"/vendor/run/someip/\" \
-Wno-unused-parameter \
-Wno-non-virtual-dtor \
Expand Down
8 changes: 7 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
Changes
=======
v3.3.8
- Check buffer size when serializing/deserializing event registrations
- Remove leftovers from shm usage
- Avoid using uninitialized variable
- Displays lib version when starting any app

v3.3.7
- Fix handling of endpoint options
- Fix build on Windows
Expand All @@ -20,7 +26,7 @@ v3.3.5.1
- Fix typo in application_impl.cpp
- Update load_balancing_option_impl.cpp
- Fix format specifier in memory_log_timer_cbk
- Isolate boost
- Prevent boost symbols from leaking into global namespace
- Remove redundant ostream manipulators
- Fix for configuration option deserialize bug
- Accept return codes within range 0x20 - 0x5E as valid
Expand Down
15 changes: 12 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ set (VSOMEIP_COMPAT_NAME vsomeip)

set (VSOMEIP_MAJOR_VERSION 3)
set (VSOMEIP_MINOR_VERSION 3)
set (VSOMEIP_PATCH_VERSION 7)
set (VSOMEIP_PATCH_VERSION 8)
set (VSOMEIP_HOTFIX_VERSION 0)

set (VSOMEIP_VERSION ${VSOMEIP_MAJOR_VERSION}.${VSOMEIP_MINOR_VERSION}.${VSOMEIP_PATCH_VERSION})
Expand Down Expand Up @@ -105,13 +105,22 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVSOMEIP_ENABLE_SIGNAL_HANDLING")
endif ()

if (NOT MSVC)
# Sanitizer
# Sanitizers

if (ENABLE_UNDEFINED_SANITIZER)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
endif ()

if (ENABLE_THREAD_SANITIZER)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
endif ()

if (ENABLE_LEAK_SANITIZER)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=leak")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=leak")
endif ()

if (ENABLE_ADDRESS_SANITIZER)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
endif ()

if (ENABLE_PROFILING)
Expand Down
1 change: 0 additions & 1 deletion implementation/configuration/include/configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ class configuration {

// File permissions
virtual std::uint32_t get_permissions_uds() const = 0;
virtual std::uint32_t get_permissions_shm() const = 0;

virtual bool log_version() const = 0;
virtual uint32_t get_log_version_interval() const = 0;
Expand Down
2 changes: 0 additions & 2 deletions implementation/configuration/include/configuration_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ class configuration_impl:
VSOMEIP_EXPORT uint32_t get_allowed_missing_pongs() const;

VSOMEIP_EXPORT std::uint32_t get_permissions_uds() const;
VSOMEIP_EXPORT std::uint32_t get_permissions_shm() const;

VSOMEIP_EXPORT bool check_routing_credentials(client_t _client,
const vsomeip_sec_client_t *_sec_client) const;
Expand Down Expand Up @@ -560,7 +559,6 @@ class configuration_impl:
};

bool is_configured_[ET_MAX];
std::uint32_t permissions_shm_;
std::uint32_t permissions_uds_;

std::string network_;
Expand Down
4 changes: 4 additions & 0 deletions implementation/configuration/include/internal.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@

#define VSOMEIP_ROUTING_READY_MESSAGE "@VSOMEIP_ROUTING_READY_MESSAGE@"

#ifndef VSOMEIP_VERSION
#define VSOMEIP_VERSION "unknown version"
#endif

namespace vsomeip_v3 {

typedef enum {
Expand Down
4 changes: 4 additions & 0 deletions implementation/configuration/include/internal_android.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@

#define VSOMEIP_ROUTING_READY_MESSAGE "SOME/IP routing ready."

#ifndef VSOMEIP_VERSION
#define VSOMEIP_VERSION "unknown version"
#endif

namespace vsomeip_v3 {

typedef enum {
Expand Down
12 changes: 1 addition & 11 deletions implementation/configuration/src/configuration_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ configuration_impl::configuration_impl(const std::string &_path)
watchdog_(std::make_shared<watchdog>()),
log_version_(true),
log_version_interval_(10),
permissions_shm_(VSOMEIP_DEFAULT_SHM_PERMISSION),
permissions_uds_(VSOMEIP_DEFAULT_UDS_PERMISSIONS),
network_("vsomeip"),
e2e_enabled_(false),
Expand Down Expand Up @@ -123,7 +122,6 @@ configuration_impl::configuration_impl(const configuration_impl &_other)
max_reliable_message_size_(_other.max_reliable_message_size_),
max_unreliable_message_size_(_other.max_unreliable_message_size_),
buffer_shrink_threshold_(_other.buffer_shrink_threshold_),
permissions_shm_(VSOMEIP_DEFAULT_SHM_PERMISSION),
permissions_uds_(VSOMEIP_DEFAULT_UDS_PERMISSIONS),
endpoint_queue_limit_external_(_other.endpoint_queue_limit_external_),
endpoint_queue_limit_local_(_other.endpoint_queue_limit_local_),
Expand Down Expand Up @@ -2427,11 +2425,7 @@ void configuration_impl::load_permissions(const configuration_element &_element)
++i) {
std::string its_key(i->first);
std::stringstream its_converter;
if (its_key == "permissions-shm") {
std::string its_value(i->second.data());
its_converter << std::oct << its_value;
its_converter >> permissions_shm_;
} else if (its_key == "permissions-uds") {
if (its_key == "permissions-uds") {
std::string its_value(i->second.data());
its_converter << std::oct << its_value;
its_converter >> permissions_uds_;
Expand Down Expand Up @@ -3460,10 +3454,6 @@ std::uint32_t configuration_impl::get_permissions_uds() const {
return permissions_uds_;
}

std::uint32_t configuration_impl::get_permissions_shm() const {
return permissions_shm_;
}

std::map<plugin_type_e, std::set<std::string>> configuration_impl::get_plugins(
const std::string &_name) const {

Expand Down
4 changes: 2 additions & 2 deletions implementation/protocol/include/register_event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class register_event {
bool is_provided = false, reliability_type_e reliability = reliability_type_e::RT_UNKNOWN,
bool is_cyclic = false, uint16_t num_eventg = 0,
const std::set<eventgroup_t> &eventgroups = std::set<eventgroup_t>());
void serialize(std::vector<byte_t> &_buffer, size_t &_offset) const;
void deserialize(const std::vector<byte_t> &_buffer, size_t &_offset);
void serialize(std::vector<byte_t> &_buffer, size_t &_offset, error_e &_error) const;
void deserialize(const std::vector<byte_t> &_buffer, size_t &_offset, error_e &_error);

service_t get_service() const { return service_; }
void set_service(service_t _service) { service_ = _service; }
Expand Down
40 changes: 38 additions & 2 deletions implementation/protocol/src/register_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,19 @@ register_event::register_event(service_t service, instance_t instance,
}

void
register_event::serialize(std::vector<byte_t> &_buffer, size_t &_offset) const {
register_event::serialize(std::vector<byte_t> &_buffer, size_t &_offset, error_e &_error) const {

size_t its_size(_offset
+ sizeof(service_) + sizeof(instance_)
+ sizeof(event_) + sizeof(event_type_)
+ sizeof(is_provided_) + sizeof(reliability_)
+ sizeof(is_cyclic_) + sizeof(num_eventg_));

// First check: Does the static part of the data fit into the buffer?
if (_buffer.size() < its_size) {
_error = error_e::ERROR_NOT_ENOUGH_BYTES;
return;
}

std::memcpy(&_buffer[_offset], &service_, sizeof(service_));
_offset += sizeof(service_);
Expand All @@ -35,14 +47,32 @@ register_event::serialize(std::vector<byte_t> &_buffer, size_t &_offset) const {
std::memcpy(&_buffer[_offset], &num_eventg_, sizeof(num_eventg_));
_offset += sizeof(num_eventg_);

// Second check: Does the dynamic part of the data fit into the buffer?
if (_buffer.size() < _offset + (num_eventg_ * sizeof(eventgroup_t))) {
_error = error_e::ERROR_NOT_ENOUGH_BYTES;
return;
}

for (const auto g : eventgroups_) {
std::memcpy(&_buffer[_offset], &g, sizeof(g));
_offset += sizeof(g);
}
}

void
register_event::deserialize(const std::vector<byte_t> &_buffer, size_t &_offset) {
register_event::deserialize(const std::vector<byte_t> &_buffer, size_t &_offset, error_e &_error) {

size_t its_size(_offset
+ sizeof(service_) + sizeof(instance_)
+ sizeof(event_) + sizeof(event_type_)
+ sizeof(is_provided_) + sizeof(reliability_)
+ sizeof(is_cyclic_) + sizeof(num_eventg_));

// First check: Does the buffer contain the full static part of the data?
if (_buffer.size() < its_size) {
_error = error_e::ERROR_NOT_ENOUGH_BYTES;
return;
}

std::memcpy(&service_, &_buffer[_offset], sizeof(service_));
_offset += sizeof(service_);
Expand All @@ -61,6 +91,12 @@ register_event::deserialize(const std::vector<byte_t> &_buffer, size_t &_offset)
std::memcpy(&num_eventg_, &_buffer[_offset], sizeof(num_eventg_));
_offset += sizeof(num_eventg_);

// Second check: Does the buffer contain the full dynamic part of the data?
if (_buffer.size() < _offset + (num_eventg_ * sizeof(eventgroup_t))) {
_error = error_e::ERROR_NOT_ENOUGH_BYTES;
return;
}

eventgroups_.clear();
for (size_t i = 0; i < num_eventg_; i++) {
eventgroup_t its_g;
Expand Down
37 changes: 17 additions & 20 deletions implementation/protocol/src/register_events_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,22 @@ register_events_command::add_registration(const register_event &_register_event)
+ sizeof(_register_event.is_provided()) + sizeof(_register_event.get_reliability())
+ sizeof(_register_event.is_cyclic()) + sizeof(_register_event.get_num_eventgroups())
+ (_register_event.get_num_eventgroups() * sizeof(eventgroup_t) ));
if (its_size > std::numeric_limits<command_size_t>::max()) {

// check size
if (its_size > std::numeric_limits<command_size_t>::max())
return false;
} else {
// set size
size_ = static_cast<command_size_t>(its_size - COMMAND_HEADER_SIZE);
registrations_.push_back(_register_event);
}

// set size
size_ = static_cast<command_size_t>(its_size - COMMAND_HEADER_SIZE);
registrations_.push_back(_register_event);

return true;
}

void
register_events_command::serialize(std::vector<byte_t> &_buffer, error_e &_error) const {

if (size_ + COMMAND_HEADER_SIZE> std::numeric_limits<command_size_t>::max()) {

if (size_ + COMMAND_HEADER_SIZE > std::numeric_limits<command_size_t>::max()) {
_error = error_e::ERROR_MAX_COMMAND_SIZE_EXCEEDED;
return;
}
Expand All @@ -54,7 +55,9 @@ register_events_command::serialize(std::vector<byte_t> &_buffer, error_e &_error
// serialize payload
size_t its_offset(COMMAND_HEADER_SIZE);
for(auto &reg : registrations_) {
reg.serialize(_buffer, its_offset);
reg.serialize(_buffer, its_offset, _error);
if (_error != error_e::ERROR_OK)
return;
}
}

Expand All @@ -74,18 +77,12 @@ register_events_command::deserialize(const std::vector<byte_t> &_buffer, error_e

size_t its_offset(COMMAND_HEADER_SIZE);

while(its_offset < _buffer.size()) {
size_t its_size(its_offset+ sizeof(service_t) + sizeof(instance_t)
+ sizeof(event_t) + sizeof(event_type_e)
+ sizeof(bool) + sizeof(bool) + sizeof(bool) + sizeof(uint16_t)
+ sizeof(eventgroup_t)); // at least one is needed
if (its_size > _buffer.size()) {
_error = error_e::ERROR_NOT_ENOUGH_BYTES;
return;
}

while (its_offset < _buffer.size()) {
register_event event_command;
event_command.deserialize(_buffer, its_offset);
event_command.deserialize(_buffer, its_offset, _error);
if (_error != error_e::ERROR_OK)
return;

registrations_.push_back(event_command);
}
}
Expand Down
4 changes: 0 additions & 4 deletions implementation/routing/src/routing_manager_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3395,10 +3395,6 @@ routing_manager_impl::expire_subscriptions(bool _force) {

void routing_manager_impl::log_version_timer_cbk(boost::system::error_code const & _error) {
if (!_error) {

#ifndef VSOMEIP_VERSION
#define VSOMEIP_VERSION "unknown version"
#endif
static int its_counter(0);
static uint32_t its_interval = configuration_->get_log_version_interval();

Expand Down
25 changes: 14 additions & 11 deletions implementation/routing/src/routing_manager_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ void routing_manager_stub::on_message(const byte_t *_data, length_t _size,
its_minor = its_command.get_minor();

if (VSOMEIP_SEC_OK == security::is_client_allowed_to_offer(
_sec_client, its_service, its_instance)) {
_sec_client, its_service, its_instance)) {
host_->offer_service(its_client, its_service, its_instance,
its_major, its_minor);
} else {
Expand Down Expand Up @@ -413,7 +413,7 @@ void routing_manager_stub::on_message(const byte_t *_data, length_t _size,
}
} else {
if (VSOMEIP_SEC_OK == security::is_client_allowed_to_access_member(
_sec_client, its_service, its_instance, its_notifier)) {
_sec_client, its_service, its_instance, its_notifier)) {
host_->subscribe(its_client, _sec_client, its_service, its_instance,
its_eventgroup, its_major, its_notifier, its_filter);
} else {
Expand Down Expand Up @@ -571,7 +571,7 @@ void routing_manager_stub::on_message(const byte_t *_data, length_t _size,
// but check requests sent by local proxies to remote against policy.
if (utility::is_request(its_message_data[VSOMEIP_MESSAGE_TYPE_POS])) {
if (VSOMEIP_SEC_OK != security::is_client_allowed_to_access_member(
_sec_client, its_service, its_instance, its_method)) {
_sec_client, its_service, its_instance, its_method)) {
VSOMEIP_WARNING << "vSomeIP Security: Client 0x" << std::hex << its_client
<< " : routing_manager_stub::on_message: "
<< " isn't allowed to send a request to service/instance/method "
Expand Down Expand Up @@ -644,7 +644,7 @@ void routing_manager_stub::on_message(const byte_t *_data, length_t _size,
std::set<protocol::service> its_allowed_requests;
for (const auto &r : its_requests) {
if (VSOMEIP_SEC_OK == security::is_client_allowed_to_request(
_sec_client, r.service_, r.instance_)) {
_sec_client, r.service_, r.instance_)) {
host_->request_service(its_client,
r.service_, r.instance_, r.major_, r.minor_);
its_allowed_requests.insert(r);
Expand Down Expand Up @@ -836,14 +836,17 @@ void routing_manager_stub::on_register_application(client_t _client) {
vsomeip_sec_client_t its_sec_client;
std::set<std::shared_ptr<policy> > its_policies;

policy_manager_impl::get()->get_client_to_sec_client_mapping(_client, its_sec_client);
if (its_sec_client.client_type == VSOMEIP_CLIENT_UDS) {
get_requester_policies(its_sec_client.client.uds_client.user,
its_sec_client.client.uds_client.group, its_policies);
}
bool has_mapping = policy_manager_impl::get()
->get_client_to_sec_client_mapping(_client, its_sec_client);
if (has_mapping) {
if (its_sec_client.client_type == VSOMEIP_CLIENT_UDS) {
get_requester_policies(its_sec_client.client.uds_client.user,
its_sec_client.client.uds_client.group, its_policies);
}

if (!its_policies.empty())
send_requester_policies({ _client }, its_policies);
if (!its_policies.empty())
send_requester_policies({ _client }, its_policies);
}
}
#endif // !VSOMEIP_DISABLE_SECURITY
}
Expand Down
Loading

0 comments on commit 0746484

Please sign in to comment.