From fe5fc851aa9ac2cc26784e91b1eebd16f87ddfb9 Mon Sep 17 00:00:00 2001 From: Simon Arlott Date: Fri, 19 Jan 2018 23:24:55 +0000 Subject: [PATCH] gcc7 fixes: NICKLEN -> NAMELEN Use NAMELEN instead of NICKLEN when accessing Client->name because it could in theory be a HOSTLEN length string. --- extensions/extb_hostmask.c | 8 ++++---- include/client.h | 2 +- include/ircd_defs.h | 4 +++- ircd/channel.c | 18 +++++++++--------- ircd/s_conf.c | 2 +- ircd/s_user.c | 4 ++-- modules/m_services.c | 4 ++-- modules/m_signon.c | 4 ++-- 8 files changed, 24 insertions(+), 22 deletions(-) diff --git a/extensions/extb_hostmask.c b/extensions/extb_hostmask.c index 15182981..c4776e55 100644 --- a/extensions/extb_hostmask.c +++ b/extensions/extb_hostmask.c @@ -32,10 +32,10 @@ _moddeinit(void) static int eb_hostmask(const char *banstr, struct Client *client_p, struct Channel *chptr, long mode_type) { - char src_host[NICKLEN + USERLEN + HOSTLEN + 6]; - char src_iphost[NICKLEN + USERLEN + HOSTLEN + 6]; - char src_althost[NICKLEN + USERLEN + HOSTLEN + 6]; - char src_ip4host[NICKLEN + USERLEN + HOSTLEN + 6]; + char src_host[NAMELEN + USERLEN + HOSTLEN + 6]; + char src_iphost[NAMELEN + USERLEN + HOSTLEN + 6]; + char src_althost[NAMELEN + USERLEN + HOSTLEN + 6]; + char src_ip4host[NAMELEN + USERLEN + HOSTLEN + 6]; struct sockaddr_in ip4; char *s = src_host, *s2 = src_iphost, *s3 = NULL, *s4 = NULL; diff --git a/include/client.h b/include/client.h index e80a7768..89c4cf8a 100644 --- a/include/client.h +++ b/include/client.h @@ -126,7 +126,7 @@ struct Client unsigned long serial; /* used to enforce 1 send per nick */ /* client->name is the unique name for a client nick or host */ - char name[HOSTLEN + 1]; + char name[NAMELEN + 1]; /* * client->username is the username from ident or the USER message, diff --git a/include/ircd_defs.h b/include/ircd_defs.h index 00bd5546..cea850ce 100644 --- a/include/ircd_defs.h +++ b/include/ircd_defs.h @@ -97,7 +97,9 @@ #define EXT_BUFSIZE (TAGSLEN + DATALEN + 1) #define OPERNICKLEN (NICKLEN*2) /* Length of OPERNICKs. */ -#define USERHOST_REPLYLEN (NICKLEN+HOSTLEN+USERLEN+5) +#define NAMELEN (MAX(NICKLEN, HOSTLEN)) + +#define USERHOST_REPLYLEN (NAMELEN+HOSTLEN+USERLEN+5) #define MAX_DATE_STRING 32 /* maximum string length for a date string */ #define HELPLEN 400 diff --git a/ircd/channel.c b/ircd/channel.c index 585f3be9..cb4bdd5c 100644 --- a/ircd/channel.c +++ b/ircd/channel.c @@ -539,10 +539,10 @@ is_banned_list(struct Channel *chptr, rb_dlink_list *list, struct Client *who, struct membership *msptr, const char *s, const char *s2, const char **forward) { - char src_host[NICKLEN + USERLEN + HOSTLEN + 6]; - char src_iphost[NICKLEN + USERLEN + HOSTLEN + 6]; - char src_althost[NICKLEN + USERLEN + HOSTLEN + 6]; - char src_ip4host[NICKLEN + USERLEN + HOSTLEN + 6]; + char src_host[NAMELEN + USERLEN + HOSTLEN + 6]; + char src_iphost[NAMELEN + USERLEN + HOSTLEN + 6]; + char src_althost[NAMELEN + USERLEN + HOSTLEN + 6]; + char src_ip4host[NAMELEN + USERLEN + HOSTLEN + 6]; char *s3 = NULL; char *s4 = NULL; struct sockaddr_in ip4; @@ -722,9 +722,9 @@ can_join(struct Client *source_p, struct Channel *chptr, const char *key, const rb_dlink_node *invite = NULL; rb_dlink_node *ptr; struct Ban *invex = NULL; - char src_host[NICKLEN + USERLEN + HOSTLEN + 6]; - char src_iphost[NICKLEN + USERLEN + HOSTLEN + 6]; - char src_althost[NICKLEN + USERLEN + HOSTLEN + 6]; + char src_host[NAMELEN + USERLEN + HOSTLEN + 6]; + char src_iphost[NAMELEN + USERLEN + HOSTLEN + 6]; + char src_althost[NAMELEN + USERLEN + HOSTLEN + 6]; int use_althost = 0; int i = 0; hook_data_channel moduledata; @@ -964,8 +964,8 @@ find_bannickchange_channel(struct Client *client_p) struct Channel *chptr; struct membership *msptr; rb_dlink_node *ptr; - char src_host[NICKLEN + USERLEN + HOSTLEN + 6]; - char src_iphost[NICKLEN + USERLEN + HOSTLEN + 6]; + char src_host[NAMELEN + USERLEN + HOSTLEN + 6]; + char src_iphost[NAMELEN + USERLEN + HOSTLEN + 6]; if (!MyClient(client_p)) return NULL; diff --git a/ircd/s_conf.c b/ircd/s_conf.c index ed5a41e5..329129cb 100644 --- a/ircd/s_conf.c +++ b/ircd/s_conf.c @@ -1261,7 +1261,7 @@ char * get_oper_name(struct Client *client_p) { /* +5 for !,@,{,} and null */ - static char buffer[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5]; + static char buffer[NAMELEN + USERLEN + HOSTLEN + HOSTLEN + 5]; if(MyOper(client_p)) { diff --git a/ircd/s_user.c b/ircd/s_user.c index 45d3c45e..ac029dbe 100644 --- a/ircd/s_user.c +++ b/ircd/s_user.c @@ -414,13 +414,13 @@ register_local_user(struct Client *client_p, struct Client *source_p) /* Apply nick override */ if(*source_p->preClient->spoofnick) { - char note[NICKLEN + 10]; + char note[NAMELEN + 10]; del_from_client_hash(source_p->name, source_p); rb_strlcpy(source_p->name, source_p->preClient->spoofnick, NICKLEN + 1); add_to_client_hash(source_p->name, source_p); - snprintf(note, NICKLEN + 10, "Nick: %s", source_p->name); + snprintf(note, sizeof(note), "Nick: %s", source_p->name); rb_note(source_p->localClient->F, note); } diff --git a/modules/m_services.c b/modules/m_services.c index b8a1f363..6633319d 100644 --- a/modules/m_services.c +++ b/modules/m_services.c @@ -160,7 +160,7 @@ me_rsfnc(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source struct Client *target_p; struct Client *exist_p; time_t newts, curts; - char note[NICKLEN + 10]; + char note[NAMELEN + 10]; if(!(source_p->flags & FLAGS_SERVICE)) { @@ -252,7 +252,7 @@ doit: del_all_accepts(target_p); - snprintf(note, NICKLEN + 10, "Nick: %s", target_p->name); + snprintf(note, sizeof(note), "Nick: %s", target_p->name); rb_note(target_p->localClient->F, note); } diff --git a/modules/m_signon.c b/modules/m_signon.c index 6aeecc47..0714b47a 100644 --- a/modules/m_signon.c +++ b/modules/m_signon.c @@ -233,11 +233,11 @@ me_svslogin(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *sou } else { - char note[NICKLEN + 10]; + char note[NAMELEN + 10]; send_signon(NULL, target_p, nick, user, host, rb_current_time(), login); - snprintf(note, NICKLEN + 10, "Nick: %s", target_p->name); + snprintf(note, sizeof(note), "Nick: %s", target_p->name); rb_note(target_p->localClient->F, note); } }