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

Unified Diff: net/server/web_socket.cc

Issue 2640363004: HttpServer WebSocket: don't crash on data before server handshake (Closed)
Patch Set: Apply review feedback. Created 3 years, 11 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 | « net/server/http_server_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/server/web_socket.cc
diff --git a/net/server/web_socket.cc b/net/server/web_socket.cc
index 79ffcecb7ada589c1c3171c27caedea4226931d4..bd3d9e494ab73d0d970a93f7091e9756a0ba7dbe 100644
--- a/net/server/web_socket.cc
+++ b/net/server/web_socket.cc
@@ -98,6 +98,17 @@ WebSocket::ParseResult WebSocket::Read(std::string* message) {
if (closed_)
return FRAME_CLOSE;
+ if (!encoder_) {
+ // RFC6455, section 4.1 says "Once the client's opening handshake has been
+ // sent, the client MUST wait for a response from the server before sending
+ // any further data". If |encoder_| is null here, ::Accept either has not
+ // been called at all, or has rejected a request rather than producing
+ // a server handshake. Either way, the client clearly couldn't have gotten
+ // a proper server handshake, so error out, especially since this method
+ // can't proceed without an |encoder_|.
+ return FRAME_ERROR;
+ }
+
HttpConnection::ReadIOBuffer* read_buf = connection_->read_buf();
base::StringPiece frame(read_buf->StartOfBuffer(), read_buf->GetSize());
int bytes_consumed = 0;
« no previous file with comments | « net/server/http_server_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698