summaryrefslogtreecommitdiff
path: root/message.c
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2021-01-19 00:12:11 +0000
committerLuke Bratch <luke@bratch.co.uk>2021-01-19 00:12:11 +0000
commit4b282dd670c7263232d19412f9735d670a1b1b76 (patch)
treead6ab244be87e432940731c60ffa0bf3babf96ff /message.c
parenta16d9bdecb572bb266a84ec90767d613ce8ce255 (diff)
Fix various issues where strncmp was only comparing a substring.
This fixes issues such as when JOINing a channel whose name is a substring of another channel, things like PARTing don't work properly.
Diffstat (limited to 'message.c')
-rw-r--r--message.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/message.c b/message.c
index 6c8f5fc..5f0c2fe 100644
--- a/message.c
+++ b/message.c
@@ -190,7 +190,7 @@ int processservermessage(SSL *server_ssl, char *str, struct client *clients, int
char *prefixcopy = strdup(tokens[0]);
// Just get the nick for comparison
extractnickfromprefix(prefixcopy, 1);
- if (strncmp(prefixcopy, ircdstate->ircnick, strlen(tokens[0])) == 0) {
+ if ((strlen(prefixcopy) == strlen(ircdstate->ircnick)) && (strncmp(prefixcopy, ircdstate->ircnick, strlen(tokens[0])) == 0)) {
debugprint(DEBUG_FULL, "Server JOIN: nick is ours ('%s' vs '%s').\n", prefixcopy, ircdstate->ircnick);
// TODO - Saner way to initialise this since we don't have the variables yet?
// TODO - Defaulting to type '=' which is "public" since I don't know what else to guess.
@@ -231,7 +231,7 @@ int processservermessage(SSL *server_ssl, char *str, struct client *clients, int
char *prefixcopy = strdup(tokens[0]);
// Just get the nick for comparison
extractnickfromprefix(prefixcopy, 1);
- if (strncmp(prefixcopy, ircdstate->ircnick, strlen(tokens[0])) == 0) {
+ if ((strlen(prefixcopy) == strlen(ircdstate->ircnick)) && (strncmp(prefixcopy, ircdstate->ircnick, strlen(tokens[0])) == 0)) {
debugprint(DEBUG_FULL, "Server PART: nick is ours ('%s' vs '%s').\n", prefixcopy, ircdstate->ircnick);
removechannel(channels, ircdstate->maxchannelcount, tokens[2]);
} else {
@@ -454,7 +454,7 @@ int processservermessage(SSL *server_ssl, char *str, struct client *clients, int
char *svrprefixcopy = strdup(tokens[0]);
// Just get the nick for comparison
extractnickfromprefix(svrprefixcopy, 1);
- if (strncmp(ircdstate->ircnick, svrprefixcopy, strlen(ircdstate->ircnick)) == 0) {
+ if ((strlen(ircdstate->ircnick) && strlen(svrprefixcopy)) && (strncmp(ircdstate->ircnick, svrprefixcopy, strlen(ircdstate->ircnick)) == 0)) {
debugprint(DEBUG_FULL, "Server NICK: nick is ours ('%s' vs '%s').\n", svrprefixcopy, ircdstate->ircnick);
// Make a copy of the old nickuserhost for updategreetings() below
char *nickuserhostcpy = strdup(ircdstate->nickuserhost);
@@ -773,7 +773,8 @@ int processservermessage(SSL *server_ssl, char *str, struct client *clients, int
debugprint(DEBUG_FULL, "Server CAP found and it is: %s with length %zd! Analysing...\n", tokens[1], strlen(tokens[1]));
// If the server said "CAP <ournick> ACK :multi-prefix" then it must have approved our CAP multi-prefix request
if (counter == 5) {
- if (strncmp(tokens[2], ircdstate->ircnick, strlen(tokens[2])) == 0 &&
+ if (strlen(tokens[2]) == strlen(ircdstate->ircnick) &&
+ strncmp(tokens[2], ircdstate->ircnick, strlen(tokens[2])) == 0 &&
strncmp(tokens[3], "ACK", strlen(tokens[3])) == 0 &&
strncmp(tokens[4], ":multi-prefix", strlen(tokens[4])) == 0) {
ircdstate->capmultiprefix = 1;
@@ -1005,6 +1006,7 @@ int processclientmessage(SSL *server_ssl, char *str, struct client *clients, int
// Send topic (or lack thereof) to client
// If there isn't one set (we guess this if topic timestamp is 0), send 331 RPL_NOTOPIC
+ // TODO - What if the topic is "0"?
if (strncmp(channels[i].topicwhen, "0", 1) == 0) {
// Prepare the no topic message...
if (!snprintf(outgoingmsg, MAXDATASIZE, ":%s 331 %s %s :No topic is set.", ircdstate->ircdname, ircdstate->ircnick, channels[i].name)) {
@@ -1172,6 +1174,7 @@ int processclientmessage(SSL *server_ssl, char *str, struct client *clients, int
if (strncasecmp(tokens[0], "MODE", strlen(tokens[0])) == 0) {
debugprint(DEBUG_FULL, "Client MODE found and it is: %s with length %zd! Analysing...\n", tokens[0], strlen(tokens[0]));
// Is it a ban MODE request (MODE #channel b)?
+ // TODO - Can something else beginning with "b" be in this position? Need a length comparison?
if (counter >= 3 && strncmp(tokens[2], "b", strlen("b")) == 0) {
debugprint(DEBUG_FULL, "Ban MODE request received, marking as pending.\n");
clients[clientindex].pendingban = 1;