From 71b854d8abbfd224a2786e1f00127bf411f5ca1b Mon Sep 17 00:00:00 2001 From: Egor Date: Thu, 27 Mar 2025 06:54:13 +0200 Subject: [PATCH] irc: turn channel length limit into a define Also add 476 response. Also move that stuff out of config.h. This isn't something that should be configured at compile time. --- src/common.h | 2 ++ src/config.h | 1 - src/irc.cpp | 14 +++++++------- src/ircfmt.cpp | 7 +++++-- src/ircfmt.h | 2 +- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/common.h b/src/common.h index 5d7e02b..43288ea 100644 --- a/src/common.h +++ b/src/common.h @@ -11,6 +11,8 @@ struct tls; #endif +#define MAX_NICKLEN 32 +#define MAX_CHANLEN 33 #define MONITOR_LIMIT 100 #define SETBIT(var, bit, val) ((void)((val) ? ((var)|=(bit)) : ((var)&=~(bit)))) diff --git a/src/config.h b/src/config.h index f34bca1..0139baa 100644 --- a/src/config.h +++ b/src/config.h @@ -1,4 +1,3 @@ -#define MAX_NICKLEN 32 #ifndef ADMINLOC1 #define ADMINLOC1 "Location 1" #endif diff --git a/src/irc.cpp b/src/irc.cpp index fc54316..5c14123 100644 --- a/src/irc.cpp +++ b/src/irc.cpp @@ -1466,13 +1466,13 @@ void channel_join(struct client_data *client, const char *channel, const char *c { // TODO: check channel limit? if (channel[0] != '#' && channel[0] != '&') - return; // FIXME: error + return err_badchanmask(client, channel), sendbuf(client); if (strchr(channel, '\7') || strchr(channel, ' ') || strchr(channel, ',')) - return; // FIXME: error + return err_badchanmask(client, channel), sendbuf(client); size_t chanlen = strlen(channel); - if (chanlen > 32) - return; // FIXME: error - char key[33]; + if (chanlen >= MAX_CHANLEN) + return err_badchanmask(client, channel), sendbuf(client); + char key[MAX_CHANLEN]; memcpy(key, channel, chanlen+1); stringlower(key); struct channel *chan = channel_map.get(key); @@ -1784,9 +1784,9 @@ struct client_data *findClient(const char *nickname) struct channel *findChannel(const char *channel) { size_t chanlen = strlen(channel); - if (chanlen > 32) + if (chanlen >= MAX_CHANLEN) return NULL; - char key[33]; + char key[MAX_CHANLEN]; memcpy(key, channel, chanlen+1); stringlower(key); return channel_map.get(key); diff --git a/src/ircfmt.cpp b/src/ircfmt.cpp index 969c373..f2d8d56 100644 --- a/src/ircfmt.cpp +++ b/src/ircfmt.cpp @@ -150,7 +150,7 @@ void rpl_myinfo(struct client_data *client) // 004 } void rpl_isupport(struct client_data *client) // 005 { - copy_strf(&databuf, ":%s 005 %s NETWORK=PatchyIRC CASEMAPPING=ascii NICKLEN=%u EXCEPTS=e INVEX=I MAXTARGETS=1 CHANMODES=beIqw,k,l,Pimnst CHANTYPES=#& PREFIX=(ov)@+ STATUSMSG=@+ BOT=B WHOX MONITOR=%u :are supported by this server\r\n", hostname, client->nick, MAX_NICKLEN-1, MONITOR_LIMIT); + copy_strf(&databuf, ":%s 005 %s NETWORK=PatchyIRC CASEMAPPING=ascii NICKLEN=%u CHANNELLEN=%u EXCEPTS=e INVEX=I MAXTARGETS=1 CHANMODES=beIqw,k,l,Pimnst CHANTYPES=#& PREFIX=(ov)@+ STATUSMSG=@+ BOT=B WHOX MONITOR=%u :are supported by this server\r\n", hostname, client->nick, MAX_NICKLEN-1, MAX_CHANLEN-1, MONITOR_LIMIT); } #if 0 @@ -648,7 +648,10 @@ void err_badchannelkey(struct client_data *client, struct channel *chan) // 475 { copy_strf(&databuf, ":%s 475 %s %s :Cannot join channel (+k)\r\n", hostname, client->nick, chan->name); } -// 476 ERR_BADCHANMASK +void err_badchanmask(struct client_data *client, const char *channel) // 476 +{ + copy_strf(&databuf, ":%s 476 %s :Bad Channel Mask\r\n", hostname, client->nick, channel); +} void err_noprivileges(struct client_data *client) // 481 { copy_strf(&databuf, ":%s 481 %s :Permission Denied- You're not an IRC operator\r\n", hostname, client->nick); diff --git a/src/ircfmt.h b/src/ircfmt.h index 75ef093..8757660 100644 --- a/src/ircfmt.h +++ b/src/ircfmt.h @@ -122,7 +122,7 @@ void err_unknownmode(struct client_data *client, char mode); // 472 void err_inviteonlychan(struct client_data *client, struct channel *chan); // 473 void err_bannedfromchan(struct client_data *client, struct channel *chan); // 474 void err_badchannelkey(struct client_data *client, struct channel *chan); // 475 -// 476 ERR_BADCHANMASK +void err_badchanmask(struct client_data *client, const char *channel); // 476 void err_noprivileges(struct client_data *client); // 481 void err_chanoprivsneeded(struct client_data *client, struct channel *chan); // 481 // 483 ERR_CANTKILLSERVER -- 2.56.0