diff options
author | Italo Guerrieri <guerital@amazon.it> | 2017-12-28 12:17:55 +0100 |
---|---|---|
committer | Ignacio Casal Quinteiro <qignacio@amazon.com> | 2018-02-01 09:58:55 +0100 |
commit | 0366756970e3b38fa63ad9200d09e9a4068b261e (patch) | |
tree | 0d263cc1f28f5a497b6cd2630602063eb67028ff /libsoup | |
parent | e7c827d5979ce6da64f8722254a315960bcf08c2 (diff) | |
download | libsoup-0366756970e3b38fa63ad9200d09e9a4068b261e.tar.gz |
Fix invalid close code
Close the connection with a protocol error, if a close control
uses a code reserved for future implementations of the WebSocket
protocol.
Fix Autobahn test cases 7.9.*.
https://bugzilla.gnome.org/show_bug.cgi?id=792113
Diffstat (limited to 'libsoup')
-rw-r--r-- | libsoup/soup-websocket-connection.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/libsoup/soup-websocket-connection.c b/libsoup/soup-websocket-connection.c index b93fab2a..f11edfed 100644 --- a/libsoup/soup-websocket-connection.c +++ b/libsoup/soup-websocket-connection.c @@ -578,7 +578,11 @@ close_connection (SoupWebsocketConnection *self, } break; default: - g_debug ("Wrong closing code %d received", code); + if (code < 3000) { + g_debug ("Wrong closing code %d received", code); + protocol_error_and_close (self); + return; + } } g_signal_emit (self, signals[CLOSING], 0); @@ -605,10 +609,21 @@ receive_close (SoupWebsocketConnection *self, pv->peer_close_data = NULL; pv->close_received = TRUE; - /* Store the code/data payload */ - if (len >= 2) { + switch (len) { + case 0: + /* Send a clean close when having an empty payload */ + close_connection (self, 1000, NULL); + return; + case 1: + /* Send a protocol error since the close code is incomplete */ + protocol_error_and_close (self); + return; + default: + /* Store the code/data payload */ pv->peer_close_code = (guint16)data[0] << 8 | data[1]; + break; } + if (len > 2) { data += 2; len -= 2; |