Skip to content

Commit

Permalink
Send_Message: Fix handling of "empty" targets
Browse files Browse the repository at this point in the history
Clients can specify multiple targets for the "PRIVMSG", "NOTICE", and
"SQUERY" commands, separated by commas (e. g. "PRIVMSG a,#b,c :text").

Since commit 49ab79d ("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!
  • Loading branch information
alexbarton committed Jan 7, 2016
1 parent 055d6e8 commit 7dba1a0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ngircd/irc.c
Expand Up @@ -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++) {
Expand Down
11 changes: 11 additions & 0 deletions src/testsuite/message-test.e
Expand Up @@ -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 }
Expand Down

0 comments on commit 7dba1a0

Please sign in to comment.