chmode: centralise + test mode limits (#94)

This commit is contained in:
Ed Kellett 2021-01-26 11:22:39 +00:00 committed by GitHub
parent 12fd6e80c5
commit 2e79cebb9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 35 deletions

View file

@ -63,8 +63,6 @@
static struct ChModeChange mode_changes[BUFSIZE];
static int mode_count;
static int mode_limit;
static int mode_limit_simple;
static int mask_pos;
static int removed_mask_pos;
@ -581,9 +579,6 @@ chm_simple(struct Client *source_p, struct Channel *chptr,
if(!allow_mode_change(source_p, chptr, alevel, errors, c))
return;
if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE))
return;
/* setting + */
if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type))
{
@ -661,9 +656,6 @@ chm_hidden(struct Client *source_p, struct Channel *chptr,
return;
}
if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE))
return;
/* setting + */
if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type))
{
@ -707,9 +699,6 @@ chm_staff(struct Client *source_p, struct Channel *chptr,
return;
}
if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE))
return;
/* setting + */
if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type))
{
@ -840,10 +829,6 @@ chm_ban(struct Client *source_p, struct Channel *chptr,
if (!allow_mode_change(source_p, chptr, alevel, errors, c))
return;
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
return;
/* empty ban, or starts with ':' which messes up s2s, ignore it */
if (EmptyString(arg) || *arg == ':')
return;
@ -1002,9 +987,6 @@ chm_op(struct Client *source_p, struct Channel *chptr,
return;
}
if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
return;
if(dir == MODE_ADD)
{
if(targ_p == source_p && mstptr->flags & CHFL_CHANOP)
@ -1070,9 +1052,6 @@ chm_voice(struct Client *source_p, struct Channel *chptr,
return;
}
if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
return;
if(dir == MODE_ADD)
{
mode_changes[mode_count].letter = c;
@ -1105,9 +1084,6 @@ chm_limit(struct Client *source_p, struct Channel *chptr,
if (!allow_mode_change(source_p, chptr, alevel, errors, c))
return;
if (MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE))
return;
if (dir == MODE_ADD)
{
if (EmptyString(arg) || (limit = atoi(arg)) <= 0)
@ -1147,9 +1123,6 @@ chm_throttle(struct Client *source_p, struct Channel *chptr,
if (!allow_mode_change(source_p, chptr, alevel, errors, c))
return;
if (MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE))
return;
if (dir == MODE_ADD)
{
if (sscanf(arg, "%d:%d", &joins, &timeslice) < 2)
@ -1219,9 +1192,6 @@ chm_forward(struct Client *source_p, struct Channel *chptr,
}
#endif
if (MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE))
return;
if (dir == MODE_ADD)
{
if(EmptyString(arg))
@ -1263,9 +1233,6 @@ chm_key(struct Client *source_p, struct Channel *chptr,
if (!allow_mode_change(source_p, chptr, alevel, errors, c))
return;
if (MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE))
return;
if (dir == MODE_ADD)
{
key = LOCAL_COPY(arg);
@ -1373,12 +1340,12 @@ set_channel_mode(struct Client *client_p, struct Client *source_p,
char c;
struct Client *fakesource_p;
int flags_list[3] = { ALL_MEMBERS, ONLY_CHANOPS, ONLY_OPERS };
int mode_limit = 0;
int mode_limit_simple = 0;
mask_pos = 0;
removed_mask_pos = 0;
mode_count = 0;
mode_limit = 0;
mode_limit_simple = 0;
/* Hide connecting server on netburst -- jilles */
if (ConfigServerHide.flatten_links && IsServer(source_p) && !has_id(source_p) && !HasSentEob(source_p))
@ -1445,6 +1412,14 @@ set_channel_mode(struct Client *client_p, struct Client *source_p,
continue;
}
if (MyClient(source_p))
{
if (use_arg && ++mode_limit > MAXMODEPARAMS)
continue;
if (!use_arg && ++mode_limit_simple > MAXMODES_SIMPLE)
continue;
}
char op = effective_dir == MODE_ADD ? '+' :
effective_dir == MODE_DEL ? '-' :
'=';

View file

@ -66,6 +66,41 @@ test_chmode_parse(void)
remove_hook("get_channel_access", chmode_access_hook);
}
void
test_chmode_limits(void)
{
char chmode_buf[2 + MAXMODEPARAMS + 1] = "+";
const char *chmode_parv[1 + MAXMODEPARAMS + 1] = { chmode_buf };
add_hook_prio("get_channel_access", chmode_access_hook, HOOK_MONITOR);
for (size_t i = 0; i < MAXMODEPARAMS + 1; i++)
{
chmode_buf[i + 1] = 'l';
chmode_parv[i + 1] = "7";
}
set_channel_mode(client, client, channel, NULL, 1 + MAXMODEPARAMS + 1, chmode_parv);
is_int('+', chmode_hdata.modestr[0], MSG);
for (size_t i = 0; i < MAXMODEPARAMS; i++)
{
is_int('l', chmode_hdata.modestr[i + 1], MSG);
}
is_int(' ', chmode_hdata.modestr[MAXMODEPARAMS + 1], MSG);
for (size_t i = 0; i < MAXMODEPARAMS; i++)
{
is_int(' ', chmode_hdata.modestr[MAXMODEPARAMS + 1 + i * 2], MSG);
is_int('7', chmode_hdata.modestr[MAXMODEPARAMS + 2 + i * 2], MSG);
}
is_int('\0', chmode_hdata.modestr[MAXMODEPARAMS * 3 + 1], MSG);
remove_hook("get_channel_access", chmode_access_hook);
}
static void
chmode_init(void)
{
@ -84,6 +119,7 @@ main(int argc, char *argv[])
chmode_init();
test_chmode_parse();
test_chmode_limits();
client_util_free();
ircd_util_free();