[libsoup] Fix invalid close code
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup] Fix invalid close code
- Date: Thu, 1 Feb 2018 09:00:44 +0000 (UTC)
commit 0366756970e3b38fa63ad9200d09e9a4068b261e
Author: Italo Guerrieri <guerital amazon it>
Date: Thu Dec 28 12:17:55 2017 +0100
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
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 b93fab2..f11edfe 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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]