From be0365e152bf7fe76a1bb5d1bb39903ac63ab9ba Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Sun, 18 Dec 2011 23:24:22 +0100 Subject: [PATCH] Add an error message if a ban mask is invalid. This is given if the ban mask is too long, it is an invalid extban or the forward channel is invalid and no other message has been given about that. --- include/numeric.h | 1 + src/chmode.c | 31 +++++++++++++++++++++++++------ src/messages.tab | 2 +- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/include/numeric.h b/include/numeric.h index fbf52fb3..d92894f1 100644 --- a/include/numeric.h +++ b/include/numeric.h @@ -365,6 +365,7 @@ extern const char *form_str(int); #define RPL_ENDOFRSACHALLENGE2 741 #define ERR_MLOCKRESTRICTED 742 +#define ERR_INVALIDBAN 743 #define RPL_SCANMATCHED 750 #define RPL_SCANUMODES 751 diff --git a/src/chmode.c b/src/chmode.c index 822b0fc4..4b50cdcc 100644 --- a/src/chmode.c +++ b/src/chmode.c @@ -850,7 +850,12 @@ chm_ban(struct Client *source_p, struct Channel *chptr, * name etc. */ if(strlen(mask) > IRCD_MIN(BANLEN, MODEBUFLEN - 5)) + { + sendto_one_numeric(source_p, ERR_INVALIDBAN, + form_str(ERR_INVALIDBAN), + chptr->chname, c, raw_mask); return; + } /* Look for a $ after the first character. * As the first character, it marks an extban; afterwards @@ -869,8 +874,12 @@ chm_ban(struct Client *source_p, struct Channel *chptr, if (*mask == '$' && MyClient(source_p)) { if (!valid_extban(mask, source_p, chptr, mode_type)) - /* XXX perhaps return an error message here */ + { + sendto_one_numeric(source_p, ERR_INVALIDBAN, + form_str(ERR_INVALIDBAN), + chptr->chname, c, raw_mask); return; + } } /* For compatibility, only check the forward channel from @@ -878,18 +887,28 @@ chm_ban(struct Client *source_p, struct Channel *chptr, */ if(forward != NULL && MyClient(source_p)) { - if(!ConfigChannel.use_forward) - return; - if(!check_forward(source_p, chptr, forward)) - return; /* For simplicity and future flexibility, do not * allow '$' in forwarding targets. */ - if(strchr(forward, '$') != NULL) + if(!ConfigChannel.use_forward || + strchr(forward, '$') != NULL) + { + sendto_one_numeric(source_p, ERR_INVALIDBAN, + form_str(ERR_INVALIDBAN), + chptr->chname, c, raw_mask); + return; + } + /* check_forward() sends its own error message */ + if(!check_forward(source_p, chptr, forward)) return; /* Forwards only make sense for bans. */ if(mode_type != CHFL_BAN) + { + sendto_one_numeric(source_p, ERR_INVALIDBAN, + form_str(ERR_INVALIDBAN), + chptr->chname, c, raw_mask); return; + } } /* dont allow local clients to overflow the banlist, dont diff --git a/src/messages.tab b/src/messages.tab index 8e51e858..72dff03f 100644 --- a/src/messages.tab +++ b/src/messages.tab @@ -768,7 +768,7 @@ static const char * replies[] = { /* 740 RPL_RSACHALLENGE2*/ ":%s 740 %s :%s", /* 741 RPL_ENDOFRSACHALLENGE2*/ ":%s 741 %s :End of CHALLENGE", /* 742 ERR_MLOCKRESTRICTED */ "%s %c %s :MODE cannot be set due to channel having an active MLOCK restriction policy", -/* 743 */ NULL, +/* 743 ERR_INVALIDBAN */ "%s %c %s :Invalid ban mask", /* 744 */ NULL, /* 745 */ NULL, /* 746 */ NULL,