Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: chrome/installer/util/google_update_util.cc

Issue 180243021: Add google_update::GetUntrustedDataValueFromTag() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/installer/util/google_update_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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;
143 if (env == NULL || !env->GetVar(kEnvVariableUntrustedData, &data_string))
144 return false;
145
146 if (data_string.length() > kEnvVariableUntrustedDataMaxLength ||
147 !IsStringPrintable(data_string)) { 142 !IsStringPrintable(data_string)) {
148 LOG(ERROR) << "Invalid value in " << kEnvVariableUntrustedData; 143 LOG(ERROR) << "Invalid value in untrusted data string.";
149 return false; 144 return false;
150 } 145 }
151 146
152 VLOG(1) << kEnvVariableUntrustedData << ": " << data_string; 147 VLOG(1) << "Untrusted data string: " << data_string;
153 148
154 std::vector<std::pair<std::string, std::string> > kv_pairs; 149 std::vector<std::pair<std::string, std::string> > kv_pairs;
155 if (!base::SplitStringIntoKeyValuePairs(data_string, '=', '&', &kv_pairs)) { 150 if (!base::SplitStringIntoKeyValuePairs(data_string, '=', '&', &kv_pairs)) {
156 LOG(ERROR) << "Failed to parse untrusted data: " << data_string; 151 LOG(ERROR) << "Failed to parse untrusted data: " << data_string;
157 return false; 152 return false;
158 } 153 }
159 154
160 untrusted_data->clear(); 155 untrusted_data->clear();
161 std::vector<std::pair<std::string, std::string> >::const_iterator it; 156 std::vector<std::pair<std::string, std::string> >::const_iterator it;
162 for (it = kv_pairs.begin(); it != kv_pairs.end(); ++it) { 157 for (it = kv_pairs.begin(); it != kv_pairs.end(); ++it) {
163 const std::string& key(it->first); 158 const std::string& key(it->first);
164 // TODO(huangs): URL unescape |value|. 159 // TODO(huangs): URL unescape |value|.
165 const std::string& value(it->second); 160 const std::string& value(it->second);
166 if (IsUntrustedDataKeyValid(key) && IsStringPrintable(value)) 161 if (IsUntrustedDataKeyValid(key) && IsStringPrintable(value))
167 (*untrusted_data)[key] = value; 162 (*untrusted_data)[key] = value;
168 else 163 else
169 LOG(ERROR) << "Illegal character found in untrusted data."; 164 LOG(ERROR) << "Illegal character found in untrusted data.";
170 } 165 }
171 return true; 166 return true;
172 } 167 }
173 168
169 // Reads and parses untrusted data passed from Google Update as key-value
170 // pairs, then overwrites |untrusted_data_map| with the result.
171 // Returns true if data are successfully read.
172 bool GetGoogleUpdateUntrustedData(
173 std::map<std::string, std::string>* untrusted_data) {
174 scoped_ptr<base::Environment> env(base::Environment::Create());
175 std::string data_string;
176 if (!env || !env->GetVar(kEnvVariableUntrustedData, &data_string))
177 return false;
178
179 return ParseUntrustedData(data_string, untrusted_data);
180 }
181
174 } // namespace 182 } // namespace
175 183
176 bool EnsureUserLevelGoogleUpdatePresent() { 184 bool EnsureUserLevelGoogleUpdatePresent() {
177 VLOG(0) << "Ensuring Google Update is present at user-level."; 185 VLOG(0) << "Ensuring Google Update is present at user-level.";
178 186
179 bool success = false; 187 bool success = false;
180 if (IsGoogleUpdatePresent(false)) { 188 if (IsGoogleUpdatePresent(false)) {
181 success = true; 189 success = true;
182 } else { 190 } else {
183 base::string16 cmd_string; 191 base::string16 cmd_string;
(...skipping 30 matching lines...) Expand all
214 if (GetGoogleUpdateUntrustedData(&untrusted_data)) { 222 if (GetGoogleUpdateUntrustedData(&untrusted_data)) {
215 std::map<std::string, std::string>::const_iterator data_it( 223 std::map<std::string, std::string>::const_iterator data_it(
216 untrusted_data.find(key)); 224 untrusted_data.find(key));
217 if (data_it != untrusted_data.end()) 225 if (data_it != untrusted_data.end())
218 return data_it->second; 226 return data_it->second;
219 } 227 }
220 228
221 return std::string(); 229 return std::string();
222 } 230 }
223 231
232 std::string GetUntrustedDataValueFromTag(const std::string& tag,
233 const std::string& key) {
234 std::map<std::string, std::string> untrusted_data;
235 if (ParseUntrustedData(tag, &untrusted_data))
236 return untrusted_data[key];
237
238 return std::string();
239 }
240
224 } // namespace google_update 241 } // namespace google_update
OLDNEW
« no previous file with comments | « chrome/installer/util/google_update_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698