Commit 3c111676 authored by pneubeck@chromium.org's avatar pneubeck@chromium.org

Don't copy empty GUID in CopyIdentifyingProperties.

This function copied an empty GUID leading to Shill not matching the right networks.
This change prevents copying an empty GUID and also checks that all other (required) identifying properties are non-empty.

BUG=280146

Review URL: https://chromiumcodereview.appspot.com/23819024

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221715 0039d316-1c4b-4281-b951-d872f2087c98
parent e7ec7c64
...@@ -43,12 +43,17 @@ std::string ValidateUTF8(const std::string& str) { ...@@ -43,12 +43,17 @@ std::string ValidateUTF8(const std::string& str) {
return result; return result;
} }
void CopyStringFromDictionary(const base::DictionaryValue& source, // If existent and non-empty, copies the string at |key| from |source| to
// |dest|. Returns true if the string was copied.
bool CopyStringFromDictionary(const base::DictionaryValue& source,
const std::string& key, const std::string& key,
base::DictionaryValue* dest) { base::DictionaryValue* dest) {
std::string string_value; std::string string_value;
if (source.GetStringWithoutPathExpansion(key, &string_value)) if (!source.GetStringWithoutPathExpansion(key, &string_value) ||
dest->SetStringWithoutPathExpansion(key, string_value); string_value.empty())
return false;
dest->SetStringWithoutPathExpansion(key, string_value);
return true;
} }
} // namespace } // namespace
...@@ -175,36 +180,45 @@ void SetUIData(const NetworkUIData& ui_data, ...@@ -175,36 +180,45 @@ void SetUIData(const NetworkUIData& ui_data,
bool CopyIdentifyingProperties(const base::DictionaryValue& service_properties, bool CopyIdentifyingProperties(const base::DictionaryValue& service_properties,
base::DictionaryValue* dest) { base::DictionaryValue* dest) {
bool success = true;
// GUID is optional.
CopyStringFromDictionary(service_properties, flimflam::kGuidProperty, dest); CopyStringFromDictionary(service_properties, flimflam::kGuidProperty, dest);
std::string type; std::string type;
service_properties.GetStringWithoutPathExpansion(flimflam::kTypeProperty, service_properties.GetStringWithoutPathExpansion(flimflam::kTypeProperty,
&type); &type);
success &= !type.empty();
dest->SetStringWithoutPathExpansion(flimflam::kTypeProperty, type); dest->SetStringWithoutPathExpansion(flimflam::kTypeProperty, type);
if (type == flimflam::kTypeWifi) { if (type == flimflam::kTypeWifi) {
CopyStringFromDictionary( success &= CopyStringFromDictionary(
service_properties, flimflam::kSecurityProperty, dest); service_properties, flimflam::kSecurityProperty, dest);
CopyStringFromDictionary(service_properties, flimflam::kSSIDProperty, dest); success &= CopyStringFromDictionary(
CopyStringFromDictionary(service_properties, flimflam::kModeProperty, dest); service_properties, flimflam::kSSIDProperty, dest);
success &= CopyStringFromDictionary(
service_properties, flimflam::kModeProperty, dest);
} else if (type == flimflam::kTypeVPN) { } else if (type == flimflam::kTypeVPN) {
CopyStringFromDictionary(service_properties, flimflam::kNameProperty, dest); success &= CopyStringFromDictionary(
service_properties, flimflam::kNameProperty, dest);
// VPN Provider values are read from the "Provider" dictionary, but written // VPN Provider values are read from the "Provider" dictionary, but written
// with the keys "Provider.Type" and "Provider.Host". // with the keys "Provider.Type" and "Provider.Host".
const base::DictionaryValue* provider_properties; const base::DictionaryValue* provider_properties = NULL;
if (!service_properties.GetDictionaryWithoutPathExpansion( if (!service_properties.GetDictionaryWithoutPathExpansion(
flimflam::kProviderProperty, &provider_properties)) { flimflam::kProviderProperty, &provider_properties)) {
LOG(ERROR) << "Incomplete Shill dictionary missing VPN provider dict."; NET_LOG_ERROR("CopyIdentifyingProperties", "Missing VPN provider dict");
return false; return false;
} }
std::string vpn_provider_type; std::string vpn_provider_type;
provider_properties->GetStringWithoutPathExpansion(flimflam::kTypeProperty, provider_properties->GetStringWithoutPathExpansion(flimflam::kTypeProperty,
&vpn_provider_type); &vpn_provider_type);
success &= !vpn_provider_type.empty();
dest->SetStringWithoutPathExpansion(flimflam::kProviderTypeProperty, dest->SetStringWithoutPathExpansion(flimflam::kProviderTypeProperty,
vpn_provider_type); vpn_provider_type);
std::string vpn_provider_host; std::string vpn_provider_host;
provider_properties->GetStringWithoutPathExpansion(flimflam::kHostProperty, provider_properties->GetStringWithoutPathExpansion(flimflam::kHostProperty,
&vpn_provider_host); &vpn_provider_host);
success &= !vpn_provider_host.empty();
dest->SetStringWithoutPathExpansion(flimflam::kProviderHostProperty, dest->SetStringWithoutPathExpansion(flimflam::kProviderHostProperty,
vpn_provider_host); vpn_provider_host);
} else if (type == flimflam::kTypeEthernet || } else if (type == flimflam::kTypeEthernet ||
...@@ -213,8 +227,11 @@ bool CopyIdentifyingProperties(const base::DictionaryValue& service_properties, ...@@ -213,8 +227,11 @@ bool CopyIdentifyingProperties(const base::DictionaryValue& service_properties,
// properties. // properties.
} else { } else {
NOTREACHED() << "Unsupported network type " << type; NOTREACHED() << "Unsupported network type " << type;
success = false;
} }
return true; if (!success)
NET_LOG_ERROR("CopyIdentifyingProperties", "Missing required properties");
return success;
} }
} // namespace shill_property_util } // namespace shill_property_util
......
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