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

Side by Side Diff: sync/internal_api/attachments/attachment_downloader_impl.cc

Issue 1885993003: [Sync] Fix a subtle use-after-free in Attachments. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « no previous file | tools/valgrind/memcheck/suppressions.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "sync/internal_api/public/attachments/attachment_downloader_impl.h" 5 #include "sync/internal_api/public/attachments/attachment_downloader_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 access_token_request_.reset(); 131 access_token_request_.reset();
132 StateList::const_iterator iter; 132 StateList::const_iterator iter;
133 // Without access token all downloads fail. 133 // Without access token all downloads fail.
134 for (iter = requests_waiting_for_access_token_.begin(); 134 for (iter = requests_waiting_for_access_token_.begin();
135 iter != requests_waiting_for_access_token_.end(); 135 iter != requests_waiting_for_access_token_.end();
136 ++iter) { 136 ++iter) {
137 DownloadState* download_state = *iter; 137 DownloadState* download_state = *iter;
138 scoped_refptr<base::RefCountedString> null_attachment_data; 138 scoped_refptr<base::RefCountedString> null_attachment_data;
139 ReportResult(*download_state, DOWNLOAD_TRANSIENT_ERROR, 139 ReportResult(*download_state, DOWNLOAD_TRANSIENT_ERROR,
140 null_attachment_data); 140 null_attachment_data);
141 DCHECK(state_map_.find(download_state->attachment_url) != state_map_.end()); 141 // Don't delete using the URL directly to avoid an access after free error
142 state_map_.erase(download_state->attachment_url); 142 // due to std::unordered_map's implementation. See crbug.com/603275.
143 auto erase_iter = state_map_.find(download_state->attachment_url);
144 DCHECK(erase_iter != state_map_.end());
145 state_map_.erase(erase_iter);
143 } 146 }
144 requests_waiting_for_access_token_.clear(); 147 requests_waiting_for_access_token_.clear();
145 } 148 }
146 149
147 void AttachmentDownloaderImpl::OnURLFetchComplete( 150 void AttachmentDownloaderImpl::OnURLFetchComplete(
148 const net::URLFetcher* source) { 151 const net::URLFetcher* source) {
149 DCHECK(CalledOnValidThread()); 152 DCHECK(CalledOnValidThread());
150 153
151 // Find DownloadState by url. 154 // Find DownloadState by url.
152 AttachmentUrl url = source->GetOriginalURL().spec(); 155 AttachmentUrl url = source->GetOriginalURL().spec();
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 285
283 if (crc32c_raw.size() != sizeof(*crc32c)) 286 if (crc32c_raw.size() != sizeof(*crc32c))
284 return false; 287 return false;
285 288
286 *crc32c = 289 *crc32c =
287 base::NetToHost32(*reinterpret_cast<const uint32_t*>(crc32c_raw.c_str())); 290 base::NetToHost32(*reinterpret_cast<const uint32_t*>(crc32c_raw.c_str()));
288 return true; 291 return true;
289 } 292 }
290 293
291 } // namespace syncer 294 } // namespace syncer
OLDNEW
« no previous file with comments | « no previous file | tools/valgrind/memcheck/suppressions.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698