From 58cd2d8bfde21cf745b4e8432038ce095c0fc2d4 Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Sun, 22 Aug 2021 19:43:36 +0200 Subject: [PATCH] Add some comments and add a redundant check for parameter writing. Better to be safe than to accidentally write OOB. --- src/modules/mode.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/modules/mode.c b/src/modules/mode.c index 25a112933..298eeb0d6 100644 --- a/src/modules/mode.c +++ b/src/modules/mode.c @@ -607,8 +607,22 @@ char *mode_ban_handler(Client *client, Channel *channel, char *param, int what, return tmpstr; } +/** Write the result of a mode change. + * This is used by do_mode_char_list_mode(), do_mode_char_member_mode() + * and do_extmode_char(). + * The result is later used by make_mode_str() to create the + * actual MODE line to be broadcasted to the channel and other servers. + */ void do_mode_char_write(char pvar[MAXMODEPARAMS][MODEBUFLEN + 3], u_int *pcount, u_int what, char modeletter, char *str) { + /* Caller should have made sure there was room! */ + if (*pcount >= MAXMODEPARAMS) +#ifdef DEBUGMODE + abort(); +#else + return 0; +#endif + ircsnprintf(pvar[*pcount], MODEBUFLEN + 3, "%c%c%s", (what == MODE_ADD) ? '+' : '-',