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

Side by Side Diff: ppapi/proxy/udp_socket_resource_base.cc

Issue 17247004: TCPSocket/UDPSocket: don't update internal state or access user buffers after Close(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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 | « no previous file | ppapi/shared_impl/tcp_socket_shared.cc » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "ppapi/proxy/udp_socket_resource_base.h" 5 #include "ppapi/proxy/udp_socket_resource_base.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cstring> 8 #include <cstring>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 return; 205 return;
206 206
207 bound_ = false; 207 bound_ = false;
208 closed_ = true; 208 closed_ = true;
209 209
210 Post(BROWSER, PpapiHostMsg_UDPSocket_Close()); 210 Post(BROWSER, PpapiHostMsg_UDPSocket_Close());
211 211
212 PostAbortIfNecessary(&bind_callback_); 212 PostAbortIfNecessary(&bind_callback_);
213 PostAbortIfNecessary(&recvfrom_callback_); 213 PostAbortIfNecessary(&recvfrom_callback_);
214 PostAbortIfNecessary(&sendto_callback_); 214 PostAbortIfNecessary(&sendto_callback_);
215
216 read_buffer_ = NULL;
217 bytes_to_read_ = -1;
215 } 218 }
216 219
217 void UDPSocketResourceBase::PostAbortIfNecessary( 220 void UDPSocketResourceBase::PostAbortIfNecessary(
218 scoped_refptr<TrackedCallback>* callback) { 221 scoped_refptr<TrackedCallback>* callback) {
219 if (TrackedCallback::IsPending(*callback)) 222 if (TrackedCallback::IsPending(*callback))
220 (*callback)->PostAbort(); 223 (*callback)->PostAbort();
221 } 224 }
222 225
223 void UDPSocketResourceBase::OnPluginMsgSetOptionReply( 226 void UDPSocketResourceBase::OnPluginMsgSetOptionReply(
224 scoped_refptr<TrackedCallback> callback, 227 scoped_refptr<TrackedCallback> callback,
225 const ResourceMessageReplyParams& params) { 228 const ResourceMessageReplyParams& params) {
226 if (TrackedCallback::IsPending(callback)) 229 if (TrackedCallback::IsPending(callback))
227 callback->Run(ConvertPPError(params.result(), private_api_)); 230 callback->Run(ConvertPPError(params.result(), private_api_));
228 } 231 }
229 232
230 void UDPSocketResourceBase::OnPluginMsgBindReply( 233 void UDPSocketResourceBase::OnPluginMsgBindReply(
231 const ResourceMessageReplyParams& params, 234 const ResourceMessageReplyParams& params,
232 const PP_NetAddress_Private& bound_addr) { 235 const PP_NetAddress_Private& bound_addr) {
233 if (!TrackedCallback::IsPending(bind_callback_)) { 236 // It is possible that |bind_callback_| is pending while |closed_| is true:
234 NOTREACHED(); 237 // CloseImpl() has been called, but a BindReply came earlier than the task to
238 // abort |bind_callback_|. We don't want to update |bound_| or |bound_addr_|
239 // in that case.
240 if (!TrackedCallback::IsPending(bind_callback_) || closed_)
235 return; 241 return;
236 } 242
237 if (params.result() == PP_OK) 243 if (params.result() == PP_OK)
238 bound_ = true; 244 bound_ = true;
239 bound_addr_ = bound_addr; 245 bound_addr_ = bound_addr;
240 bind_callback_->Run(ConvertPPError(params.result(), private_api_)); 246 bind_callback_->Run(ConvertPPError(params.result(), private_api_));
241 } 247 }
242 248
243 void UDPSocketResourceBase::OnPluginMsgRecvFromReply( 249 void UDPSocketResourceBase::OnPluginMsgRecvFromReply(
244 PP_Resource* output_addr, 250 PP_Resource* output_addr,
245 const ResourceMessageReplyParams& params, 251 const ResourceMessageReplyParams& params,
246 const std::string& data, 252 const std::string& data,
247 const PP_NetAddress_Private& addr) { 253 const PP_NetAddress_Private& addr) {
248 if (!TrackedCallback::IsPending(recvfrom_callback_)) { 254 // It is possible that |recvfrom_callback_| is pending while |read_buffer_| is
249 NOTREACHED(); 255 // NULL: CloseImpl() has been called, but a RecvFromReply came earlier than
256 // the task to abort |recvfrom_callback_|. We shouldn't access the buffer in
257 // that case. The user may have released it.
258 if (!TrackedCallback::IsPending(recvfrom_callback_) || !read_buffer_)
250 return; 259 return;
251 } 260
252 int32_t result = params.result(); 261 int32_t result = params.result();
253 if (result == PP_OK && output_addr) { 262 if (result == PP_OK && output_addr) {
254 thunk::EnterResourceCreationNoLock enter(pp_instance()); 263 thunk::EnterResourceCreationNoLock enter(pp_instance());
255 if (enter.succeeded()) { 264 if (enter.succeeded()) {
256 *output_addr = enter.functions()->CreateNetAddressFromNetAddressPrivate( 265 *output_addr = enter.functions()->CreateNetAddressFromNetAddressPrivate(
257 pp_instance(), addr); 266 pp_instance(), addr);
258 } else { 267 } else {
259 result = PP_ERROR_FAILED; 268 result = PP_ERROR_FAILED;
260 } 269 }
261 } 270 }
(...skipping 10 matching lines...) Expand all
272 281
273 if (result == PP_OK) 282 if (result == PP_OK)
274 recvfrom_callback_->Run(static_cast<int32_t>(data.size())); 283 recvfrom_callback_->Run(static_cast<int32_t>(data.size()));
275 else 284 else
276 recvfrom_callback_->Run(ConvertPPError(result, private_api_)); 285 recvfrom_callback_->Run(ConvertPPError(result, private_api_));
277 } 286 }
278 287
279 void UDPSocketResourceBase::OnPluginMsgSendToReply( 288 void UDPSocketResourceBase::OnPluginMsgSendToReply(
280 const ResourceMessageReplyParams& params, 289 const ResourceMessageReplyParams& params,
281 int32_t bytes_written) { 290 int32_t bytes_written) {
282 if (!TrackedCallback::IsPending(sendto_callback_)) { 291 if (!TrackedCallback::IsPending(sendto_callback_))
283 NOTREACHED();
284 return; 292 return;
285 } 293
286 if (params.result() == PP_OK) 294 if (params.result() == PP_OK)
287 sendto_callback_->Run(bytes_written); 295 sendto_callback_->Run(bytes_written);
288 else 296 else
289 sendto_callback_->Run(ConvertPPError(params.result(), private_api_)); 297 sendto_callback_->Run(ConvertPPError(params.result(), private_api_));
290 } 298 }
291 299
292 } // namespace proxy 300 } // namespace proxy
293 } // namespace ppapi 301 } // namespace ppapi
OLDNEW
« no previous file with comments | « no previous file | ppapi/shared_impl/tcp_socket_shared.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698