]> arthur.barton.de Git - ngircd-alex.git/commitdiff
Send_Message: Fix handling of "empty" targets
authorAlexander Barton <alex@barton.de>
Thu, 7 Jan 2016 00:54:11 +0000 (01:54 +0100)
committerAlexander Barton <alex@barton.de>
Thu, 7 Jan 2016 00:54:11 +0000 (01:54 +0100)
Clients can specify multiple targets for the "PRIVMSG", "NOTICE", and
"SQUERY" commands, separated by commas (e. g. "PRIVMSG a,#b,c :text").

Since commit 49ab79d0 ("Limit the number of message targes, and suppress
duplicates"), ngIRCd crashed when the client sent the separator character
only as target(s), e. g. "," or ",,,," etc.!

This patch fixes the bug and adds a test case for this issue.

Thanks to Florian Westphal <fw@strlen.de> for spotting the issue!

src/ngircd/irc.c
src/testsuite/message-test.e

index 15bb90f73ced63e4d7134d5f49b56fb893debd2a..5325b52aedaa7ef3cd470f9ef09a7a9c3bb2a2d7 100644 (file)
@@ -563,7 +563,9 @@ Send_Message(CLIENT * Client, REQUEST * Req, int ForceType, bool SendErrors)
        currentTarget = strtok_r(currentTarget, ",", &strtok_last);
        ngt_UpperStr(Req->command);
 
-       while (true) {
+       /* Please note that "currentTarget" is NULL when the target contains
+        * the separator character only, e. g. "," or ",,,," etc.! */
+       while (currentTarget) {
                /* Make sure that there hasn't been such a target already: */
                targets[target_nr++] = currentTarget;
                for(i = 0; i < target_nr - 1; i++) {
index e46378637b8c2ff44df43a85d13911484809eeec..9eb22e77896fd0bd6241059147c3093861d1ecd0 100644 (file)
@@ -38,6 +38,17 @@ expect {
        "@* PRIVMSG nick :test"
 }
 
+send "privmsg ,,,, :dummy\r"
+send "privmsg ,,,nick,,&server,,, :test\r"
+expect {
+       timeout { exit 1 }
+       "@* PRIVMSG nick :test"
+}
+expect {
+       timeout { exit 1 }
+       "404"
+}
+
 send "privmsg Nick,#testChannel,nick :test\r"
 expect {
        timeout { exit 1 }