summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorItalo Guerrieri <guerital@amazon.it>2017-12-28 12:17:55 +0100
committerIgnacio Casal Quinteiro <qignacio@amazon.com>2018-02-01 09:58:55 +0100
commit0366756970e3b38fa63ad9200d09e9a4068b261e (patch)
tree0d263cc1f28f5a497b6cd2630602063eb67028ff
parente7c827d5979ce6da64f8722254a315960bcf08c2 (diff)
downloadlibsoup-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
-rw-r--r--libsoup/soup-websocket-connection.c21
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;