Skip to content

Commit c49e7c7

Browse files
committed
Add a little bit of memory safety on the websocket connection
1 parent f19e5d6 commit c49e7c7

File tree

3 files changed

+103
-1
lines changed

3 files changed

+103
-1
lines changed

.vscode/settings.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"cmake.configureOnOpen": false,
3+
"C_Cpp.default.compilerPath": "C:\\cygwin64\\home\\eion\\win32-dev\\mingw-4.7.2\\bin\\gcc.exe",
4+
"cSpell.words": [
5+
"blist",
6+
"cbflags",
7+
"chatconv",
8+
"chatname",
9+
"gboolean",
10+
"gchar",
11+
"gdouble",
12+
"gint",
13+
"gpointer",
14+
"gssize",
15+
"guchar",
16+
"guint",
17+
"guintptr",
18+
"gulong",
19+
"HALFOP",
20+
"postdata",
21+
"prpl",
22+
"qrauth",
23+
"QRCODE",
24+
"roomlist",
25+
"ROOMTYPE",
26+
"strconcat",
27+
"strfreev",
28+
"strjoinv",
29+
"strsplit",
30+
"unreact",
31+
"wpurple"
32+
],
33+
"C_Cpp.codeAnalysis.clangTidy.enabled": true,
34+
"C_Cpp.default.cStandard": "gnu99",
35+
"C_Cpp.default.intelliSenseMode": "windows-gcc-x86",
36+
"C_Cpp.intelliSenseEngine": "default",
37+
"C_Cpp.codeAnalysis.clangTidy.args": [
38+
"-external:W0"
39+
]
40+
}

libdiscord.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6592,6 +6592,7 @@ discord_socket_got_data(gpointer userdata, PurpleSslConnection *conn, PurpleInpu
65926592

65936593
length_code = 0;
65946594
purple_ssl_read(conn, &length_code, 1);
6595+
length_code = length_code & ~0x80;
65956596

65966597
if (length_code <= 125) {
65976598
ya->frame_len = length_code;
@@ -6601,6 +6602,18 @@ discord_socket_got_data(gpointer userdata, PurpleSslConnection *conn, PurpleInpu
66016602
} else if (length_code == 127) {
66026603
purple_ssl_read(conn, &ya->frame_len, 8);
66036604
ya->frame_len = GUINT64_FROM_BE(ya->frame_len);
6605+
if ((ya->frame_len & (1ULL << 63)) != 0) {
6606+
purple_debug_error("discord", "Frame length has MSB set, possible protocol error\n");
6607+
purple_connection_error(ya->pc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("Websocket protocol error"));
6608+
return;
6609+
}
6610+
}
6611+
6612+
// Check for unreasonable frame_len value
6613+
if (ya->frame_len > (16 * 1024 * 1024)) { // 16MB max frame size
6614+
purple_debug_error("discord", "Unreasonable frame length: %" G_GUINT64_FORMAT "\n", ya->frame_len);
6615+
purple_connection_error(ya->pc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("Websocket protocol error: unreasonable frame length"));
6616+
return;
66046617
}
66056618

66066619
ya->frame = g_new0(gchar, ya->frame_len + 1);

po/purple-discord.pot

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2025-03-13 21:40+0100\n"
11+
"POT-Creation-Date: 2025-06-29 22:12+0100\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -27,6 +27,46 @@ msgstr ""
2727
msgid "Connection error: %s."
2828
msgstr ""
2929

30+
#, c-format
31+
msgid "%d second%s ago"
32+
msgstr ""
33+
34+
#, c-format
35+
msgid "%d minute%s ago"
36+
msgstr ""
37+
38+
#, c-format
39+
msgid "%d hour%s ago"
40+
msgstr ""
41+
42+
#, c-format
43+
msgid "%d day%s ago"
44+
msgstr ""
45+
46+
#, c-format
47+
msgid "%d year%s ago"
48+
msgstr ""
49+
50+
#, c-format
51+
msgid "in %d second%s"
52+
msgstr ""
53+
54+
#, c-format
55+
msgid "in %d minute%s"
56+
msgstr ""
57+
58+
#, c-format
59+
msgid "in %d hour%s"
60+
msgstr ""
61+
62+
#, c-format
63+
msgid "in %d day%s"
64+
msgstr ""
65+
66+
#, c-format
67+
msgid "in %d year%s"
68+
msgstr ""
69+
3070
msgid "your"
3171
msgstr ""
3272

@@ -173,6 +213,12 @@ msgstr ""
173213
msgid "Reauthentication required"
174214
msgstr ""
175215

216+
msgid "Websocket protocol error"
217+
msgstr ""
218+
219+
msgid "Websocket protocol error: unreasonable frame length"
220+
msgstr ""
221+
176222
msgid "Lost connection to server"
177223
msgstr ""
178224

@@ -301,6 +347,9 @@ msgstr ""
301347
msgid "Email address..."
302348
msgstr ""
303349

350+
msgid "Show reaction emojis"
351+
msgstr ""
352+
304353
msgid "Use status message as in-game info"
305354
msgstr ""
306355

0 commit comments

Comments
 (0)