Chromium Code Reviews| Index: chrome/installer/util/google_update_util.cc |
| diff --git a/chrome/installer/util/google_update_util.cc b/chrome/installer/util/google_update_util.cc |
| index 748e3f6c2fe07824bf7ec6711f8c225b143aff0d..d75f6ecd8052e9ac376dc9039cd52c214702af3a 100644 |
| --- a/chrome/installer/util/google_update_util.cc |
| +++ b/chrome/installer/util/google_update_util.cc |
| @@ -34,7 +34,7 @@ namespace { |
| const int kGoogleUpdateTimeoutMs = 20 * 1000; |
| const char kEnvVariableUntrustedData[] = "GoogleUpdateUntrustedData"; |
| -const int kEnvVariableUntrustedDataMaxLength = 4096; |
| +const int kUntrustedDataMaxLength = 4096; |
| // Returns true if Google Update is present at the given level. |
| bool IsGoogleUpdatePresent(bool system_install) { |
| @@ -132,24 +132,23 @@ bool IsUntrustedDataKeyValid(const std::string& key) { |
| == key.end(); |
| } |
| -// Reads and parses untrusted data passed from Google Update as key-value |
| -// pairs, then overwrites |untrusted_data_map| with the result. |
| -// Returns true if data are successfully read. |
| -bool GetGoogleUpdateUntrustedData( |
| +// Parses |data_string| as key-value pairs and overwrites |untrusted_data| with |
| +// the result. Returns true if the data could be parsed. |
| +bool ParseUntrustedData( |
| + const std::string& data_string, |
| std::map<std::string, std::string>* untrusted_data) { |
| DCHECK(untrusted_data); |
| - scoped_ptr<base::Environment> env(base::Environment::Create()); |
| - std::string data_string; |
| - if (env == NULL || !env->GetVar(kEnvVariableUntrustedData, &data_string)) |
| + if (data_string.length() > kUntrustedDataMaxLength) { |
| + LOG(ERROR) << "Untrusted data string is too long."; |
| return false; |
| + } |
| - if (data_string.length() > kEnvVariableUntrustedDataMaxLength || |
| - !IsStringPrintable(data_string)) { |
| - LOG(ERROR) << "Invalid value in " << kEnvVariableUntrustedData; |
| + if (!IsStringPrintable(data_string)) { |
| + LOG(ERROR) << "Invalid value in untrusted data string."; |
|
grt (UTC plus 2)
2014/03/04 15:55:59
i don't think we need two log statements for the c
jackhou1
2014/03/05 05:29:22
Done.
|
| return false; |
| } |
| - VLOG(1) << kEnvVariableUntrustedData << ": " << data_string; |
| + VLOG(1) << "Untrusted data string: " << data_string; |
| std::vector<std::pair<std::string, std::string> > kv_pairs; |
| if (!base::SplitStringIntoKeyValuePairs(data_string, '=', '&', &kv_pairs)) { |
| @@ -171,6 +170,19 @@ bool GetGoogleUpdateUntrustedData( |
| return true; |
| } |
| +// Reads and parses untrusted data passed from Google Update as key-value |
| +// pairs, then overwrites |untrusted_data_map| with the result. |
| +// Returns true if data are successfully read. |
| +bool GetGoogleUpdateUntrustedData( |
| + std::map<std::string, std::string>* untrusted_data) { |
| + scoped_ptr<base::Environment> env(base::Environment::Create()); |
| + std::string data_string; |
| + if (!env || !env->GetVar(kEnvVariableUntrustedData, &data_string)) |
| + return false; |
| + |
| + return ParseUntrustedData(data_string, untrusted_data); |
| +} |
| + |
| } // namespace |
| bool EnsureUserLevelGoogleUpdatePresent() { |
| @@ -221,4 +233,13 @@ std::string GetUntrustedDataValue(const std::string& key) { |
| return std::string(); |
| } |
| +std::string GetUntrustedDataValueFromTag(const std::string& tag, |
| + const std::string& key) { |
| + std::map<std::string, std::string> untrusted_data; |
| + if (ParseUntrustedData(tag, &untrusted_data)) |
| + return untrusted_data[key]; |
| + |
| + return std::string(); |
| +} |
| + |
| } // namespace google_update |