Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix potential bad_optional_access crash in connectivity manager #912

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/ocpp/v201/connectivity_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,13 @@ void ConnectivityManager::try_connect_websocket() {

const int configuration_slot_to_set =
this->pending_configuration_slot.value_or(this->get_active_network_configuration_slot());
const std::optional<int> priority_to_set = this->get_priority_from_configuration_slot(configuration_slot_to_set);
const auto network_connection_profile = this->get_network_connection_profile(configuration_slot_to_set);
// Not const as the iface member can be set by the configure network connection profile callback
auto connection_options = this->get_ws_connection_options(configuration_slot_to_set);
bool can_use_connection_profile = true;

if (!network_connection_profile.has_value()) {
if (!network_connection_profile.has_value() || !priority_to_set.has_value()) {
EVLOG_warning << "No network connection profile configured for " << configuration_slot_to_set;
can_use_connection_profile = false;
} else if (!connection_options.has_value()) {
Expand Down Expand Up @@ -211,8 +212,7 @@ void ConnectivityManager::try_connect_websocket() {
}

this->pending_configuration_slot.reset();
this->active_network_configuration_priority =
get_priority_from_configuration_slot(configuration_slot_to_set).value();
this->active_network_configuration_priority = priority_to_set.value();

if (connection_options->security_profile ==
security::OCPP_1_6_ONLY_UNSECURED_TRANSPORT_WITHOUT_BASIC_AUTHENTICATION) {
Expand Down