[Telepathy-commits] [telepathy-idle/master] Fix parsing error on leading whitespace (bug #17390)

Jonathon Jongsma jjongsma at gnome.org
Wed Dec 31 13:52:47 PST 2008


The basic problem is as follows:
There is an incoming message that looks like the following:
":jonner!n=jonner at jalfrezi.collabora.co.uk PRIVMSG #channelname : foo bar"

When this message gets tokenized, we get the following tokens:
 - :jonner!n=jonner at jalfrezi.collabora.co.uk
 - PRIVMSG
 - #channelname
 - :
 - foo
 - bar

When we get to parsing the chat message portion, our current token is simply
":".  There is a check in the code that was meant to prevent zero-length strings
from being added to the parsed arguments, but that check assumes that we'll only
be adding the current token to the parsed args.  In reality, we want to consume
the entire remaining string (which may contain multiple tokens) and add it to
args.  So instead of checking that the the character immediately after the ':'
is non-NULL in the strdup-ed token, we should really check that the character
immediately after the ':' is non-NULL in the original message string.

Bug was introduced in commit 02cf59fb7b7efebbec39422460ec13ae1e3f5c89
---
 src/idle-parser.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/src/idle-parser.c b/src/idle-parser.c
index e8fddca..5b5214b 100644
--- a/src/idle-parser.c
+++ b/src/idle-parser.c
@@ -350,7 +350,13 @@ static void _parse_and_forward_one(IdleParser *parser, gchar **tokens, IdleParse
 				iter += 2;
 			}
 		} else if ((*format == ':') || (*format == '.')) {
-			if ((iter[0][0] != ':') || (iter[0][1] == '\0')) {
+			/* Because of the way things are tokenized, if there is a space
+			 * immediately after the the ':', the current token will only be
+			 * ":", so we check that iter[1][1] is non-NULL rather than checking
+			 * iter[0][1] (since iter[0] is a NULL-terminated token string
+			 * whereas iter[1] is a pointer into the full message string
+			 */
+			if ((iter[0][0] != ':') || (iter[1][1] == '\0')) {
 				success = FALSE;
 				break;
 			}
-- 
1.5.6.5



More information about the Telepathy-commits mailing list