Commit 1f1947ae authored by Steven Bennetts's avatar Steven Bennetts Committed by Commit Bot

NetworkStateHandler: Avoid Matches call to uninitialized networks

Briefly: When a ManagedState entry is added to a list, no initial
properties have been received, so these entries are *mostly* ignored.

In NetworkTypePattern::Matches(), we have a DCHECK to help ensure that
uninitialized states are not used. That means that when we are
iterating through a list of networks, we need to avoid calling
Matches on ManagedState.type_.

This adds a convenience wrapper for places where we need this extra
test, and uses it in UpdateManagedList which is currently triggering
DCHECKs.

TBR=vecore@chromium.org

Bug: 1049808
Change-Id: I1a159622adb24b221849e1fa1a98ce89a3357744
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2050759
Auto-Submit: Steven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#741121}
parent 4b3472b5
......@@ -90,6 +90,13 @@ bool ShouldIncludeNetworkInList(const NetworkState* network_state,
return true;
}
// ManagedState entries may not have |type| set when the network is initially
// added to a list (i.e. before the initial properties are received). Use this
// wrapper anyplace where |managed| might be uninitialized.
bool TypeMatches(const ManagedState* managed, const NetworkTypePattern& type) {
return !managed->type().empty() && managed->Matches(type);
}
} // namespace
// Class for tracking properties that affect whether a NetworkState is active.
......@@ -966,7 +973,7 @@ void NetworkStateHandler::EnsureTetherDeviceState() {
}
bool NetworkStateHandler::UpdateBlockedByPolicy(NetworkState* network) const {
if (network->type().empty() || !network->Matches(NetworkTypePattern::WiFi()))
if (!TypeMatches(network, NetworkTypePattern::WiFi()))
return false;
bool prev_blocked_by_policy = network->blocked_by_policy();
......@@ -1270,11 +1277,11 @@ void NetworkStateHandler::UpdateManagedList(ManagedState::ManagedType type,
// Remove associations Tether NetworkStates had with now removed Wi-Fi
// NetworkStates.
for (auto& iter : managed_map) {
if (!iter.second->Matches(NetworkTypePattern::WiFi()))
ManagedState* managed = iter.second.get();
if (!TypeMatches(managed, NetworkTypePattern::WiFi()))
continue;
NetworkState* tether_network = GetModifiableNetworkStateFromGuid(
iter.second->AsNetworkState()->tether_guid());
managed->AsNetworkState()->tether_guid());
if (tether_network)
tether_network->set_tether_guid(std::string());
}
......@@ -1814,9 +1821,7 @@ DeviceState* NetworkStateHandler::GetModifiableDeviceState(
DeviceState* NetworkStateHandler::GetModifiableDeviceStateByType(
const NetworkTypePattern& type) const {
for (const auto& device : device_list_) {
if (device->type().empty())
continue; // kTypeProperty not set yet, skip.
if (device->Matches(type))
if (TypeMatches(device.get(), type))
return device->AsDeviceState();
}
return nullptr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment