Opened 11 years ago

Closed 11 years ago

#6343 closed defect (fixed)

OIMs broken in msnp15 because of the wrap at 76 chars.

Reported by: Dimmuxx Owned by: khc
Milestone: 2.5.0 Component: MSN
Version: 2.4.3 Keywords: msnp15 oim crash


Adium crashes when you send an OIM with libpurple aa1091727852b14118b50e7b20134127c4bf09d3 because of the wrapping at 76 characters.

This is because g_string_printf(oim_body, MSN_OIM_MSG_TEMPLATE, oim->run_id, oim->send_seq); is before the while loop and also len = ((len / 3) + 1) * 4 - 76; probably doesn't work as intended.

I think this should work though:

len_mod = (len % 3) ? 1 : 0;
len = ((len / 3) + len_mod) * 4 - 76;

If I fix these bugs I get an error instead when trying to send an OIM.

23:41:11: (Libpurple: msn) Encoding OIM Message...
23:41:11: (Libpurple: msn) Encoded base64 body:{dGVzdA==}
23:41:11: (Libpurple: xmlnode) XML parser error: Domain 1, code 9, level 3: Input is not proper UTF-8, indicate encoding !
Bytes: 0xF4 0x2D 0xD7 0x17

23:41:11: (Libpurple: xmlnode) XML parser error: Domain 1, code 1, level 3: internal error
23:41:11: (Libpurple: xmlnode) XML parser error: Domain 1, code 5, level 3: Extra content at the end of the document

I thought that maybe this was because of oim_body was missing at the end of the g_string_printf. So I added it g_string_printf(oim_body, MSN_OIM_MSG_TEMPLATE, oim->run_id, oim->send_seq, oim_body);

But adding this didn't solve anything so I'm thinking that it might be because \n are inserted in a base64 encoded string. So maybe the string should be wrapped before the base64 encoding at 50 characters or something to ensure that it doesn't get over 76 characters before a newline.

Change History (4)

comment:1 Changed 11 years ago by khc

the crash is probably because MSN_OIM_MSG_TEMPLATE defined 3 params but only 2 are passed. can you try this:

--- libpurple/protocols/msn/oim.c       0d64864aa018bd11de963bbbc973f0c856048dac
+++ libpurple/protocols/msn/oim.c       2052f01081c4575e8d311ffdb22eff4a2995f424
@@ -274,22 +274,27 @@ msn_oim_msg_to_str(MsnOim *oim, const ch
        char *oim_base64;
        char *c;
        int len;
+       size_t base64_len;
        purple_debug_info("msn", "Encoding OIM Message...\n");
        len = strlen(body);
        c = oim_base64 = purple_base64_encode((const guchar *)body, len);
+       base64_len = strlen(oim_base64);
        purple_debug_info("msn", "Encoded base64 body:{%s}\n", oim_base64);
        oim_body = g_string_new(NULL);
        g_string_printf(oim_body, MSN_OIM_MSG_TEMPLATE,
-                       oim->run_id, oim->send_seq);
+               oim->run_id, oim->send_seq, "");
-       len = ((len / 3) + 1) * 4 - 76;
-       while ((c - oim_base64) < len) {
-               g_string_append_len(oim_body, c, 76);
+#define OIM_LINE_LEN 76
+       while (base64_len > OIM_LINE_LEN) {
+               g_string_append_len(oim_body, c, OIM_LINE_LEN);
                g_string_append_c(oim_body, '\n');
-               c += 76;
+               c += OIM_LINE_LEN;
+               base64_len -= OIM_LINE_LEN;
+#undef OIM_LINE_LEN
        g_string_append(oim_body, c);

comment:2 Changed 11 years ago by Dimmuxx

That seems to fix it. Thanks! :)

comment:3 Changed 11 years ago by QuLogic

Oops, sorry, I forgot to commit oim.h. I took that len line from purple_base64_encode. I probably should have checked if it was an exact calculation first.

comment:4 Changed 11 years ago by QuLogic

  • Milestone set to 2.5.0
  • Resolution set to fixed
  • Status changed from new to closed

Trac seems broken... In d13ab585f3e5a58e32ca8136c3b48ea767918734:

fixes a crash and probably more correct and definitely easier to understand
splitting. Fixes #6343. Thanks Dimmuxx for testing since I was too lazy to
do it myself

In c7cd6a4c341ff512ad7adad3fe410b621991aed9:

Commit the changes to oim.h that I forgot last time. Fixes #6343,
though khc's commit did too, if only trac noticed.
Note: See TracTickets for help on using tickets.
All information, including names and email addresses, entered onto this website or sent to mailing lists affiliated with this website will be public. Do not post confidential information, especially passwords!