Commit f8adddd6 authored by Italo Guerrieri's avatar Italo Guerrieri Committed by Ignacio Casal Quinteiro
Browse files

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
parent 03667569
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment