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

Unified Diff: base/sync_socket_win.cc

Issue 570713003: Avoid unsafe usage of CancelIo() within Windows SyncSocket. (Closed) Base URL: http://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix clients. Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | content/browser/renderer_host/media/audio_sync_reader.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/sync_socket_win.cc
diff --git a/base/sync_socket_win.cc b/base/sync_socket_win.cc
index 3c40ebaa6f1a9a8a296909153aeabdabb384f569..6b2575c2f691f99c72a95c9cd478aba0ccb6e349 100644
--- a/base/sync_socket_win.cc
+++ b/base/sync_socket_win.cc
@@ -154,21 +154,27 @@ size_t CancelableFileOperation(Function operation,
timeout_in_ms == INFINITE
? timeout_in_ms
: (finish_time - current_time).InMilliseconds());
- if (wait_result == (WAIT_OBJECT_0 + 0)) {
- GetOverlappedResult(file, &ol, &len, TRUE);
- } else if (wait_result == (WAIT_OBJECT_0 + 1)) {
- DVLOG(1) << "Shutdown was signaled. Closing socket.";
+ if (wait_result != WAIT_OBJECT_0 + 0) {
+ // CancelIo() doesn't synchronously cancel outstanding IO, only marks
+ // outstanding IO for cancellation. We must call GetOverlappedResult()
+ // below to ensure in flight writes complete before returning.
CancelIo(file);
+ }
+
+ // We set the |bWait| parameter to TRUE for GetOverlappedResult() to
+ // ensure writes are complete before returning.
+ if (!GetOverlappedResult(file, &ol, &len, TRUE))
+ len = 0;
+
+ if (wait_result == WAIT_OBJECT_0 + 1) {
+ DVLOG(1) << "Shutdown was signaled. Closing socket.";
socket->Close();
- count = 0;
- break;
- } else {
- // Timeout happened.
- DCHECK_EQ(WAIT_TIMEOUT, wait_result);
- if (!CancelIo(file))
- DLOG(WARNING) << "CancelIo() failed";
- break;
+ return count;
}
+
+ // Timeouts will be handled by the while() condition below since
+ // GetOverlappedResult() may complete successfully after CancelIo().
+ DCHECK(wait_result == WAIT_OBJECT_0 + 0 || wait_result == WAIT_TIMEOUT);
} else {
break;
}
« no previous file with comments | « no previous file | content/browser/renderer_host/media/audio_sync_reader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698