fix a valgrind'd bug with irc_nick_chanflags being given an empty string
authorTero Marttila <terom@fixme.fi>
Fri, 27 Mar 2009 01:01:34 +0200
changeset 82 bc767e01648d
parent 81 d90edc052352
child 83 c8e2dac08207
fix a valgrind'd bug with irc_nick_chanflags being given an empty string
src/irc_chan.c
src/irc_proto.c
src/test.c
--- a/src/irc_chan.c	Fri Mar 27 00:48:12 2009 +0200
+++ b/src/irc_chan.c	Fri Mar 27 01:01:34 2009 +0200
@@ -160,6 +160,10 @@
     // iterate over each name
     // XXX: nickflags
     while ((nickname = strsep(&names, " "))) {
+        // skip empty token at end
+        if (strlen(nickname) == 0)
+            continue;
+
         // parse off the channel flags
         nickname = irc_nick_chanflags(nickname, chanflags);
 
--- a/src/irc_proto.c	Fri Mar 27 00:48:12 2009 +0200
+++ b/src/irc_proto.c	Fri Mar 27 01:01:34 2009 +0200
@@ -96,7 +96,8 @@
     char *cf = chanflags;
 
     // consume the chanflags, using strchr to look for the char in the set of chanflags...
-    while (strchr(IRC_CHANFLAGS, *nick) && (cf < chanflags + IRC_CHANFLAGS_MAX - 1))
+    // XXX: error if nickname is empty...
+    while (*nick && strchr(IRC_CHANFLAGS, *nick) && (cf < chanflags + IRC_CHANFLAGS_MAX - 1))
         *cf++ = *nick++;
 
     // NUL-terminate chanflags
--- a/src/test.c	Fri Mar 27 00:48:12 2009 +0200
+++ b/src/test.c	Fri Mar 27 01:01:34 2009 +0200
@@ -764,6 +764,7 @@
 {
     // RPL_NAMREPLY
     test_sock_push(sock, "353 mynick = %s :mynick userA +userB @userC\r\n", ctx->channel);
+    test_sock_push(sock, "353 mynick = %s :trailingspace \r\n", ctx->channel);
     test_sock_push(sock, "366 mynick %s :End of NAMES\r\n", ctx->channel);
     
     // XXX: this should be an exclusive test, i.e. these should be the only ones...