ref: 4251d493d8eb4371fb6f59a0f511cb80e4a24588
parent: 4d1358e76bdcf18d76d4c74af87c93ad5a418007
author: glenda <glenda@cirno>
date: Sat Aug 31 15:11:46 EDT 2024
improve handling of trailing parameters this is still technically incorrect, however it's the best we can do without an actual irc parser. also fixes a segfault when no password specified while password protection is enabled.
--- a/ircd.c
+++ b/ircd.c
@@ -1042,7 +1042,7 @@
if(c->passok)
return 0;
else{
- if(strcmp(p, password) != 0){
+ if(p == nil || *p == ':' && !*++p || strcmp(p, password) != 0){
r.code = ERR_PASSWDMISMATCH;
reply(c, &r);
return 0;
@@ -1093,7 +1093,7 @@
}
if(strcmp(cmd, "NICK") == 0){
tmp = strtok(0, " \r"); /* nick */
- if(tmp == nil){
+ if(tmp == nil || *tmp == ':' && !*++tmp){
r.code = ERR_NONICKNAMEGIVEN;
reply(c, &r);
return 1;
@@ -1126,17 +1126,16 @@
return 1;
}
tmp2 = strtok(0, "\r"); /* msg */
- if(tmp2 == nil){
+ if(tmp2 == nil || *tmp2 == ':' && !*++tmp2){
r.code = ERR_NOTEXTTOSEND;
reply(c, &r);
return 1;
}
- tmp2++;
return privmsg(c, tmp, tmp2);
}
/* JOIN #c or JOIN #c1,#c2 hence the check for "," */
if(strcmp(cmd, "JOIN") == 0){
- tmp = strtok(0, " \r"); /* channels */
+ tmp = strtok(0, " :\r"); /* channels */
if(tmp == nil)
return 0;
tmp2 = strtok(tmp, ",");
@@ -1153,7 +1152,8 @@
tmp2 = strtok(0, "\r"); /* reason */
if(tmp2 == nil)
return 0;
- tmp2++;
+ if(*tmp2 == ':')
+ tmp2++;
return part(c, tmp, tmp2);
}
if(strcmp(cmd, "TOPIC") == 0){
@@ -1161,7 +1161,7 @@
if(tmp == nil)
return 0;
tmp2 = strtok(0, "\r"); /* topic */
- if(tmp2 != nil)
+ if(tmp2 != nil && *tmp2 == ':')
tmp2++;
return topic(c, tmp, tmp2);
}
@@ -1169,20 +1169,21 @@
tmp = strtok(0, "\r"); /* reason */
if(tmp == nil)
return 0;
- tmp++;
+ if(*tmp == ':')
+ tmp++;
quit(c, tmp);
return 0;
}
if(strcmp(cmd, "LIST") == 0){
- tmp = strtok(0, " \r"); /* channels */
+ tmp = strtok(0, " :\r"); /* channels */
return list(c, tmp);
}
if(strcmp(cmd, "WHOIS") == 0){
- tmp = strtok(0, " \r"); /* nicks */
+ tmp = strtok(0, " :\r"); /* nicks */
return whois(c, tmp);
}
if(strcmp(cmd, "AWAY") == 0){
- tmp = strtok(0, " \r"); /* msg */
+ tmp = strtok(0, " :\r"); /* msg */
return away(c, tmp);
}
if(strcmp(cmd, "MOTD") == 0)