From e92c889580bc22165e62ee42310bec4ce09cde3a Mon Sep 17 00:00:00 2001 From: Florian Westphal Date: Sat, 16 Feb 2008 11:26:11 +0000 Subject: [PATCH] From: Dana Dahlstrom Under some circumstances ngIRCd currently issues a channel MODE message with a trailing space after the last parameter, which isn't permitted by the grammar in RFC 2812 section 2.3.1: http://tools.ietf.org/html/rfc2812#section-2.3.1 The following patch modifies mode-test.e to expose this, and modifies irc-mode.c to correct it. [from HEAD] --- ChangeLog | 5 ++++- src/ngircd/irc-mode.c | 14 +++++--------- src/testsuite/mode-test.e | 6 +++--- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index d3ece683..28faac75 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,7 +8,10 @@ terms of the GNU General Public License. -- ChangeLog -- +ngIRCd 0.11.1 + - Under some circumstances ngIRCd issued + channel MODE message with a trailing space. (Dana Dahlstrom) [from HEAD] ngIRCd 0.11.0 (2008-01-15) @@ -734,4 +737,4 @@ ngIRCd 0.0.1, 31.12.2001 -- -$Id: ChangeLog,v 1.332.2.6 2008/01/15 20:45:52 alex Exp $ +$Id: ChangeLog,v 1.332.2.7 2008/02/16 11:26:11 fw Exp $ diff --git a/src/ngircd/irc-mode.c b/src/ngircd/irc-mode.c index c26984d8..af024624 100644 --- a/src/ngircd/irc-mode.c +++ b/src/ngircd/irc-mode.c @@ -14,7 +14,7 @@ #include "portab.h" -static char UNUSED id[] = "$Id: irc-mode.c,v 1.50 2007/10/14 12:08:57 alex Exp $"; +static char UNUSED id[] = "$Id: irc-mode.c,v 1.50.2.1 2008/02/16 11:26:12 fw Exp $"; #include "imp.h" #include @@ -317,7 +317,7 @@ Channel_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel ) /* Prepare reply string */ if( set ) strcpy( the_modes, "+" ); else strcpy( the_modes, "-" ); - strcpy( the_args, " " ); + the_args[0] = '\0'; x[1] = '\0'; ok = CONNECTED; @@ -528,8 +528,8 @@ Channel_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel ) /* Channel-User-Mode */ if( Channel_UserModeAdd( Channel, client, x[0] )) { - strlcat( the_args, Client_ID( client ), sizeof( the_args )); strlcat( the_args, " ", sizeof( the_args )); + strlcat( the_args, Client_ID( client ), sizeof( the_args )); strlcat( the_modes, x, sizeof( the_modes )); Log( LOG_DEBUG, "User \"%s\": Mode change on %s, now \"%s\"", Client_Mask( client ), Channel_Name( Channel ), Channel_UserModes( Channel, client )); } @@ -552,8 +552,8 @@ Channel_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel ) /* Channel-User-Mode */ if( Channel_UserModeDel( Channel, client, x[0] )) { - strlcat( the_args, Client_ID( client ), sizeof( the_args )); strlcat( the_args, " ", sizeof( the_args )); + strlcat( the_args, Client_ID( client ), sizeof( the_args )); strlcat( the_modes, x, sizeof( the_modes )); Log( LOG_DEBUG, "User \"%s\": Mode change on %s, now \"%s\"", Client_Mask( client ), Channel_Name( Channel ), Channel_UserModes( Channel, client )); } @@ -572,8 +572,7 @@ Channel_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel ) /* Are there additional arguments to add? */ if( argadd[0] ) { - len = strlen( the_args ) - 1; - if( the_args[len] != ' ' ) strlcat( the_args, " ", sizeof( the_args )); + strlcat( the_args, " ", sizeof( the_args )); strlcat( the_args, argadd, sizeof( the_args )); } } @@ -586,9 +585,6 @@ chan_exit: len = strlen( the_modes ) - 1; if(( the_modes[len] == '+' ) || ( the_modes[len] == '-' )) the_modes[len] = '\0'; - /* Clean up argument string if there are none */ - if( ! the_args[1] ) the_args[0] = '\0'; - if( Client_Type( Client ) == CLIENT_SERVER ) { /* Forward mode changes to channel users and other servers */ diff --git a/src/testsuite/mode-test.e b/src/testsuite/mode-test.e index 05dffc5c..8aa4925a 100644 --- a/src/testsuite/mode-test.e +++ b/src/testsuite/mode-test.e @@ -1,4 +1,4 @@ -# $Id: mode-test.e,v 1.6 2004/03/10 20:40:06 alex Exp $ +# $Id: mode-test.e,v 1.6.8.1 2008/02/16 11:26:13 fw Exp $ spawn telnet localhost 6789 expect { @@ -72,7 +72,7 @@ expect { send "mode #channel +v nick\r" expect { timeout { exit 1 } - "@* MODE #channel +v nick" + "@* MODE #channel +v nick\r" } send "mode #channel +I nick1\r" @@ -96,7 +96,7 @@ expect { send "mode #channel -vo nick nick\r" expect { timeout { exit 1 } - "@* MODE #channel -vo nick nick" + "@* MODE #channel -vo nick nick\r" } send "quit\r"