From 9fc1e758abe8d700d2ad36ba059d83ddedb6a7b7 Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Sat, 14 Sep 2019 16:53:15 +0200 Subject: [PATCH] Mass change of dst = strdup(str) to safe_strdup(dst,str) but with a manual audit since 'dst' must now be initialized memory. There's still a raw_strdup() if you insist. This is step 2 of X of memory allocation changes --- src/api-clicap.c | 2 +- src/api-event.c | 7 +- src/api-history-backend.c | 2 +- src/api-isupport.c | 12 +--- src/api-messagetag.c | 2 +- src/api-moddata.c | 2 +- src/auth.c | 2 +- src/bsd.c | 6 +- src/channel.c | 4 +- src/conf.c | 111 +++++++++++++++--------------- src/conf_preprocessor.c | 12 ++-- src/dns.c | 12 ++-- src/extra.c | 10 ++- src/hash.c | 2 +- src/ircd.c | 2 +- src/match.c | 2 +- src/misc.c | 6 +- src/modules.c | 4 +- src/modules/account-tag.c | 4 +- src/modules/authprompt.c | 2 +- src/modules/away.c | 3 +- src/modules/blacklist.c | 4 +- src/modules/certfp.c | 4 +- src/modules/channeldb.c | 6 +- src/modules/charsys.c | 2 +- src/modules/chghost.c | 10 +-- src/modules/history_backend_mem.c | 4 +- src/modules/jumpserver.c | 6 +- src/modules/list.c | 4 +- src/modules/mdex.c | 7 +- src/modules/message-ids.c | 2 +- src/modules/message-tags.c | 8 ++- src/modules/mode.c | 6 +- src/modules/nick.c | 4 +- src/modules/oper.c | 5 +- src/modules/protoctl.c | 2 +- src/modules/restrict-commands.c | 4 +- src/modules/sasl.c | 7 +- src/modules/server-time.c | 4 +- src/modules/sethost.c | 7 +- src/modules/svsmode.c | 5 +- src/modules/svsnline.c | 4 +- src/modules/webirc.c | 3 +- src/modules/websocket.c | 3 +- src/operclass.c | 4 +- src/packet.c | 2 +- src/send.c | 2 +- src/serv.c | 2 +- src/tls.c | 4 +- src/updconf.c | 2 +- src/url.c | 8 +-- src/user.c | 11 +-- src/whowas.c | 12 ++-- src/windows/rtf.c | 2 +- 54 files changed, 164 insertions(+), 205 deletions(-) diff --git a/src/api-clicap.c b/src/api-clicap.c index c4f95558d..1648f46bf 100644 --- a/src/api-clicap.c +++ b/src/api-clicap.c @@ -170,7 +170,7 @@ ClientCapability *ClientCapabilityAdd(Module *module, ClientCapabilityInfo *clic } /* New client capability */ clicap = safe_alloc(sizeof(ClientCapability)); - clicap->name = strdup(clicap_request->name); + safe_strdup(clicap->name, clicap_request->name); clicap->cap = v; } /* Add or update the following fields: */ diff --git a/src/api-event.c b/src/api-event.c index 22faa44e0..a4a1c9c30 100644 --- a/src/api-event.c +++ b/src/api-event.c @@ -40,7 +40,7 @@ Event *EventAdd(Module *module, char *name, long every, long howmany, return NULL; } newevent = safe_alloc(sizeof(Event)); - newevent->name = strdup(name); + safe_strdup(newevent->name, name); newevent->howmany = howmany; newevent->every = every; newevent->event = event; @@ -120,10 +120,7 @@ int EventMod(Event *event, EventInfo *mods) if (mods->flags & EMOD_HOWMANY) event->howmany = mods->howmany; if (mods->flags & EMOD_NAME) - { - free(event->name); - event->name = strdup(mods->name); - } + safe_strdup(event->name, mods->name); if (mods->flags & EMOD_EVENT) event->event = mods->event; if (mods->flags & EMOD_DATA) diff --git a/src/api-history-backend.c b/src/api-history-backend.c index 4995f7fd4..d50ac3874 100644 --- a/src/api-history-backend.c +++ b/src/api-history-backend.c @@ -83,7 +83,7 @@ HistoryBackend *HistoryBackendAdd(Module *module, HistoryBackendInfo *mreq) } else { /* New history backend */ m = safe_alloc(sizeof(HistoryBackend)); - m->name = strdup(mreq->name); + safe_strdup(m->name, mreq->name); } /* Add or update the following fields: */ diff --git a/src/api-isupport.c b/src/api-isupport.c index d87838e9c..7c799611a 100644 --- a/src/api-isupport.c +++ b/src/api-isupport.c @@ -138,13 +138,7 @@ void isupport_init(void) */ void ISupportSetValue(ISupport *isupport, const char *value) { - if (isupport->value) - free(isupport->value); - if (value) - isupport->value = strdup(value); - else - isupport->value = NULL; - + safe_strdup(isupport->value, value); make_isupportstrings(); } @@ -219,9 +213,9 @@ ISupport *ISupportAdd(Module *module, const char *token, const char *value) isupport = safe_alloc(sizeof(ISupport)); isupport->owner = module; - isupport->token = strdup(token); + safe_strdup(isupport->token, token); if (value) - isupport->value = strdup(value); + safe_strdup(isupport->value, value); isupport_add_sorted(isupport); make_isupportstrings(); if (module) diff --git a/src/api-messagetag.c b/src/api-messagetag.c index 9e8a80efe..2f04ef49a 100644 --- a/src/api-messagetag.c +++ b/src/api-messagetag.c @@ -89,7 +89,7 @@ MessageTagHandler *MessageTagHandlerAdd(Module *module, MessageTagHandlerInfo *m } else { /* New message tag handler */ m = safe_alloc(sizeof(MessageTagHandler)); - m->name = strdup(mreq->name); + safe_strdup(m->name, mreq->name); } /* Add or update the following fields: */ m->owner = module; diff --git a/src/api-moddata.c b/src/api-moddata.c index e56fe2315..9414ffb2e 100644 --- a/src/api-moddata.c +++ b/src/api-moddata.c @@ -71,7 +71,7 @@ ModDataInfo *ModDataAdd(Module *module, ModDataInfo req) new_struct = 1; m = safe_alloc(sizeof(ModDataInfo)); - m->name = strdup(req.name); + safe_strdup(m->name, req.name); m->slot = slotav; m->type = req.type; moddataadd_isok: diff --git a/src/auth.c b/src/auth.c index cea857b9e..295deafc5 100644 --- a/src/auth.c +++ b/src/auth.c @@ -264,7 +264,7 @@ AuthConfig *AuthBlockToAuthConfig(ConfigEntry *ce) type = AUTHTYPE_PLAINTEXT; as = safe_alloc(sizeof(AuthConfig)); - as->data = strdup(ce->ce_vardata); + safe_strdup(as->data, ce->ce_vardata); as->type = type; return as; } diff --git a/src/bsd.c b/src/bsd.c index 0838cdfbd..d33620125 100644 --- a/src/bsd.c +++ b/src/bsd.c @@ -953,7 +953,7 @@ refuse_client: /* Fill in sockhost & ip ASAP */ set_sockhost(acptr, ip); - acptr->ip = strdup(ip); + safe_strdup(acptr->ip, ip); acptr->local->port = port; acptr->local->fd = fd; @@ -1364,7 +1364,7 @@ int connect_server(ConfigItem_link *aconf, Client *by, struct hostent *hp) if (is_valid_ip(aconf->outgoing.hostname)) { /* link::outgoing::hostname is an IP address. No need to resolve host. */ - aconf->connect_ip = strdup(aconf->outgoing.hostname); + safe_strdup(aconf->connect_ip, aconf->outgoing.hostname); } else { /* It's a hostname, let the resolver look it up. */ @@ -1450,7 +1450,7 @@ int connect_inet(ConfigItem_link *aconf, Client *cptr) if (strchr(aconf->connect_ip, ':')) SetIPV6(cptr); - cptr->ip = strdup(aconf->connect_ip); + safe_strdup(cptr->ip, aconf->connect_ip); snprintf(buf, sizeof buf, "Outgoing connection: %s", get_client_name(cptr, TRUE)); cptr->local->fd = fd_socket(IsIPV6(cptr) ? AF_INET6 : AF_INET, SOCK_STREAM, 0, buf); diff --git a/src/channel.c b/src/channel.c index cdc82d651..926faa308 100644 --- a/src/channel.c +++ b/src/channel.c @@ -1129,9 +1129,7 @@ void send_user_joins(Client *cptr, Client *user) */ void set_channel_mlock(Client *cptr, Client *sptr, Channel *chptr, const char *newmlock, int propagate) { - if (chptr->mode_lock) - safe_free(chptr->mode_lock); - chptr->mode_lock = (newmlock != NULL) ? strdup(newmlock) : NULL; + safe_strdup(chptr->mode_lock, newmlock); if (propagate) { diff --git a/src/conf.c b/src/conf.c index d7cfeb19e..dcc3e47c5 100644 --- a/src/conf.c +++ b/src/conf.c @@ -1639,9 +1639,9 @@ void postconf_defaults(void) if (!tk->set_by) { if (me.name[0] != '\0') - tk->set_by = strdup(me.name); + safe_strdup(tk->set_by, me.name); else - tk->set_by = strdup(conf_me->name ? conf_me->name : "~server~"); + safe_strdup(tk->set_by, conf_me->name ? conf_me->name : "~server~"); } } @@ -1651,17 +1651,16 @@ void postconf_defaults(void) continue; /* global entry or something else.. */ if (!strcmp(tk->ptr.spamfilter->tkl_reason, "")) { - safe_free(tk->ptr.spamfilter->tkl_reason); - tk->ptr.spamfilter->tkl_reason = strdup(encoded); + safe_strdup(tk->ptr.spamfilter->tkl_reason, encoded); tk->ptr.spamfilter->tkl_duration = SPAMFILTER_BAN_TIME; } /* This one is even more ugly, but our config crap is VERY confusing :[ */ if (!tk->set_by) { if (me.name[0] != '\0') - tk->set_by = strdup(me.name); + safe_strdup(tk->set_by, me.name); else - tk->set_by = strdup(conf_me->name ? conf_me->name : "~server~"); + safe_strdup(tk->set_by, conf_me->name ? conf_me->name : "~server~"); } } @@ -3417,15 +3416,15 @@ int _conf_files(ConfigFile *conf, ConfigEntry *ce) conf_files = safe_alloc(sizeof(ConfigItem_files)); /* set defaults */ - conf_files->motd_file = strdup(MPATH); - conf_files->rules_file = strdup(RPATH); - conf_files->smotd_file = strdup(SMPATH); - conf_files->botmotd_file = strdup(BPATH); - conf_files->opermotd_file = strdup(OPATH); - conf_files->svsmotd_file = strdup(VPATH); + safe_strdup(conf_files->motd_file, MPATH); + safe_strdup(conf_files->rules_file, RPATH); + safe_strdup(conf_files->smotd_file, SMPATH); + safe_strdup(conf_files->botmotd_file, BPATH); + safe_strdup(conf_files->opermotd_file, OPATH); + safe_strdup(conf_files->svsmotd_file, VPATH); - conf_files->pid_file = strdup(IRCD_PIDFILE); - conf_files->tune_file = strdup(IRCDTUNE); + safe_strdup(conf_files->pid_file, IRCD_PIDFILE); + safe_strdup(conf_files->tune_file, IRCDTUNE); /* we let actual files get read in later by the motd caching mechanism */ } @@ -3606,10 +3605,10 @@ OperClassACLEntry* _conf_parseACLEntry(ConfigEntry *ce) for (cep = ce->ce_entries; cep; cep = cep->ce_next) { OperClassACLEntryVar *var = safe_alloc(sizeof(OperClassACLEntryVar)); - var->name = strdup(cep->ce_varname); + safe_strdup(var->name, cep->ce_varname); if (cep->ce_vardata) { - var->value = strdup(cep->ce_vardata); + safe_strdup(var->value, cep->ce_vardata); } AddListItem(var,entry->variables); } @@ -3623,7 +3622,7 @@ OperClassACL* _conf_parseACL(char* name, ConfigEntry *ce) OperClassACL *acl = NULL; acl = safe_alloc(sizeof(OperClassACL)); - acl->name = strdup(name); + safe_strdup(acl->name, name); for (cep = ce->ce_entries; cep; cep = cep->ce_next) { @@ -3648,13 +3647,13 @@ int _conf_operclass(ConfigFile *conf, ConfigEntry *ce) ConfigItem_operclass *operClass = NULL; operClass = safe_alloc(sizeof(ConfigItem_operclass)); operClass->classStruct = safe_alloc(sizeof(OperClass)); - operClass->classStruct->name = strdup(ce->ce_vardata); + safe_strdup(operClass->classStruct->name, ce->ce_vardata); for (cep = ce->ce_entries; cep; cep = cep->ce_next) { if (!strcmp(cep->ce_varname, "parent")) { - operClass->classStruct->ISA = strdup(cep->ce_vardata); + safe_strdup(operClass->classStruct->ISA, cep->ce_vardata); } else if (!strcmp(cep->ce_varname, "permissions")) { @@ -3758,12 +3757,12 @@ int _conf_oper(ConfigFile *conf, ConfigEntry *ce) ConfigItem_oper *oper = NULL; oper = safe_alloc(sizeof(ConfigItem_oper)); - oper->name = strdup(ce->ce_vardata); + safe_strdup(oper->name, ce->ce_vardata); for (cep = ce->ce_entries; cep; cep = cep->ce_next) { if (!strcmp(cep->ce_varname, "operclass")) - oper->operclass = strdup(cep->ce_vardata); + safe_strdup(oper->operclass, cep->ce_vardata); if (!strcmp(cep->ce_varname, "password")) oper->auth = AuthBlockToAuthConfig(cep); else if (!strcmp(cep->ce_varname, "class")) @@ -3785,16 +3784,16 @@ int _conf_oper(ConfigFile *conf, ConfigEntry *ce) for (cepp = cep->ce_entries; cepp; cepp = cepp->ce_next) { s = safe_alloc(sizeof(SWhois)); - s->line = strdup(cepp->ce_varname); - s->setby = strdup("oper"); + safe_strdup(s->line, cepp->ce_varname); + safe_strdup(s->setby, "oper"); AddListItem(s, oper->swhois); } } else if (cep->ce_vardata) { s = safe_alloc(sizeof(SWhois)); - s->line = strdup(cep->ce_vardata); - s->setby = strdup("oper"); + safe_strdup(s->line, cep->ce_vardata); + safe_strdup(s->setby, "oper"); AddListItem(s, oper->swhois); } } @@ -4416,30 +4415,30 @@ int _conf_tld(ConfigFile *conf, ConfigEntry *ce) for (cep = ce->ce_entries; cep; cep = cep->ce_next) { if (!strcmp(cep->ce_varname, "mask")) - ca->mask = strdup(cep->ce_vardata); + safe_strdup(ca->mask, cep->ce_vardata); else if (!strcmp(cep->ce_varname, "motd")) { - ca->motd_file = strdup(cep->ce_vardata); + safe_strdup(ca->motd_file, cep->ce_vardata); read_motd(cep->ce_vardata, &ca->motd); } else if (!strcmp(cep->ce_varname, "shortmotd")) { - ca->smotd_file = strdup(cep->ce_vardata); + safe_strdup(ca->smotd_file, cep->ce_vardata); read_motd(cep->ce_vardata, &ca->smotd); } else if (!strcmp(cep->ce_varname, "opermotd")) { - ca->opermotd_file = strdup(cep->ce_vardata); + safe_strdup(ca->opermotd_file, cep->ce_vardata); read_motd(cep->ce_vardata, &ca->opermotd); } else if (!strcmp(cep->ce_varname, "botmotd")) { - ca->botmotd_file = strdup(cep->ce_vardata); + safe_strdup(ca->botmotd_file, cep->ce_vardata); read_motd(cep->ce_vardata, &ca->botmotd); } else if (!strcmp(cep->ce_varname, "rules")) { - ca->rules_file = strdup(cep->ce_vardata); + safe_strdup(ca->rules_file, cep->ce_vardata); read_motd(cep->ce_vardata, &ca->rules); } else if (!strcmp(cep->ce_varname, "options")) @@ -4454,7 +4453,7 @@ int _conf_tld(ConfigFile *conf, ConfigEntry *ce) } } else if (!strcmp(cep->ce_varname, "channel")) - ca->channel = strdup(cep->ce_vardata); + safe_strdup(ca->channel, cep->ce_vardata); } AddListItem(ca, conf_tld); return 1; @@ -4710,7 +4709,7 @@ int _conf_listen(ConfigFile *conf, ConfigEntry *ce) if (!(listen = Find_listen(ip, port, 0))) { listen = safe_alloc(sizeof(ConfigItem_listen)); - listen->ip = strdup(ip); + safe_strdup(listen->ip, ip); listen->port = port; listen->fd = -1; listen->ipv6 = 0; @@ -4754,7 +4753,7 @@ int _conf_listen(ConfigFile *conf, ConfigEntry *ce) if (!(listen = Find_listen(ip, port, 1))) { listen = safe_alloc(sizeof(ConfigItem_listen)); - listen->ip = strdup(ip); + safe_strdup(listen->ip, ip); listen->port = port; listen->fd = -1; listen->ipv6 = 1; @@ -5008,10 +5007,10 @@ int _conf_allow(ConfigFile *conf, ConfigEntry *ce) { if (!strcmp(cep->ce_varname, "ip")) { - allow->ip = strdup(cep->ce_vardata); + safe_strdup(allow->ip, cep->ce_vardata); } else if (!strcmp(cep->ce_varname, "hostname")) - allow->hostname = strdup(cep->ce_vardata); + safe_strdup(allow->hostname, cep->ce_vardata); else if (!strcmp(cep->ce_varname, "password")) allow->auth = AuthBlockToAuthConfig(cep); else if (!strcmp(cep->ce_varname, "class")) @@ -5029,7 +5028,7 @@ int _conf_allow(ConfigFile *conf, ConfigEntry *ce) else if (!strcmp(cep->ce_varname, "maxperip")) allow->maxperip = atoi(cep->ce_vardata); else if (!strcmp(cep->ce_varname, "redirect-server")) - allow->server = strdup(cep->ce_vardata); + safe_strdup(allow->server, cep->ce_vardata); else if (!strcmp(cep->ce_varname, "redirect-port")) allow->port = atoi(cep->ce_vardata); else if (!strcmp(cep->ce_varname, "ipv6-clone-mask")) @@ -5056,10 +5055,10 @@ int _conf_allow(ConfigFile *conf, ConfigEntry *ce) } if (!allow->hostname) - allow->hostname = strdup("*@NOMATCH"); + safe_strdup(allow->hostname, "*@NOMATCH"); if (!allow->ip) - allow->ip = strdup("*@NOMATCH"); + safe_strdup(allow->ip, "*@NOMATCH"); AddListItem(allow, conf_allow); return 1; @@ -5544,15 +5543,15 @@ int _conf_vhost(ConfigFile *conf, ConfigEntry *ce) user = strtok(cep->ce_vardata, "@"); host = strtok(NULL, ""); if (!host) - vhost->virthost = strdup(user); + safe_strdup(vhost->virthost, user); else { - vhost->virtuser = strdup(user); - vhost->virthost = strdup(host); + safe_strdup(vhost->virtuser, user); + safe_strdup(vhost->virthost, host); } } else if (!strcmp(cep->ce_varname, "login")) - vhost->login = strdup(cep->ce_vardata); + safe_strdup(vhost->login, cep->ce_vardata); else if (!strcmp(cep->ce_varname, "password")) vhost->auth = AuthBlockToAuthConfig(cep); else if (!strcmp(cep->ce_varname, "mask")) @@ -5567,16 +5566,16 @@ int _conf_vhost(ConfigFile *conf, ConfigEntry *ce) for (cepp = cep->ce_entries; cepp; cepp = cepp->ce_next) { s = safe_alloc(sizeof(SWhois)); - s->line = strdup(cepp->ce_varname); - s->setby = strdup("vhost"); + safe_strdup(s->line, cepp->ce_varname); + safe_strdup(s->setby, "vhost"); AddListItem(s, vhost->swhois); } } else if (cep->ce_vardata) { s = safe_alloc(sizeof(SWhois)); - s->line = strdup(cep->ce_vardata); - s->setby = strdup("vhost"); + safe_strdup(s->line, cep->ce_vardata); + safe_strdup(s->setby, "vhost"); AddListItem(s, vhost->swhois); } } @@ -5783,7 +5782,7 @@ int _conf_sni(ConfigFile *conf, ConfigEntry *ce) return 0; sni = safe_alloc(sizeof(ConfigItem_listen)); - sni->name = strdup(name); + safe_strdup(sni->name, name); sni->tls_options = safe_alloc(sizeof(TLSOptions)); conf_tlsblock(conf, tlsconfig, sni->tls_options); sni->ssl_ctx = init_ctx(sni->tls_options, 1); @@ -5802,12 +5801,12 @@ int _conf_help(ConfigFile *conf, ConfigEntry *ce) if (!ce->ce_vardata) ca->command = NULL; else - ca->command = strdup(ce->ce_vardata); + safe_strdup(ca->command, ce->ce_vardata); for (cep = ce->ce_entries; cep; cep = cep->ce_next) { temp = safe_alloc(sizeof(MOTDLine)); - temp->line = strdup(cep->ce_varname); + safe_strdup(temp->line, cep->ce_varname); temp->next = NULL; if (!last) ca->text = temp; @@ -5972,7 +5971,7 @@ int _conf_link(ConfigFile *conf, ConfigEntry *ce) NameValue *ofp; link = safe_alloc(sizeof(ConfigItem_link)); - link->servername = strdup(ce->ce_vardata); + safe_strdup(link->servername, ce->ce_vardata); for (cep = ce->ce_entries; cep; cep = cep->ce_next) { @@ -6052,7 +6051,7 @@ int _conf_link(ConfigFile *conf, ConfigEntry *ce) /* The default is 'hub *', unless you specify leaf or hub manually. */ if (!link->hub && !link->leaf) - link->hub = strdup("*"); + safe_strdup(link->hub, "*"); AddListItem(link, conf_link); return 0; @@ -6371,10 +6370,10 @@ int _conf_ban(ConfigFile *conf, ConfigEntry *ce) { if (!strcmp(cep->ce_varname, "mask")) { - ca->mask = strdup(cep->ce_vardata); + safe_strdup(ca->mask, cep->ce_vardata); } else if (!strcmp(cep->ce_varname, "reason")) - ca->reason = strdup(cep->ce_vardata); + safe_strdup(ca->reason, cep->ce_vardata); else if (!strcmp(cep->ce_varname, "action")) ca ->action = banact_stringtoval(cep->ce_vardata); } @@ -8793,7 +8792,7 @@ int _test_blacklist_module(ConfigFile *conf, ConfigEntry *ce) } m = safe_alloc(sizeof(ConfigItem_blacklist_module)); - m->name = strdup(ce->ce_vardata); + safe_strdup(m->name, ce->ce_vardata); AddListItem(m, conf_blacklist_module); return 0; @@ -8902,7 +8901,7 @@ int _conf_offchans(ConfigFile *conf, ConfigEntry *ce) for (cepp = cep->ce_entries; cepp; cepp = cepp->ce_next) { if (!strcmp(cepp->ce_varname, "topic")) - of->topic = strdup(cepp->ce_vardata); + safe_strdup(of->topic, cepp->ce_vardata); } AddListItem(of, conf_offchans); } diff --git a/src/conf_preprocessor.c b/src/conf_preprocessor.c index b4b054055..dd8282604 100644 --- a/src/conf_preprocessor.c +++ b/src/conf_preprocessor.c @@ -74,7 +74,7 @@ int evaluate_preprocessor_if(char *statement, char *filename, int linenumber, Co cc = safe_alloc(sizeof(ConditionalConfig)); cc->condition = IF_MODULE; cc->negative = negative; - cc->name = strdup(name); + safe_strdup(cc->name, name); *cc_out = cc; return PREPROCESSOR_IF; } else @@ -104,7 +104,7 @@ int evaluate_preprocessor_if(char *statement, char *filename, int linenumber, Co cc = safe_alloc(sizeof(ConditionalConfig)); cc->condition = IF_DEFINED; cc->negative = negative; - cc->name = strdup(name); + safe_strdup(cc->name, name); *cc_out = cc; return PREPROCESSOR_IF; } else @@ -168,8 +168,8 @@ int evaluate_preprocessor_if(char *statement, char *filename, int linenumber, Co cc = safe_alloc(sizeof(ConditionalConfig)); cc->condition = IF_VALUE; cc->negative = negative; - cc->name = strdup(name); - cc->opt = strdup(name2); + safe_strdup(cc->name, name); + safe_strdup(cc->opt, name2); *cc_out = cc; return PREPROCESSOR_IF; } @@ -216,8 +216,8 @@ int evaluate_preprocessor_define(char *statement, char *filename, int linenumber *name_terminator = '\0'; NameValueList *d = safe_alloc(sizeof(NameValueList)); - d->name = strdup(name); - d->value = strdup(value); + safe_strdup(d->name, name); + safe_strdup(d->value, value); AddListItem(d, config_defines); return PREPROCESSOR_DEFINE; } diff --git a/src/dns.c b/src/dns.c index df18ef4af..db7b24d92 100644 --- a/src/dns.c +++ b/src/dns.c @@ -240,7 +240,7 @@ void unrealdns_gethostbyname_link(char *name, ConfigItem_link *conf, int ipv4_on /* Create a request */ r = safe_alloc(sizeof(DNSReq)); r->linkblock = conf; - r->name = strdup(name); + safe_strdup(r->name, name); if (!DISABLE_IPV6 && !ipv4_only) { /* We try an IPv6 lookup first, and if that fails we try IPv4. */ @@ -277,7 +277,7 @@ char ipv6 = r->ipv6; newr = safe_alloc(sizeof(DNSReq)); newr->cptr = acptr; newr->ipv6 = ipv6; - newr->name = strdup(he->h_name); + safe_strdup(newr->name, he->h_name); unrealdns_addreqtolist(newr); ares_gethostbyname(resolver_channel, he->h_name, ipv6 ? AF_INET6 : AF_INET, unrealdns_cb_nametoip_verify, newr); @@ -414,7 +414,7 @@ void unrealdns_cb_nametoip_link(void *arg, int status, int timeouts, struct host /* Ok, since we got here, it seems things were actually succesfull */ /* Fill in [linkblockstruct]->ipnum */ - r->linkblock->connect_ip = strdup(ip); + safe_strdup(r->linkblock->connect_ip, ip); he2 = unreal_create_hostent(he->h_name, ip); switch ((n = connect_server(r->linkblock, r->cptr, he2))) @@ -467,8 +467,8 @@ static void unrealdns_addtocache(char *name, char *ip) /* Create record */ c = safe_alloc(sizeof(DNSCache)); - c->name = strdup(name); - c->ip = strdup(ip); + safe_strdup(c->name, name); + safe_strdup(c->ip, ip); c->expires = TStime() + DNSCACHE_TTL; /* Add to hash table */ @@ -578,7 +578,7 @@ struct hostent *he; /* Create a hostent structure (I HATE HOSTENTS) and return it.. */ he = safe_alloc(sizeof(struct hostent)); - he->h_name = strdup(name); + safe_strdup(he->h_name, name); if (strchr(ip, ':')) { /* IPv6 */ diff --git a/src/extra.c b/src/extra.c index 72aaf6b36..7eab525f6 100644 --- a/src/extra.c +++ b/src/extra.c @@ -101,8 +101,8 @@ void DCCdeny_add(char *filename, char *reason, int type, int type2) ConfigItem_deny_dcc *deny = NULL; deny = safe_alloc(sizeof(ConfigItem_deny_dcc)); - deny->filename = strdup(filename); - deny->reason = strdup(reason); + safe_strdup(deny->filename, filename); + safe_strdup(deny->reason, reason); deny->flag.type = type; deny->flag.type2 = type2; AddListItem(deny, conf_deny_dcc); @@ -111,10 +111,8 @@ void DCCdeny_add(char *filename, char *reason, int type, int type2) void DCCdeny_del(ConfigItem_deny_dcc *deny) { DelListItem(deny, conf_deny_dcc); - if (deny->filename) - safe_free(deny->filename); - if (deny->reason) - safe_free(deny->reason); + safe_free(deny->filename); + safe_free(deny->reason); safe_free(deny); } diff --git a/src/hash.c b/src/hash.c index fc2ec0e02..80f00acd2 100644 --- a/src/hash.c +++ b/src/hash.c @@ -977,7 +977,7 @@ void add_throttling_bucket(Client *acptr) n = safe_alloc(sizeof(struct ThrottlingBucket)); n->next = n->prev = NULL; - n->ip = strdup(acptr->ip); + safe_strdup(n->ip, acptr->ip); n->since = TStime(); n->count = 1; hash = hash_throttling(acptr->ip); diff --git a/src/ircd.c b/src/ircd.c index 846325e9c..151856532 100644 --- a/src/ircd.c +++ b/src/ircd.c @@ -1219,7 +1219,7 @@ int InitUnrealIRCd(int argc, char *argv[]) timeofday = time(NULL); me.local->lasttime = me.local->since = me.local->firsttime = me.serv->boottime = TStime(); me.serv->features.protocol = UnrealProtocol; - me.serv->features.software = strdup(version); + safe_strdup(me.serv->features.software, version); (void)add_to_client_hash_table(me.name, &me); (void)add_to_id_hash_table(me.id, &me); list_add(&me.client_node, &global_server_list); diff --git a/src/match.c b/src/match.c index 164ddf7bb..e642d46b8 100644 --- a/src/match.c +++ b/src/match.c @@ -391,7 +391,7 @@ Match *unreal_create_match(MatchType type, char *str, char **error) *errorbuf = '\0'; - m->str = strdup(str); + safe_strdup(m->str, str); m->type = type; if (m->type == MATCH_SIMPLE) diff --git a/src/misc.c b/src/misc.c index 073210e1e..28c90f798 100644 --- a/src/misc.c +++ b/src/misc.c @@ -1035,8 +1035,8 @@ int swhois_add(Client *acptr, char *tag, int priority, char *swhois, Client *fro return -1; /* exists */ s = safe_alloc(sizeof(SWhois)); - s->line = strdup(swhois); - s->setby = strdup(tag); + safe_strdup(s->line, swhois); + safe_strdup(s->setby, tag); s->priority = priority; AddListItemPrio(s, acptr->user->swhois, s->priority); @@ -1289,7 +1289,7 @@ void free_message_tags(MessageTag *m) MessageTag *duplicate_mtag(MessageTag *mtag) { MessageTag *m = safe_alloc(sizeof(MessageTag)); - m->name = strdup(mtag->name); + safe_strdup(m->name, mtag->name); safe_strdup(m->value, mtag->value); return m; } diff --git a/src/modules.c b/src/modules.c index 3ee9d10f4..9a72074d5 100644 --- a/src/modules.c +++ b/src/modules.c @@ -392,10 +392,10 @@ char *Module_Create(char *path_) return (NULL); } mod = (Module *)Module_make(mod_header, Mod); - mod->tmp_file = strdup(tmppath); + safe_strdup(mod->tmp_file, tmppath); mod->mod_sys_version = modsys_ver; mod->compiler_version = compiler_version ? *compiler_version : 0; - mod->relpath = strdup(relpath); + safe_strdup(mod->relpath, relpath); irc_dlsym(Mod, "Mod_Init", Mod_Init); if (!Mod_Init) diff --git a/src/modules/account-tag.c b/src/modules/account-tag.c index b21ed6bcb..2a729cae3 100644 --- a/src/modules/account-tag.c +++ b/src/modules/account-tag.c @@ -90,8 +90,8 @@ void mtag_add_account(Client *acptr, MessageTag *recv_mtags, MessageTag **mtag_l if (acptr && acptr->user && (*acptr->user->svid != '*') && !isdigit(*acptr->user->svid)) { m = safe_alloc(sizeof(MessageTag)); - m->name = strdup("account"); - m->value = strdup(acptr->user->svid); + safe_strdup(m->name, "account"); + safe_strdup(m->value, acptr->user->svid); AddListItem(m, *mtag_list); } diff --git a/src/modules/authprompt.c b/src/modules/authprompt.c index b99231973..0a56873c9 100644 --- a/src/modules/authprompt.c +++ b/src/modules/authprompt.c @@ -131,7 +131,7 @@ static void init_config(void) static void addmultiline(MultiLine **l, char *line) { MultiLine *m = safe_alloc(sizeof(MultiLine)); - m->line = strdup(line); + safe_strdup(m->line, line); append_ListItem((ListStruct *)m, (ListStruct **)l); } diff --git a/src/modules/away.c b/src/modules/away.c index 5a3299de6..18da4820e 100644 --- a/src/modules/away.c +++ b/src/modules/away.c @@ -148,7 +148,8 @@ CMD_FUNC(cmd_away) wasaway = 1; } - away = sptr->user->away = strdup(awy2); + safe_strdup(sptr->user->away, awy2); + away = sptr->user->away; if (MyConnect(sptr)) sendnumeric(sptr, RPL_NOWAWAY); diff --git a/src/modules/blacklist.c b/src/modules/blacklist.c index e9db9900a..913147a88 100644 --- a/src/modules/blacklist.c +++ b/src/modules/blacklist.c @@ -457,10 +457,10 @@ int blacklist_config_run(ConfigFile *cf, ConfigEntry *ce, int type) return 0; /* not interested */ d = safe_alloc(sizeof(Blacklist)); - d->name = strdup(ce->ce_vardata); + safe_strdup(d->name, ce->ce_vardata); /* set some defaults. TODO: use set::blacklist or something ? */ d->action = BAN_ACT_KILL; - d->reason = strdup("Your IP is on a DNS Blacklist"); + safe_strdup(d->reason, "Your IP is on a DNS Blacklist"); d->ban_time = 3600; /* assume dns for now ;) */ diff --git a/src/modules/certfp.c b/src/modules/certfp.c index 45d385f50..1a360e3ee 100644 --- a/src/modules/certfp.c +++ b/src/modules/certfp.c @@ -155,7 +155,5 @@ char *certfp_serialize(ModData *m) void certfp_unserialize(char *str, ModData *m) { - if (m->str) - safe_free(m->str); - m->str = strdup(str); + safe_strdup(m->str, str); } diff --git a/src/modules/channeldb.c b/src/modules/channeldb.c index ddecf6c2c..87b8182ff 100644 --- a/src/modules/channeldb.c +++ b/src/modules/channeldb.c @@ -431,10 +431,10 @@ int read_channeldb(void) /* If we got this far, we can create/initialize the channel with the above */ chptr = get_channel(&me, chname, CREATE); chptr->creationtime = creationtime; - chptr->topic = BadPtr(topic) ? NULL : strdup(topic); - chptr->topic_nick = BadPtr(topic_nick) ? NULL : strdup(topic_nick); + safe_strdup(chptr->topic, topic); + safe_strdup(chptr->topic_nick, topic_nick); chptr->topic_time = topic_time; - chptr->mode_lock = BadPtr(mode_lock) ? NULL : strdup(mode_lock); + safe_strdup(chptr->mode_lock, mode_lock); set_channel_mode(chptr, modes1, modes2); R_SAFE(read_listmode(fd, &chptr->banlist)); R_SAFE(read_listmode(fd, &chptr->exlist)); diff --git a/src/modules/charsys.c b/src/modules/charsys.c index f7bd2fd98..c92f34660 100644 --- a/src/modules/charsys.c +++ b/src/modules/charsys.c @@ -627,7 +627,7 @@ char tmp[512], *lang, *p; { /* Add... */ li = safe_alloc(sizeof(ILangList)); - li->name = strdup(lang); + safe_strdup(li->name, lang); AddListItem(li, ilanglist); } } diff --git a/src/modules/chghost.c b/src/modules/chghost.c index 5eb4f116b..5e3236865 100644 --- a/src/modules/chghost.c +++ b/src/modules/chghost.c @@ -144,14 +144,8 @@ CMD_FUNC(cmd_chghost) acptr->umodes |= UMODE_HIDE; acptr->umodes |= UMODE_SETHOST; - sendto_server(cptr, 0, 0, NULL, ":%s CHGHOST %s %s", - sptr->name, acptr->name, parv[2]); - if (acptr->user->virthost) - { - safe_free(acptr->user->virthost); - acptr->user->virthost = 0; - } - acptr->user->virthost = strdup(parv[2]); + sendto_server(cptr, 0, 0, NULL, ":%s CHGHOST %s %s", sptr->name, acptr->name, parv[2]); + safe_strdup(acptr->user->virthost, parv[2]); userhost_changed(acptr); diff --git a/src/modules/history_backend_mem.c b/src/modules/history_backend_mem.c index 52eed3c58..cfeb6542a 100644 --- a/src/modules/history_backend_mem.c +++ b/src/modules/history_backend_mem.c @@ -162,8 +162,8 @@ void hbm_duplicate_mtags(HistoryLogLine *l, MessageTag *m) (int)(t.tv_usec / 1000)); n = safe_alloc(sizeof(MessageTag)); - n->name = strdup("time"); - n->value = strdup(buf); + safe_strdup(n->name, "time"); + safe_strdup(n->value, buf); AddListItem(n, l->mtags); } /* Now convert the "time" message tag to something we can use in l->t */ diff --git a/src/modules/jumpserver.c b/src/modules/jumpserver.c index 8b8ba2571..2a70387c0 100644 --- a/src/modules/jumpserver.c +++ b/src/modules/jumpserver.c @@ -234,14 +234,14 @@ CMD_FUNC(cmd_jumpserver) jss = safe_alloc(sizeof(JSS)); /* Set it */ - jss->server = strdup(serv); + safe_strdup(jss->server, serv); jss->port = port; if (sslserv) { - jss->ssl_server = strdup(sslserv); + safe_strdup(jss->ssl_server, sslserv); jss->ssl_port = sslport; } - jss->reason = strdup(reason); + safe_strdup(jss->reason, reason); /* Broadcast/log */ if (sslserv) diff --git a/src/modules/list.c b/src/modules/list.c index 10ec0e911..87a140aa4 100644 --- a/src/modules/list.c +++ b/src/modules/list.c @@ -220,7 +220,7 @@ CMD_FUNC(cmd_list) lp = make_link(); lp->next = nolist; nolist = lp; - lp->value.cp = strdup(name + 1); + safe_strdup(lp->value.cp, name + 1); } else if (strchr(name, '*') || strchr(name, '?')) { @@ -228,7 +228,7 @@ CMD_FUNC(cmd_list) lp = make_link(); lp->next = yeslist; yeslist = lp; - lp->value.cp = strdup(name); + safe_strdup(lp->value.cp, name); } else /* Just a normal channel */ { diff --git a/src/modules/mdex.c b/src/modules/mdex.c index 2ab408424..6d06a4d20 100644 --- a/src/modules/mdex.c +++ b/src/modules/mdex.c @@ -301,8 +301,7 @@ CMD_FUNC(cmd_mdex) void mdex_free(ModData *m) { - if (m->str) - safe_free(m->str); + safe_free(m->str); } char *mdex_serialize(ModData *m) @@ -314,7 +313,5 @@ char *mdex_serialize(ModData *m) void mdex_unserialize(char *str, ModData *m) { - if (m->str) - safe_free(m->str); - m->str = strdup(str); + safe_strdup(m->str, str); } diff --git a/src/modules/message-ids.c b/src/modules/message-ids.c index 348a458f1..17b62519c 100644 --- a/src/modules/message-ids.c +++ b/src/modules/message-ids.c @@ -104,7 +104,7 @@ int msgid_mtag_is_ok(Client *acptr, char *name, char *value) MessageTag *mtag_generate_msgid(void) { MessageTag *m = safe_alloc(sizeof(MessageTag)); - m->name = strdup("msgid"); + safe_strdup(m->name, "msgid"); m->value = safe_alloc(MSGIDLEN+1); gen_random_alnum(m->value, MSGIDLEN); return m; diff --git a/src/modules/message-tags.c b/src/modules/message-tags.c index a4cb8d80d..6e18ac69d 100644 --- a/src/modules/message-tags.c +++ b/src/modules/message-tags.c @@ -198,8 +198,12 @@ void _parse_message_tags(Client *cptr, char **str, MessageTag **mtag_list) if (message_tag_ok(cptr, name, value)) { m = safe_alloc(sizeof(MessageTag)); - m->name = strdup(name); - m->value = BadPtr(value) ? NULL : strdup(value); + safe_strdup(m->name, name); + /* Both NULL and empty become NULL: */ + if (BadPtr(value)) + m->value = NULL; + else /* a real value... */ + safe_strdup(m->value, value); AddListItem(m, *mtag_list); } } diff --git a/src/modules/mode.c b/src/modules/mode.c index 4bff953ec..a81b95184 100644 --- a/src/modules/mode.c +++ b/src/modules/mode.c @@ -1812,8 +1812,7 @@ CMD_FUNC(_cmd_umode) sptr->name, sptr->user->virthost); /* Set the vhost */ - safe_free(sptr->user->virthost); - sptr->user->virthost = strdup(sptr->user->cloakedhost); + safe_strdup(sptr->user->virthost, sptr->user->cloakedhost); /* Notify */ userhost_changed(sptr); @@ -1828,8 +1827,7 @@ CMD_FUNC(_cmd_umode) * for ban-checking... free+recreate here because it could have * been a vhost for example. -- Syzop */ - safe_free(sptr->user->virthost); - sptr->user->virthost = strdup(sptr->user->cloakedhost); + safe_strdup(sptr->user->virthost, sptr->user->cloakedhost); /* Notify */ userhost_changed(sptr); diff --git a/src/modules/nick.c b/src/modules/nick.c index 3f877effd..236749a48 100644 --- a/src/modules/nick.c +++ b/src/modules/nick.c @@ -1367,7 +1367,7 @@ int _register_user(Client *cptr, Client *sptr, char *nick, char *username, char sptr->srvptr->serv->users++; make_virthost(sptr, user->realhost, user->cloakedhost, 0); - user->virthost = strdup(user->cloakedhost); + safe_strdup(user->virthost, user->cloakedhost); if (MyConnect(sptr)) { @@ -1506,7 +1506,7 @@ int _register_user(Client *cptr, Client *sptr, char *nick, char *username, char sptr->name, ip); return exit_client(sptr, sptr, &me, NULL, "USER with invalid IP"); } - sptr->ip = strdup(ipstring); + safe_strdup(sptr->ip, ipstring); } /* For remote clients we recalculate the cloakedhost here because diff --git a/src/modules/oper.c b/src/modules/oper.c index cfeabc681..d11e2ecec 100644 --- a/src/modules/oper.c +++ b/src/modules/oper.c @@ -224,8 +224,7 @@ CMD_FUNC(cmd_oper) /* /OPER really succeeded now. Start processing it. */ /* Store which oper block was used to become IRCOp (for maxlogins and whois) */ - safe_free(sptr->user->operlogin); - sptr->user->operlogin = strdup(operblock->name); + safe_strdup(sptr->user->operlogin, operblock->name); /* Put in the right class */ if (sptr->local->class) @@ -256,7 +255,7 @@ CMD_FUNC(cmd_oper) if (IsHidden(sptr) && !sptr->user->virthost) { /* +x has just been set by modes-on-oper and no vhost. cloak the oper! */ - sptr->user->virthost = strdup(sptr->user->cloakedhost); + safe_strdup(sptr->user->virthost, sptr->user->cloakedhost); } sendto_snomask_global(SNO_OPER, diff --git a/src/modules/protoctl.c b/src/modules/protoctl.c index d864fc2fc..ace9d97ba 100644 --- a/src/modules/protoctl.c +++ b/src/modules/protoctl.c @@ -271,7 +271,7 @@ CMD_FUNC(cmd_protoctl) if (protocol) cptr->serv->features.protocol = atoi(protocol); if (software) - cptr->serv->features.software = strdup(software); + safe_strdup(cptr->serv->features.software, software); if (!IsHandshake(cptr) && aconf) /* Send PASS early... */ sendto_one(sptr, NULL, "PASS :%s", (aconf->auth->type == AUTHTYPE_PLAINTEXT) ? aconf->auth->data : "*"); } diff --git a/src/modules/restrict-commands.c b/src/modules/restrict-commands.c index dad402f33..445cc09cd 100644 --- a/src/modules/restrict-commands.c +++ b/src/modules/restrict-commands.c @@ -257,8 +257,8 @@ int rcmd_configrun(ConfigFile *cf, ConfigEntry *ce, int type) } rcmd = safe_alloc(sizeof(RestrictedCommand)); - rcmd->cmd = strdup(cmd); - rcmd->conftag = (conftag ? strdup(conftag) : NULL); + safe_strdup(rcmd->cmd, cmd); + safe_strdup(rcmd->conftag, conftag); for (cep2 = cep->ce_entries; cep2; cep2 = cep2->ce_next) { if (!cep2->ce_vardata) diff --git a/src/modules/sasl.c b/src/modules/sasl.c index 18b7bca02..3c4beae3b 100644 --- a/src/modules/sasl.c +++ b/src/modules/sasl.c @@ -446,8 +446,7 @@ MOD_UNLOAD() void saslmechlist_free(ModData *m) { - if (m->str) - safe_free(m->str); + safe_free(m->str); } char *saslmechlist_serialize(ModData *m) @@ -459,9 +458,7 @@ char *saslmechlist_serialize(ModData *m) void saslmechlist_unserialize(char *str, ModData *m) { - if (m->str) - safe_free(m->str); - m->str = strdup(str); + safe_strdup(m->str, str); } char *sasl_capability_parameter(Client *acptr) diff --git a/src/modules/server-time.c b/src/modules/server-time.c index 9756f2933..a33efbcce 100644 --- a/src/modules/server-time.c +++ b/src/modules/server-time.c @@ -109,8 +109,8 @@ void mtag_add_or_inherit_time(Client *sender, MessageTag *recv_mtags, MessageTag (int)(t.tv_usec / 1000)); m = safe_alloc(sizeof(MessageTag)); - m->name = strdup("time"); - m->value = strdup(buf); + safe_strdup(m->name, "time"); + safe_strdup(m->value, buf); } AddListItem(m, *mtag_list); } diff --git a/src/modules/sethost.c b/src/modules/sethost.c index 652ed186f..c3858ff70 100644 --- a/src/modules/sethost.c +++ b/src/modules/sethost.c @@ -134,12 +134,7 @@ CMD_FUNC(cmd_sethost) sptr->umodes |= UMODE_HIDE; sptr->umodes |= UMODE_SETHOST; /* get it in */ - if (sptr->user->virthost) - { - safe_free(sptr->user->virthost); - sptr->user->virthost = NULL; - } - sptr->user->virthost = strdup(vhost); + safe_strdup(sptr->user->virthost, vhost); /* spread it out */ sendto_server(cptr, 0, 0, NULL, ":%s SETHOST %s", sptr->name, parv[1]); diff --git a/src/modules/svsmode.c b/src/modules/svsmode.c index 8ac0de80f..d3b2eae11 100644 --- a/src/modules/svsmode.c +++ b/src/modules/svsmode.c @@ -427,8 +427,7 @@ int do_svsmode(Client *cptr, Client *sptr, MessageTag *recv_mtags, int parc, cha if (acptr->user->virthost) { /* Removing mode +x and virthost set... recalculate host then (but don't activate it!) */ - safe_free(acptr->user->virthost); - acptr->user->virthost = strdup(acptr->user->cloakedhost); + safe_strdup(acptr->user->virthost, acptr->user->cloakedhost); } } else { @@ -438,7 +437,7 @@ int do_svsmode(Client *cptr, Client *sptr, MessageTag *recv_mtags, int parc, cha /* Hmm... +x but no virthost set, that's bad... use cloakedhost. * Not sure if this could ever happen, but just in case... -- Syzop */ - acptr->user->virthost = strdup(acptr->user->cloakedhost); + safe_strdup(acptr->user->virthost, acptr->user->cloakedhost); } /* Announce the new host to VHP servers if we're setting the virthost to the cloakedhost. * In other cases, we can assume that the host has been broadcasted already (after all, diff --git a/src/modules/svsnline.c b/src/modules/svsnline.c index 65d636de1..0a33a7d72 100644 --- a/src/modules/svsnline.c +++ b/src/modules/svsnline.c @@ -103,8 +103,8 @@ CMD_FUNC(cmd_svsnline) { bconf = safe_alloc(sizeof(ConfigItem_ban)); bconf->flag.type = CONF_BAN_REALNAME; - bconf->mask = strdup(parv[3]); - bconf->reason = strdup(parv[2]); + safe_strdup(bconf->mask, parv[3]); + safe_strdup(bconf->reason, parv[2]); for (s = bconf->reason; *s; s++) if (*s == '_') *s = ' '; diff --git a/src/modules/webirc.c b/src/modules/webirc.c index f49f539b0..28628e046 100644 --- a/src/modules/webirc.c +++ b/src/modules/webirc.c @@ -357,8 +357,7 @@ int dowebirc(Client *cptr, char *ip, char *host, char *options) } /* STEP 2: Update GetIP() */ - safe_free(cptr->ip); - cptr->ip = strdup(ip); + safe_strdup(cptr->ip, ip); /* STEP 3: Update cptr->local->hostp */ /* (free old) */ diff --git a/src/modules/websocket.c b/src/modules/websocket.c index 000dc4784..a68272914 100644 --- a/src/modules/websocket.c +++ b/src/modules/websocket.c @@ -395,8 +395,7 @@ int websocket_handle_handshake(Client *sptr, char *readbuf, int *length) if (lastloc) { /* Last line was cut somewhere, save it for next round. */ - safe_free(WSU(sptr)->lefttoparse); - WSU(sptr)->lefttoparse = strdup(lastloc); + safe_strdup(WSU(sptr)->lefttoparse, lastloc); } return 0; /* don't let UnrealIRCd process this */ } diff --git a/src/operclass.c b/src/operclass.c index 6c775fc05..93b5f8891 100644 --- a/src/operclass.c +++ b/src/operclass.c @@ -55,7 +55,7 @@ OperClassValidator* OperClassAddValidator(Module *module, char* pathStr, OperCla if (!nextNode) { nextNode = safe_alloc(sizeof(OperClassPathNode)); - nextNode->identifier = strdup(path->identifier); + safe_strdup(nextNode->identifier, path->identifier); AddListItem(nextNode,node->children); } node = nextNode; @@ -120,7 +120,7 @@ OperClassACLPath* OperClass_parsePath(char* path) while (str) { tmpPath = safe_alloc(sizeof(OperClassACLPath)); - tmpPath->identifier = strdup(str); + safe_strdup(tmpPath->identifier, str); AddListItem(tmpPath,pathHead); str = strtok(NULL,":"); } diff --git a/src/packet.c b/src/packet.c index 5830e66cb..a82066409 100644 --- a/src/packet.c +++ b/src/packet.c @@ -98,7 +98,7 @@ RealCommand *add_Command_backend(char *cmd) { RealCommand *c = safe_alloc(sizeof(RealCommand)); - c->cmd = strdup(cmd); + safe_strdup(c->cmd, cmd); /* Add in hash with hash value = first byte */ AddListItem(c, CommandHash[toupper(*cmd)]); diff --git a/src/send.c b/src/send.c index a3b0db1d2..defd10a0a 100644 --- a/src/send.c +++ b/src/send.c @@ -68,7 +68,7 @@ int dead_link(Client *to, char *notice) sendto_ops_and_log("Link to server %s (%s) closed: %s", to->name, to->ip?to->ip:"", notice); Debug((DEBUG_ERROR, "dead_link: %s - %s", notice, get_client_name(to, FALSE))); - to->local->error_str = strdup(notice); + safe_strdup(to->local->error_str, notice); return -1; } diff --git a/src/serv.c b/src/serv.c index e83f6e82c..93a5695f0 100644 --- a/src/serv.c +++ b/src/serv.c @@ -1034,7 +1034,7 @@ void do_read_motd(const char *filename, MOTDFile *themotd) line[510] = '\0'; temp = safe_alloc(sizeof(MOTDLine)); - temp->line = strdup(line); + safe_strdup(temp->line, line); if(last) last->next = temp; diff --git a/src/tls.c b/src/tls.c index de64657e2..e0e12e23c 100644 --- a/src/tls.c +++ b/src/tls.c @@ -922,10 +922,10 @@ static int fatal_ssl_error(int ssl_error, int where, int my_errno, Client *sptr) if (errtmp) { SET_ERRNO(errtmp); - sptr->local->error_str = strdup(strerror(errtmp)); + safe_strdup(sptr->local->error_str, strerror(errtmp)); } else { SET_ERRNO(P_EIO); - sptr->local->error_str = strdup(ssl_errstr); + safe_strdup(sptr->local->error_str, ssl_errstr); } /* deregister I/O notification since we don't care anymore. the actual closing of socket will happen later. */ diff --git a/src/updconf.c b/src/updconf.c index e8ba1e4a8..664911280 100644 --- a/src/updconf.c +++ b/src/updconf.c @@ -1598,7 +1598,7 @@ static void add_include_list(char *fname, ConfigFile **cf) ConfigFile *n = safe_alloc(sizeof(ConfigFile)); // config_status("INCLUDE: %s", fname); - n->cf_filename = strdup(fname); + safe_strdup(n->cf_filename, fname); n->cf_next = *cf; *cf = n; } diff --git a/src/url.c b/src/url.c index 60e2ec123..dc5b29b90 100644 --- a/src/url.c +++ b/src/url.c @@ -413,18 +413,16 @@ void download_file_async(const char *url, time_t cachetime, vFP callback, void * { snprintf(errorbuf, sizeof(errorbuf), "Cannot create '%s': %s", tmp, strerror(ERRNO)); callback(url, NULL, errorbuf, 0, callback_data); - if (file) - safe_free(file); + safe_free(file); safe_free(handle); return; } handle->callback = callback; handle->callback_data = callback_data; handle->cachetime = cachetime; - handle->url = strdup(url); + safe_strdup(handle->url, url); strlcpy(handle->filename, tmp, sizeof(handle->filename)); - if (file) - free(file); + safe_free(file); curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, do_download); diff --git a/src/user.c b/src/user.c index 50d948fcb..73eb62e0b 100644 --- a/src/user.c +++ b/src/user.c @@ -45,12 +45,7 @@ void iNAH_host(Client *sptr, char *host) userhost_save_current(sptr); - if (sptr->user->virthost) - { - safe_free(sptr->user->virthost); - sptr->user->virthost = NULL; - } - sptr->user->virthost = strdup(host); + safe_strdup(sptr->user->virthost, host); if (MyConnect(sptr)) sendto_server(&me, 0, 0, NULL, ":%s SETHOST :%s", sptr->name, sptr->user->virthost); sptr->umodes |= UMODE_SETHOST; @@ -564,7 +559,7 @@ int add_silence(Client *sptr, char *mask, int senderr) lp = make_link(); memset(lp, 0, sizeof(Link)); lp->next = sptr->user->silence; - lp->value.cp = strdup(mask); + safe_strdup(lp->value.cp, mask); sptr->user->silence = lp; return 0; } @@ -630,7 +625,7 @@ void setmaxtargets(char *cmd, int limit) *o++ = toupper(*i); *o = '\0'; m = safe_alloc(sizeof(MaxTarget)); - m->cmd = strdup(cmdupper); + safe_strdup(m->cmd, cmdupper); maxtarget_add_sorted(m); } m->limit = limit; diff --git a/src/whowas.c b/src/whowas.c index 4bc237ce7..fc63ed42e 100644 --- a/src/whowas.c +++ b/src/whowas.c @@ -56,15 +56,15 @@ void add_history(Client *cptr, int online) new->hashv = hash_whowas_name(cptr->name); new->logoff = TStime(); new->umodes = cptr->umodes; - new->name = strdup(cptr->name); - new->username = strdup(cptr->user->username); - new->hostname = strdup(cptr->user->realhost); + safe_strdup(new->name, cptr->name); + safe_strdup(new->username, cptr->user->username); + safe_strdup(new->hostname, cptr->user->realhost); if (cptr->user->virthost) - new->virthost = strdup(cptr->user->virthost); + safe_strdup(new->virthost, cptr->user->virthost); else - new->virthost = strdup(""); + safe_strdup(new->virthost, ""); new->servername = cptr->user->server; - new->realname = strdup(cptr->info); + safe_strdup(new->realname, cptr->info); /* Its not string copied, a pointer to the scache hash is copied -Dianora diff --git a/src/windows/rtf.c b/src/windows/rtf.c index 7e5f13ce9..98df22bbf 100644 --- a/src/windows/rtf.c +++ b/src/windows/rtf.c @@ -101,7 +101,7 @@ DWORD CALLBACK BufferIt(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb) void ColorPush(unsigned char *color, IRCColor **stack) { IRCColor *t = safe_alloc(sizeof(IRCColor)); - t->color = strdup(color); + safe_strdup(t->color, color); t->next = *stack; (*stack) = t; }