summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorItalo Guerrieri <guerital@amazon.it>2017-12-28 16:14:26 +0100
committerIgnacio Casal Quinteiro <qignacio@amazon.com>2018-02-01 09:58:55 +0100
commitf8adddd69bad32d347351075c8a2f09d0ec01004 (patch)
tree8a6f8dac0df7d1cebe19ea20a370525b6bd4e145
parent0366756970e3b38fa63ad9200d09e9a4068b261e (diff)
downloadlibsoup-f8adddd69bad32d347351075c8a2f09d0ec01004.tar.gz
Fix UTF8 message
Instead of checking if a string is valid frame by frame, it check if it is a valid utf8 only when the message is totaly reassembled. Fix Autobahn test cases: 6.2.3, 6.2.4 and 6.4.2. https://bugzilla.gnome.org/show_bug.cgi?id=792113
-rw-r--r--libsoup/soup-websocket-connection.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/libsoup/soup-websocket-connection.c b/libsoup/soup-websocket-connection.c
index f11edfed..0258a22c 100644
--- a/libsoup/soup-websocket-connection.c
+++ b/libsoup/soup-websocket-connection.c
@@ -761,18 +761,6 @@ process_contents (SoupWebsocketConnection *self,
switch (pv->message_opcode) {
case 0x01:
- if (!g_utf8_validate ((char *)payload, payload_len, NULL)) {
- g_debug ("received invalid non-UTF8 text data");
-
- /* Discard the entire message */
- g_byte_array_unref (pv->message_data);
- pv->message_data = NULL;
- pv->message_opcode = 0;
-
- bad_data_error_and_close (self);
- return;
- }
- /* fall through */
case 0x02:
g_byte_array_append (pv->message_data, payload, payload_len);
break;
@@ -784,6 +772,22 @@ process_contents (SoupWebsocketConnection *self,
/* Actually deliver the message? */
if (fin) {
+ if (pv->message_opcode == 0x01 &&
+ !g_utf8_validate((char *)pv->message_data->data,
+ pv->message_data->len,
+ NULL)) {
+
+ g_debug ("received invalid non-UTF8 text data");
+
+ /* Discard the entire message */
+ g_byte_array_unref (pv->message_data);
+ pv->message_data = NULL;
+ pv->message_opcode = 0;
+
+ bad_data_error_and_close (self);
+ return;
+ }
+
/* Always null terminate, as a convenience */
g_byte_array_append (pv->message_data, (guchar *)"\0", 1);