Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/installer/util/google_update_util.h" | 5 #include "chrome/installer/util/google_update_util.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 | 27 |
| 28 using base::win::RegKey; | 28 using base::win::RegKey; |
| 29 | 29 |
| 30 namespace google_update { | 30 namespace google_update { |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 const int kGoogleUpdateTimeoutMs = 20 * 1000; | 34 const int kGoogleUpdateTimeoutMs = 20 * 1000; |
| 35 | 35 |
| 36 const char kEnvVariableUntrustedData[] = "GoogleUpdateUntrustedData"; | 36 const char kEnvVariableUntrustedData[] = "GoogleUpdateUntrustedData"; |
| 37 const int kEnvVariableUntrustedDataMaxLength = 4096; | 37 const int kUntrustedDataMaxLength = 4096; |
| 38 | 38 |
| 39 // Returns true if Google Update is present at the given level. | 39 // Returns true if Google Update is present at the given level. |
| 40 bool IsGoogleUpdatePresent(bool system_install) { | 40 bool IsGoogleUpdatePresent(bool system_install) { |
| 41 // Using the existence of version key in the registry to decide. | 41 // Using the existence of version key in the registry to decide. |
| 42 return GoogleUpdateSettings::GetGoogleUpdateVersion(system_install).IsValid(); | 42 return GoogleUpdateSettings::GetGoogleUpdateVersion(system_install).IsValid(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 // Returns GoogleUpdateSetup.exe's executable path at specified level. | 45 // Returns GoogleUpdateSetup.exe's executable path at specified level. |
| 46 // or an empty path if none is found. | 46 // or an empty path if none is found. |
| 47 base::FilePath GetGoogleUpdateSetupExe(bool system_install) { | 47 base::FilePath GetGoogleUpdateSetupExe(bool system_install) { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 return !(c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || | 125 return !(c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || |
| 126 c >= '0' && c <= '9' || c == '-' || c == '_' || c == '$'); | 126 c >= '0' && c <= '9' || c == '-' || c == '_' || c == '$'); |
| 127 } | 127 } |
| 128 | 128 |
| 129 // Returns true if |key| from untrusted data is valid. | 129 // Returns true if |key| from untrusted data is valid. |
| 130 bool IsUntrustedDataKeyValid(const std::string& key) { | 130 bool IsUntrustedDataKeyValid(const std::string& key) { |
| 131 return std::find_if(key.begin(), key.end(), IsIllegalUntrustedDataKeyChar) | 131 return std::find_if(key.begin(), key.end(), IsIllegalUntrustedDataKeyChar) |
| 132 == key.end(); | 132 == key.end(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 // Reads and parses untrusted data passed from Google Update as key-value | 135 // Parses |data_string| as key-value pairs and overwrites |untrusted_data| with |
| 136 // pairs, then overwrites |untrusted_data_map| with the result. | 136 // the result. Returns true if the data could be parsed. |
| 137 // Returns true if data are successfully read. | 137 bool ParseUntrustedData( |
| 138 bool GetGoogleUpdateUntrustedData( | 138 const std::string& data_string, |
| 139 std::map<std::string, std::string>* untrusted_data) { | 139 std::map<std::string, std::string>* untrusted_data) { |
| 140 DCHECK(untrusted_data); | 140 DCHECK(untrusted_data); |
| 141 scoped_ptr<base::Environment> env(base::Environment::Create()); | 141 if (data_string.length() > kUntrustedDataMaxLength) { |
| 142 std::string data_string; | 142 LOG(ERROR) << "Untrusted data string is too long."; |
| 143 if (env == NULL || !env->GetVar(kEnvVariableUntrustedData, &data_string)) | |
| 144 return false; | |
| 145 | |
| 146 if (data_string.length() > kEnvVariableUntrustedDataMaxLength || | |
| 147 !IsStringPrintable(data_string)) { | |
| 148 LOG(ERROR) << "Invalid value in " << kEnvVariableUntrustedData; | |
| 149 return false; | 143 return false; |
| 150 } | 144 } |
| 151 | 145 |
| 152 VLOG(1) << kEnvVariableUntrustedData << ": " << data_string; | 146 if (!IsStringPrintable(data_string)) { |
| 147 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.
| |
| 148 return false; | |
| 149 } | |
| 150 | |
| 151 VLOG(1) << "Untrusted data string: " << data_string; | |
| 153 | 152 |
| 154 std::vector<std::pair<std::string, std::string> > kv_pairs; | 153 std::vector<std::pair<std::string, std::string> > kv_pairs; |
| 155 if (!base::SplitStringIntoKeyValuePairs(data_string, '=', '&', &kv_pairs)) { | 154 if (!base::SplitStringIntoKeyValuePairs(data_string, '=', '&', &kv_pairs)) { |
| 156 LOG(ERROR) << "Failed to parse untrusted data: " << data_string; | 155 LOG(ERROR) << "Failed to parse untrusted data: " << data_string; |
| 157 return false; | 156 return false; |
| 158 } | 157 } |
| 159 | 158 |
| 160 untrusted_data->clear(); | 159 untrusted_data->clear(); |
| 161 std::vector<std::pair<std::string, std::string> >::const_iterator it; | 160 std::vector<std::pair<std::string, std::string> >::const_iterator it; |
| 162 for (it = kv_pairs.begin(); it != kv_pairs.end(); ++it) { | 161 for (it = kv_pairs.begin(); it != kv_pairs.end(); ++it) { |
| 163 const std::string& key(it->first); | 162 const std::string& key(it->first); |
| 164 // TODO(huangs): URL unescape |value|. | 163 // TODO(huangs): URL unescape |value|. |
| 165 const std::string& value(it->second); | 164 const std::string& value(it->second); |
| 166 if (IsUntrustedDataKeyValid(key) && IsStringPrintable(value)) | 165 if (IsUntrustedDataKeyValid(key) && IsStringPrintable(value)) |
| 167 (*untrusted_data)[key] = value; | 166 (*untrusted_data)[key] = value; |
| 168 else | 167 else |
| 169 LOG(ERROR) << "Illegal character found in untrusted data."; | 168 LOG(ERROR) << "Illegal character found in untrusted data."; |
| 170 } | 169 } |
| 171 return true; | 170 return true; |
| 172 } | 171 } |
| 173 | 172 |
| 173 // Reads and parses untrusted data passed from Google Update as key-value | |
| 174 // pairs, then overwrites |untrusted_data_map| with the result. | |
| 175 // Returns true if data are successfully read. | |
| 176 bool GetGoogleUpdateUntrustedData( | |
| 177 std::map<std::string, std::string>* untrusted_data) { | |
| 178 scoped_ptr<base::Environment> env(base::Environment::Create()); | |
| 179 std::string data_string; | |
| 180 if (!env || !env->GetVar(kEnvVariableUntrustedData, &data_string)) | |
| 181 return false; | |
| 182 | |
| 183 return ParseUntrustedData(data_string, untrusted_data); | |
| 184 } | |
| 185 | |
| 174 } // namespace | 186 } // namespace |
| 175 | 187 |
| 176 bool EnsureUserLevelGoogleUpdatePresent() { | 188 bool EnsureUserLevelGoogleUpdatePresent() { |
| 177 VLOG(0) << "Ensuring Google Update is present at user-level."; | 189 VLOG(0) << "Ensuring Google Update is present at user-level."; |
| 178 | 190 |
| 179 bool success = false; | 191 bool success = false; |
| 180 if (IsGoogleUpdatePresent(false)) { | 192 if (IsGoogleUpdatePresent(false)) { |
| 181 success = true; | 193 success = true; |
| 182 } else { | 194 } else { |
| 183 base::string16 cmd_string; | 195 base::string16 cmd_string; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 214 if (GetGoogleUpdateUntrustedData(&untrusted_data)) { | 226 if (GetGoogleUpdateUntrustedData(&untrusted_data)) { |
| 215 std::map<std::string, std::string>::const_iterator data_it( | 227 std::map<std::string, std::string>::const_iterator data_it( |
| 216 untrusted_data.find(key)); | 228 untrusted_data.find(key)); |
| 217 if (data_it != untrusted_data.end()) | 229 if (data_it != untrusted_data.end()) |
| 218 return data_it->second; | 230 return data_it->second; |
| 219 } | 231 } |
| 220 | 232 |
| 221 return std::string(); | 233 return std::string(); |
| 222 } | 234 } |
| 223 | 235 |
| 236 std::string GetUntrustedDataValueFromTag(const std::string& tag, | |
| 237 const std::string& key) { | |
| 238 std::map<std::string, std::string> untrusted_data; | |
| 239 if (ParseUntrustedData(tag, &untrusted_data)) | |
| 240 return untrusted_data[key]; | |
| 241 | |
| 242 return std::string(); | |
| 243 } | |
| 244 | |
| 224 } // namespace google_update | 245 } // namespace google_update |
| OLD | NEW |