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

Side by Side Diff: content/browser/appcache/appcache_host.cc

Issue 1418783005: Fix possible map::end() dereference in AppCacheUpdateJob triggered by a compromised renderer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move check to host, add unittest Created 5 years, 1 month 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "content/browser/appcache/appcache_host.h" 5 #include "content/browser/appcache/appcache_host.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "content/browser/appcache/appcache.h" 10 #include "content/browser/appcache/appcache.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 } 73 }
74 74
75 void AppCacheHost::AddObserver(Observer* observer) { 75 void AppCacheHost::AddObserver(Observer* observer) {
76 observers_.AddObserver(observer); 76 observers_.AddObserver(observer);
77 } 77 }
78 78
79 void AppCacheHost::RemoveObserver(Observer* observer) { 79 void AppCacheHost::RemoveObserver(Observer* observer) {
80 observers_.RemoveObserver(observer); 80 observers_.RemoveObserver(observer);
81 } 81 }
82 82
83 void AppCacheHost::SelectCache(const GURL& document_url, 83 bool AppCacheHost::SelectCache(const GURL& document_url,
84 const int64 cache_document_was_loaded_from, 84 const int64 cache_document_was_loaded_from,
85 const GURL& manifest_url) { 85 const GURL& manifest_url) {
86 if (was_select_cache_called_)
87 return false;
88
86 DCHECK(pending_start_update_callback_.is_null() && 89 DCHECK(pending_start_update_callback_.is_null() &&
87 pending_swap_cache_callback_.is_null() && 90 pending_swap_cache_callback_.is_null() &&
88 pending_get_status_callback_.is_null() && 91 pending_get_status_callback_.is_null() &&
89 !is_selection_pending() && !was_select_cache_called_); 92 !is_selection_pending());
90 93
91 was_select_cache_called_ = true; 94 was_select_cache_called_ = true;
92 if (!is_cache_selection_enabled_) { 95 if (!is_cache_selection_enabled_) {
93 FinishCacheSelection(NULL, NULL); 96 FinishCacheSelection(NULL, NULL);
94 return; 97 return true;
95 } 98 }
96 99
97 origin_in_use_ = document_url.GetOrigin(); 100 origin_in_use_ = document_url.GetOrigin();
98 if (service()->quota_manager_proxy() && !origin_in_use_.is_empty()) 101 if (service()->quota_manager_proxy() && !origin_in_use_.is_empty())
99 service()->quota_manager_proxy()->NotifyOriginInUse(origin_in_use_); 102 service()->quota_manager_proxy()->NotifyOriginInUse(origin_in_use_);
100 103
101 if (main_resource_blocked_) 104 if (main_resource_blocked_)
102 frontend_->OnContentBlocked(host_id_, 105 frontend_->OnContentBlocked(host_id_,
103 blocked_manifest_url_); 106 blocked_manifest_url_);
104 107
105 // 6.9.6 The application cache selection algorithm. 108 // 6.9.6 The application cache selection algorithm.
106 // The algorithm is started here and continues in FinishCacheSelection, 109 // The algorithm is started here and continues in FinishCacheSelection,
107 // after cache or group loading is complete. 110 // after cache or group loading is complete.
108 // Note: Foreign entries are detected on the client side and 111 // Note: Foreign entries are detected on the client side and
109 // MarkAsForeignEntry is called in that case, so that detection 112 // MarkAsForeignEntry is called in that case, so that detection
110 // step is skipped here. See WebApplicationCacheHostImpl.cc 113 // step is skipped here. See WebApplicationCacheHostImpl.cc
111 114
112 if (cache_document_was_loaded_from != kAppCacheNoCacheId) { 115 if (cache_document_was_loaded_from != kAppCacheNoCacheId) {
113 LoadSelectedCache(cache_document_was_loaded_from); 116 LoadSelectedCache(cache_document_was_loaded_from);
114 return; 117 return true;
115 } 118 }
116 119
117 if (!manifest_url.is_empty() && 120 if (!manifest_url.is_empty() &&
118 (manifest_url.GetOrigin() == document_url.GetOrigin())) { 121 (manifest_url.GetOrigin() == document_url.GetOrigin())) {
119 DCHECK(!first_party_url_.is_empty()); 122 DCHECK(!first_party_url_.is_empty());
120 AppCachePolicy* policy = service()->appcache_policy(); 123 AppCachePolicy* policy = service()->appcache_policy();
121 if (policy && 124 if (policy &&
122 !policy->CanCreateAppCache(manifest_url, first_party_url_)) { 125 !policy->CanCreateAppCache(manifest_url, first_party_url_)) {
123 FinishCacheSelection(NULL, NULL); 126 FinishCacheSelection(NULL, NULL);
124 std::vector<int> host_ids(1, host_id_); 127 std::vector<int> host_ids(1, host_id_);
125 frontend_->OnEventRaised(host_ids, APPCACHE_CHECKING_EVENT); 128 frontend_->OnEventRaised(host_ids, APPCACHE_CHECKING_EVENT);
126 frontend_->OnErrorEventRaised( 129 frontend_->OnErrorEventRaised(
127 host_ids, 130 host_ids,
128 AppCacheErrorDetails( 131 AppCacheErrorDetails(
129 "Cache creation was blocked by the content policy", 132 "Cache creation was blocked by the content policy",
130 APPCACHE_POLICY_ERROR, 133 APPCACHE_POLICY_ERROR,
131 GURL(), 134 GURL(),
132 0, 135 0,
133 false /*is_cross_origin*/)); 136 false /*is_cross_origin*/));
134 frontend_->OnContentBlocked(host_id_, manifest_url); 137 frontend_->OnContentBlocked(host_id_, manifest_url);
135 return; 138 return true;
136 } 139 }
137 140
138 // Note: The client detects if the document was not loaded using HTTP GET 141 // Note: The client detects if the document was not loaded using HTTP GET
139 // and invokes SelectCache without a manifest url, so that detection step 142 // and invokes SelectCache without a manifest url, so that detection step
140 // is also skipped here. See WebApplicationCacheHostImpl.cc 143 // is also skipped here. See WebApplicationCacheHostImpl.cc
141 set_preferred_manifest_url(manifest_url); 144 set_preferred_manifest_url(manifest_url);
142 new_master_entry_url_ = document_url; 145 new_master_entry_url_ = document_url;
143 LoadOrCreateGroup(manifest_url); 146 LoadOrCreateGroup(manifest_url);
144 return; 147 return true;
145 } 148 }
146 149
147 // TODO(michaeln): If there was a manifest URL, the user agent may report 150 // TODO(michaeln): If there was a manifest URL, the user agent may report
148 // to the user that it was ignored, to aid in application development. 151 // to the user that it was ignored, to aid in application development.
149 FinishCacheSelection(NULL, NULL); 152 FinishCacheSelection(NULL, NULL);
153 return true;
150 } 154 }
151 155
152 void AppCacheHost::SelectCacheForWorker(int parent_process_id, 156 bool AppCacheHost::SelectCacheForWorker(int parent_process_id,
153 int parent_host_id) { 157 int parent_host_id) {
158 if (was_select_cache_called_)
159 return false;
160
154 DCHECK(pending_start_update_callback_.is_null() && 161 DCHECK(pending_start_update_callback_.is_null() &&
155 pending_swap_cache_callback_.is_null() && 162 pending_swap_cache_callback_.is_null() &&
156 pending_get_status_callback_.is_null() && 163 pending_get_status_callback_.is_null() &&
157 !is_selection_pending() && !was_select_cache_called_); 164 !is_selection_pending());
158 165
159 was_select_cache_called_ = true; 166 was_select_cache_called_ = true;
160 parent_process_id_ = parent_process_id; 167 parent_process_id_ = parent_process_id;
161 parent_host_id_ = parent_host_id; 168 parent_host_id_ = parent_host_id;
162 FinishCacheSelection(NULL, NULL); 169 FinishCacheSelection(NULL, NULL);
170 return true;
163 } 171 }
164 172
165 void AppCacheHost::SelectCacheForSharedWorker(int64 appcache_id) { 173 bool AppCacheHost::SelectCacheForSharedWorker(int64 appcache_id) {
174 if (was_select_cache_called_)
175 return false;
176
166 DCHECK(pending_start_update_callback_.is_null() && 177 DCHECK(pending_start_update_callback_.is_null() &&
167 pending_swap_cache_callback_.is_null() && 178 pending_swap_cache_callback_.is_null() &&
168 pending_get_status_callback_.is_null() && 179 pending_get_status_callback_.is_null() &&
169 !is_selection_pending() && !was_select_cache_called_); 180 !is_selection_pending());
170 181
171 was_select_cache_called_ = true; 182 was_select_cache_called_ = true;
172 if (appcache_id != kAppCacheNoCacheId) { 183 if (appcache_id != kAppCacheNoCacheId) {
173 LoadSelectedCache(appcache_id); 184 LoadSelectedCache(appcache_id);
174 return; 185 return true;
175 } 186 }
176 FinishCacheSelection(NULL, NULL); 187 FinishCacheSelection(NULL, NULL);
188 return true;
177 } 189 }
178 190
179 // TODO(michaeln): change method name to MarkEntryAsForeign for consistency 191 // TODO(michaeln): change method name to MarkEntryAsForeign for consistency
180 void AppCacheHost::MarkAsForeignEntry(const GURL& document_url, 192 bool AppCacheHost::MarkAsForeignEntry(const GURL& document_url,
181 int64 cache_document_was_loaded_from) { 193 int64 cache_document_was_loaded_from) {
194 if (was_select_cache_called_)
195 return false;
196
182 // The document url is not the resource url in the fallback case. 197 // The document url is not the resource url in the fallback case.
183 storage()->MarkEntryAsForeign( 198 storage()->MarkEntryAsForeign(
184 main_resource_was_namespace_entry_ ? namespace_entry_url_ : document_url, 199 main_resource_was_namespace_entry_ ? namespace_entry_url_ : document_url,
185 cache_document_was_loaded_from); 200 cache_document_was_loaded_from);
186 SelectCache(document_url, kAppCacheNoCacheId, GURL()); 201 SelectCache(document_url, kAppCacheNoCacheId, GURL());
202 return true;
187 } 203 }
188 204
189 void AppCacheHost::GetStatusWithCallback(const GetStatusCallback& callback, 205 void AppCacheHost::GetStatusWithCallback(const GetStatusCallback& callback,
190 void* callback_param) { 206 void* callback_param) {
191 DCHECK(pending_start_update_callback_.is_null() && 207 DCHECK(pending_start_update_callback_.is_null() &&
192 pending_swap_cache_callback_.is_null() && 208 pending_swap_cache_callback_.is_null() &&
193 pending_get_status_callback_.is_null()); 209 pending_get_status_callback_.is_null());
194 210
195 pending_get_status_callback_ = callback; 211 pending_get_status_callback_ = callback;
196 pending_callback_param_ = callback_param; 212 pending_callback_param_ = callback_param;
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 associated_cache_info_pending_ = cache && !cache->is_complete(); 567 associated_cache_info_pending_ = cache && !cache->is_complete();
552 AppCacheInfo info; 568 AppCacheInfo info;
553 if (cache) 569 if (cache)
554 cache->AssociateHost(this); 570 cache->AssociateHost(this);
555 571
556 FillCacheInfo(cache, manifest_url, GetStatus(), &info); 572 FillCacheInfo(cache, manifest_url, GetStatus(), &info);
557 frontend_->OnCacheSelected(host_id_, info); 573 frontend_->OnCacheSelected(host_id_, info);
558 } 574 }
559 575
560 } // namespace content 576 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/appcache/appcache_host.h ('k') | content/browser/appcache/appcache_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698