From 68ba581a92579aee59b16e5faf88eeb3676f35af Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Fri, 9 Sep 2011 09:46:34 +0100 Subject: [PATCH] Connection: replace \r and \n with spaces If a message gets as far as _send_with_priority and contains \r or \n, it's almost certainly not what the user anticipated. For instance, before this fix, calling RemoveMembers([self_handle], "bye\r\nJOIN #telepathy") would cause the user to leave the channel with the message "bye", and then accidentally join #telepathy. Rather than trying to strip out \r and \n everywhere, this patch just replaces them with spaces just before sending. https://bugs.freedesktop.org/show_bug.cgi?id=34840 --- src/idle-connection.c | 5 +++-- tests/twisted/channels/requests-muc.py | 9 +++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/idle-connection.c b/src/idle-connection.c index 4bd7b0e..f9f196f 100644 --- a/src/idle-connection.c +++ b/src/idle-connection.c @@ -884,11 +884,12 @@ static void _send_with_priority(IdleConnection *conn, const gchar *msg, guint pr g_assert(msg != NULL); /* Clip the message */ - g_strlcpy(cmd, msg, IRC_MSG_MAXLEN + 1); - /* Append */ + /* Strip out any / which have crept in */ + g_strdelimit (cmd, "\r\n", ' '); + /* Append */ len = strlen(cmd); cmd[len++] = '\r'; cmd[len++] = '\n'; diff --git a/tests/twisted/channels/requests-muc.py b/tests/twisted/channels/requests-muc.py index 1931214..58704b6 100644 --- a/tests/twisted/channels/requests-muc.py +++ b/tests/twisted/channels/requests-muc.py @@ -92,7 +92,7 @@ def test(q, bus, conn, stream): assert chans[0] == (path, props) chan = make_channel_proxy(conn, path, 'Channel') - chan.RemoveMembers([self_handle], "bye bye cruel world", + chan.RemoveMembers([self_handle], "bye bye cruel\r\nworld", dbus_interface=cs.CHANNEL_IFACE_GROUP) part_event = q.expect('stream-PART') @@ -100,7 +100,12 @@ def test(q, bus, conn, stream): # This is a regression test for # , where part messages # were not correctly colon-quoted. - assertEquals("bye bye cruel world", part_event.data[1]) + # + # It is also a regression test for + # , where newlines + # weren't stripped from part messages. We check that both \r and \n are + # replaced by harmless spaces. + assertEquals("bye bye cruel world", part_event.data[1]) stream.sendPart('#idletest', stream.nick) -- 1.7.5.4