From 0982871a9992e58c9a9e0bd1aedbff3e0e0d8877 Mon Sep 17 00:00:00 2001 From: Aaron Jones Date: Sun, 15 May 2016 03:57:16 +0000 Subject: [PATCH] strcpy: mass-migrate to strlcpy where appropriate --- ircd/client.c | 2 +- ircd/ircd.c | 2 +- ircd/match.c | 8 ++++---- ircd/newconf.c | 2 +- ircd/s_serv.c | 2 +- ircd/s_user.c | 2 +- ircd/sslproc.c | 2 +- modules/core/m_join.c | 6 +++--- modules/core/m_nick.c | 10 +++++----- modules/core/m_server.c | 2 +- modules/m_pass.c | 2 +- modules/m_sasl.c | 2 +- modules/m_signon.c | 8 ++++---- 13 files changed, 25 insertions(+), 25 deletions(-) diff --git a/ircd/client.c b/ircd/client.c index d33aa13e..9ec5c6cc 100644 --- a/ircd/client.c +++ b/ircd/client.c @@ -247,7 +247,7 @@ make_client(struct Client *from) } SetUnknown(client_p); - strcpy(client_p->username, "unknown"); + rb_strlcpy(client_p->username, "unknown", sizeof(client_p->username)); return client_p; } diff --git a/ircd/ircd.c b/ircd/ircd.c index 998e2c87..9df6a759 100644 --- a/ircd/ircd.c +++ b/ircd/ircd.c @@ -815,7 +815,7 @@ charybdis_main(int argc, char * const argv[]) ierror("no server sid specified in serverinfo block."); return -2; } - strcpy(me.id, ServerInfo.sid); + rb_strlcpy(me.id, ServerInfo.sid, sizeof(me.id)); init_uid(); /* serverinfo{} description must exist. If not, error out. */ diff --git a/ircd/match.c b/ircd/match.c index 66ffe236..165baeab 100644 --- a/ircd/match.c +++ b/ircd/match.c @@ -358,8 +358,8 @@ int match_ips(const char *s1, const char *s2) void *ipptr, *maskptr; int cidrlen, aftype; - strcpy(mask, s1); - strcpy(address, s2); + rb_strlcpy(mask, s1, sizeof(mask)); + rb_strlcpy(address, s2, sizeof(address)); len = strrchr(mask, '/'); if (len == NULL) @@ -422,8 +422,8 @@ int match_cidr(const char *s1, const char *s2) void *ipptr, *maskptr; int cidrlen, aftype; - strcpy(mask, s1); - strcpy(address, s2); + rb_strlcpy(mask, s1, sizeof(mask)); + rb_strlcpy(address, s2, sizeof(address)); ipmask = strrchr(mask, '@'); if (ipmask == NULL) diff --git a/ircd/newconf.c b/ircd/newconf.c index 4f245063..72e6060a 100644 --- a/ircd/newconf.c +++ b/ircd/newconf.c @@ -225,7 +225,7 @@ conf_set_serverinfo_sid(void *data) return; } - strcpy(ServerInfo.sid, sid); + rb_strlcpy(ServerInfo.sid, sid, sizeof(ServerInfo.sid)); } } diff --git a/ircd/s_serv.c b/ircd/s_serv.c index 7b5d15cb..5c3fa62a 100644 --- a/ircd/s_serv.c +++ b/ircd/s_serv.c @@ -1132,7 +1132,7 @@ serv_connect(struct server_conf *server_p, struct Client *by) */ make_server(client_p); if(by && IsClient(by)) - strcpy(client_p->serv->by, by->name); + rb_strlcpy(client_p->serv->by, by->name, sizeof(client_p->serv->by)); else strcpy(client_p->serv->by, "AutoConn."); diff --git a/ircd/s_user.c b/ircd/s_user.c index 7c668b89..b18df182 100644 --- a/ircd/s_user.c +++ b/ircd/s_user.c @@ -621,7 +621,7 @@ register_local_user(struct Client *client_p, struct Client *source_p) */ if(!*source_p->id) { - strcpy(source_p->id, generate_uid()); + rb_strlcpy(source_p->id, generate_uid(), sizeof(source_p->id)); add_to_id_hash(source_p->id, source_p); } diff --git a/ircd/sslproc.c b/ircd/sslproc.c index 941fd9c1..b8d551bb 100644 --- a/ircd/sslproc.c +++ b/ircd/sslproc.c @@ -524,7 +524,7 @@ ssl_process_certfp(ssl_ctl_t * ctl, ssl_ctl_buf_t * ctl_buf) rb_free(client_p->certfp); certfp_string = rb_malloc(method_len + len * 2 + 1); - strcpy(certfp_string, method_string); + rb_strlcpy(certfp_string, method_string, method_len + len * 2 + 1); for(uint32_t i = 0; i < len; i++) snprintf(certfp_string + method_len + 2 * i, 3, "%02x", certfp[i]); diff --git a/modules/core/m_join.c b/modules/core/m_join.c index 5ed6cb29..f74d7dd5 100644 --- a/modules/core/m_join.c +++ b/modules/core/m_join.c @@ -179,7 +179,7 @@ m_join(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p /* join 0 parts all channels */ if(*name == '0' && (name[1] == ',' || name[1] == '\0') && name == chanlist) { - (void) strcpy(jbuf, "0"); + rb_strlcpy(jbuf, "0", sizeof(jbuf)); continue; } @@ -687,7 +687,7 @@ ms_sjoin(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source if(oldmode->limit > mode.limit) mode.limit = oldmode->limit; if(strcmp(mode.key, oldmode->key) < 0) - strcpy(mode.key, oldmode->key); + rb_strlcpy(mode.key, oldmode->key, sizeof(mode.key)); if(oldmode->join_num > mode.join_num || (oldmode->join_num == mode.join_num && oldmode->join_time > mode.join_time)) @@ -696,7 +696,7 @@ ms_sjoin(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source mode.join_time = oldmode->join_time; } if(irccmp(mode.forward, oldmode->forward) < 0) - strcpy(mode.forward, oldmode->forward); + rb_strlcpy(mode.forward, oldmode->forward, sizeof(mode.forward)); } else { diff --git a/modules/core/m_nick.c b/modules/core/m_nick.c index 7930ddea..81f916ec 100644 --- a/modules/core/m_nick.c +++ b/modules/core/m_nick.c @@ -155,7 +155,7 @@ mr_nick(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_ if((target_p = find_named_client(nick)) == NULL) set_initial_nick(client_p, source_p, nick); else if(source_p == target_p) - strcpy(source_p->name, nick); + rb_strlcpy(source_p->name, nick, sizeof(source_p->name)); else sendto_one(source_p, form_str(ERR_NICKNAMEINUSE), me.name, "*", nick); } @@ -593,7 +593,7 @@ set_initial_nick(struct Client *client_p, struct Client *source_p, char *nick) if(source_p->name[0]) del_from_client_hash(source_p->name, source_p); - strcpy(source_p->name, nick); + rb_strlcpy(source_p->name, nick, sizeof(source_p->name)); add_to_client_hash(nick, source_p); snprintf(note, sizeof(note), "Nick: %s", nick); @@ -680,7 +680,7 @@ change_local_nick(struct Client *client_p, struct Client *source_p, /* Finally, add to hash */ del_from_client_hash(source_p->name, source_p); - strcpy(source_p->name, nick); + rb_strlcpy(source_p->name, nick, sizeof(source_p->name)); add_to_client_hash(nick, source_p); if(!samenick) @@ -743,7 +743,7 @@ change_remote_nick(struct Client *client_p, struct Client *source_p, if((nd = rb_dictionary_retrieve(nd_dict, nick))) free_nd_entry(nd); - strcpy(source_p->name, nick); + rb_strlcpy(source_p->name, nick, sizeof(source_p->name)); add_to_client_hash(nick, source_p); if(!samenick) @@ -1023,7 +1023,7 @@ register_client(struct Client *client_p, struct Client *server, source_p->hopcount = atoi(parv[2]); source_p->tsinfo = newts; - strcpy(source_p->name, nick); + rb_strlcpy(source_p->name, nick, sizeof(source_p->name)); rb_strlcpy(source_p->username, parv[5], sizeof(source_p->username)); rb_strlcpy(source_p->host, parv[6], sizeof(source_p->host)); rb_strlcpy(source_p->orighost, source_p->host, sizeof(source_p->orighost)); diff --git a/modules/core/m_server.c b/modules/core/m_server.c index 213d7f51..1ceaca9f 100644 --- a/modules/core/m_server.c +++ b/modules/core/m_server.c @@ -636,7 +636,7 @@ ms_sid(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p rb_strlcpy(target_p->name, parv[1], sizeof(target_p->name)); target_p->hopcount = atoi(parv[2]); - strcpy(target_p->id, parv[3]); + rb_strlcpy(target_p->id, parv[3], sizeof(target_p->id)); set_server_gecos(target_p, parv[4]); target_p->servptr = source_p; diff --git a/modules/m_pass.c b/modules/m_pass.c index bf60e2e1..36398055 100644 --- a/modules/m_pass.c +++ b/modules/m_pass.c @@ -104,7 +104,7 @@ mr_pass(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_ EmptyString(client_p->id)) { client_p->localClient->caps |= CAP_TS6; - strcpy(client_p->id, parv[4]); + rb_strlcpy(client_p->id, parv[4], sizeof(client_p->id)); } } } diff --git a/modules/m_sasl.c b/modules/m_sasl.c index 470832cb..ee201017 100644 --- a/modules/m_sasl.c +++ b/modules/m_sasl.c @@ -165,7 +165,7 @@ m_authenticate(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client * if(!*source_p->id) { /* Allocate a UID. */ - strcpy(source_p->id, generate_uid()); + rb_strlcpy(source_p->id, generate_uid(), sizeof(source_p->id)); add_to_id_hash(source_p->id, source_p); } diff --git a/modules/m_signon.c b/modules/m_signon.c index 9175c357..6aeecc47 100644 --- a/modules/m_signon.c +++ b/modules/m_signon.c @@ -221,13 +221,13 @@ me_svslogin(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *sou struct User *user_p = make_user(target_p); if(valid & NICK_VALID) - strcpy(target_p->preClient->spoofnick, nick); + rb_strlcpy(target_p->preClient->spoofnick, nick, sizeof(target_p->preClient->spoofnick)); if(valid & USER_VALID) - strcpy(target_p->preClient->spoofuser, user); + rb_strlcpy(target_p->preClient->spoofuser, user, sizeof(target_p->preClient->spoofuser)); if(valid & HOST_VALID) - strcpy(target_p->preClient->spoofhost, host); + rb_strlcpy(target_p->preClient->spoofhost, host, sizeof(target_p->preClient->spoofhost)); rb_strlcpy(user_p->suser, login, NICKLEN + 1); } @@ -410,7 +410,7 @@ send_signon(struct Client *client_p, struct Client *target_p, use_id(target_p), nick, user, host, (long) target_p->tsinfo, *login ? login : "0"); - strcpy(target_p->user->suser, login); + rb_strlcpy(target_p->user->suser, login, sizeof(target_p->user->suser)); change_nick_user_host(target_p, nick, user, host, newts, "Signing %s (%s)", *login ? "in" : "out", nick); }