[libsoup] Fix UTF8 message
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup] Fix UTF8 message
- Date: Thu, 1 Feb 2018 09:00:49 +0000 (UTC)
commit f8adddd69bad32d347351075c8a2f09d0ec01004
Author: Italo Guerrieri <guerital amazon it>
Date: Thu Dec 28 16:14:26 2017 +0100
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
libsoup/soup-websocket-connection.c | 28 ++++++++++++++++------------
1 files changed, 16 insertions(+), 12 deletions(-)
---
diff --git a/libsoup/soup-websocket-connection.c b/libsoup/soup-websocket-connection.c
index f11edfe..0258a22 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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]