repo: ngircd
action: commit
revision: 
path_from: 
revision_from: 07cb8ed9ae14307b7b9335faa957baa340632e57:
path_to: 
revision_to: 
git.thebackupbox.net
ngircd
git clone git://git.thebackupbox.net/ngircd
commit 07cb8ed9ae14307b7b9335faa957baa340632e57
Author: Alexander Barton 
Date:   Thu Jun 11 16:45:30 2020 +0200

    Don't send invalid CHANINFO commands when no key is set

    It can happen that a channel is +k, but no key is set: for example by
    misconfiguring a pre-defined channel. In this case, ngIRCd sent an
    invalud CHANINFO command ("CHANINFO #test +Pk  0 :'", note the unset
    key represented by the two spaces) to its peers.

    Fix this and enhance the CHANINFO documentation.

diff --git a/doc/Commands.txt b/doc/Commands.txt
index 0accc5c29d81c02369f53c244b4686cb13b1f0c9..
index ..0ca8703cf4c9831a6cb4f292de80ce9935c028f0 100644
--- a/doc/Commands.txt
+++ b/doc/Commands.txt
@@ -874,6 +874,10 @@ Server Protocol Commands
 	CHANINFO is used by servers to inform each other about a channel:
 	its modes, channel key, user limits and its topic.
 	.
+	Note: even when  don't include "k" (key) or "l" (limit), both
+	parameters must be given when used; use "*" for "no key" and 0 for
+	"no limit" for the unused parameter in this case.
+	.
 	The CHANINFO command is allowed on server-links only.

 	References:
diff --git a/src/ngircd/numeric.c b/src/ngircd/numeric.c
index 380b9078b210deb9a6853cf2c966357efec75481..
index ..8edb76e2169150951fbcdf9cb5611102b346d16f 100644
--- a/src/ngircd/numeric.c
+++ b/src/ngircd/numeric.c
@@ -214,7 +214,7 @@ Synchronize_Lists(CLIENT * Client)
 static bool
 Send_CHANINFO(CLIENT * Client, CHANNEL * Chan)
 {
-	char *modes, *topic;
+	char *modes, *topic, *key;
 	bool has_k, has_l;

 #ifdef DEBUG
@@ -243,9 +243,10 @@ Send_CHANINFO(CLIENT * Client, CHANNEL * Chan)
 					  Channel_Name(Chan), modes, topic);
 	}
 	/* "CHANINFO  +   :" */
+	key = Channel_Key(Chan);
 	return IRC_WriteStrClient(Client, "CHANINFO %s +%s %s %lu :%s",
 				  Channel_Name(Chan), modes,
-				  has_k ? Channel_Key(Chan) : "*",
+				  has_k ? (key && *key ? key : "*") : "*",
 				  has_l ? Channel_MaxUsers(Chan) : 0, topic);
 } /* Send_CHANINFO */

-----END OF PAGE-----