Jelajahi Sumber

* Implemented strdup()
Will setup a compat function in the future...


svn: 591

Bryan Drewery 22 tahun lalu
induk
melakukan
39d0b57cd0

+ 1 - 2
src/auth.c

@@ -75,8 +75,7 @@ char *makehash(struct userrec *u, char *rand)
 {
   char hash[256], *secpass = NULL;
   if (get_user(&USERENTRY_SECPASS, u)) {
-    secpass = malloc(strlen(get_user(&USERENTRY_SECPASS, u)) + 1);
-    strcpy(secpass, (char *) get_user(&USERENTRY_SECPASS, u));
+    secpass = strdup(get_user(&USERENTRY_SECPASS, u));
     secpass[strlen(secpass)] = 0;
   }
   sprintf(hash, "%s%s%s", rand, (secpass && secpass[0]) ? secpass : "" , (authkey && authkey[0]) ? authkey : "");

+ 4 - 8
src/botnet.c

@@ -142,8 +142,7 @@ int addparty(char *bot, char *nick, int chan, char flag, int sock,
 	party[i].flag = flag;
 	if (party[i].from)
 	  free(party[i].from);
-	party[i].from = malloc(strlen(from) + 1);
-	strcpy(party[i].from, from);
+        party[i].from = strdup(from);
       }
       *idx = i;
       return oldchan;
@@ -167,12 +166,10 @@ int addparty(char *bot, char *nick, int chan, char flag, int sock,
     if (flag == ' ')
       flag = '-';
     party[parties].flag = flag;
-    party[parties].from = malloc(strlen(from) + 1);
-    strcpy(party[parties].from, from);
+    party[parties].from = strdup(from);
   } else {
     party[parties].flag = ' ';
-    party[parties].from = malloc(10);
-    strcpy(party[parties].from, "(unknown)");
+    party[parties].from = strdup("(unknown)");
   }
   *idx = parties;
   parties++;
@@ -270,8 +267,7 @@ void partyaway(char *bot, int sock, char *msg)
       if (party[i].away)
 	free(party[i].away);
       if (msg[0]) {
-	party[i].away = malloc(strlen(msg) + 1);
-	strcpy(party[i].away, msg);
+        party[i].away = strdup(msg);
       } else
 	party[i].away = 0;
     }

+ 2 - 4
src/chanprog.c

@@ -454,8 +454,7 @@ void load_internal_users()
 	if (!get_user_by_handle(userlist, hand)) {
 	  userlist = adduser(userlist, hand, "none", "-", USER_BOT | USER_OP);
 	  bi = malloc(sizeof(struct bot_addr));
-	  bi->address = malloc(strlen(ip) + 1);
-	  strcpy(bi->address, ip);
+          bi->address = strdup(ip);
 	  bi->telnet_port = atoi(port) ? atoi(port) : 0;
 	  bi->relay_port = bi->telnet_port;
           bi->hublevel = hublevel;
@@ -584,8 +583,7 @@ void chanprog()
     u = get_user_by_handle(userlist, botnetnick);
     bi = malloc(sizeof(struct bot_addr));
 
-    bi->address = malloc(strlen(myip) + 1);
-    strcpy(bi->address, myip);
+    bi->address = strdup(myip);
     bi->telnet_port = atoi(buf) ? atoi(buf) : 3333;
     bi->relay_port = bi->telnet_port;
 #ifdef HUB

+ 9 - 15
src/cmds.c

@@ -1592,10 +1592,8 @@ static void cmd_hublevel(struct userrec *u, int idx, char *par)
   obi = get_user(&USERENTRY_BOTADDR, u1);
   bi = malloc(sizeof(struct bot_addr));
 
-  bi->uplink = malloc(strlen(obi->uplink) + 1);
-  strcpy(bi->uplink, obi->uplink);
-  bi->address = malloc(strlen(obi->address) + 1);
-  strcpy(bi->address, obi->address);
+  bi->uplink = strdup(obi->uplink);
+  bi->address = strdup(obi->address);
   bi->telnet_port = obi->telnet_port;
   bi->relay_port = obi->relay_port;
   bi->hublevel = atoi(level);
@@ -1632,10 +1630,8 @@ static void cmd_uplink(struct userrec *u, int idx, char *par)
   obi = get_user(&USERENTRY_BOTADDR, u1);
   bi = malloc(sizeof(struct bot_addr));
 
-  bi->uplink = malloc(strlen(uplink) + 1);
-  strcpy(bi->uplink, uplink);
-  bi->address = malloc(strlen(obi->address) + 1);
-  strcpy(bi->address, obi->address);
+  bi->uplink = strdup(uplink);
+  bi->address = strdup(obi->address);
   bi->telnet_port = obi->telnet_port;
   bi->relay_port = obi->relay_port;
   bi->hublevel = obi->hublevel;
@@ -1686,14 +1682,12 @@ static void cmd_chaddr(struct userrec *u, int idx, char *par)
 
   bi = malloc(sizeof(struct bot_addr));
 
-  bi->uplink = malloc(strlen(obi->uplink) + 1);
-  strcpy(bi->uplink, obi->uplink);
+  bi->uplink = strdup(obi->uplink);
   bi->hublevel = obi->hublevel;
 
   q = strchr(addr, ':');
   if (!q) {
-    bi->address = malloc(strlen(addr) + 1);
-    strcpy(bi->address, addr);
+    bi->address = strdup(addr);
     bi->telnet_port = telnet_port;
     bi->relay_port = relay_port;
   } else {
@@ -3688,10 +3682,10 @@ void crontab_show(struct userrec * u, int idx) {
 }
 
 void crontab_del() {
-  char * tmpfile, *p, buf[2048];
-  tmpfile=malloc(strlen(binname)+100);
+  char *tmpfile, *p, buf[2048];
+  tmpfile = malloc(strlen(binname) + 100);
   strcpy(tmpfile, binname);
-  if (!(p=strrchr(tmpfile, '/')))
+  if (!(p = strrchr(tmpfile, '/')))
     return;
   p++;
   strcpy(p, STR(".ctb"));

+ 5 - 10
src/config.c

@@ -601,8 +601,7 @@ void set_cfg_str(char *target, char *entryname, char *data)
 
     if (u && !strcmp(botnetnick, u->handle)) {
       if (data) {
-        entry->ldata = malloc(strlen(data) + 1);
-        strcpy(entry->ldata, data);
+        entry->ldata = strdup(data);
       } else
         entry->ldata = NULL;
       if (entry->localchanged) {
@@ -620,11 +619,9 @@ void set_cfg_str(char *target, char *entryname, char *data)
     }
     xk = malloc(sizeof(struct xtra_key));
     egg_bzero(xk, sizeof(struct xtra_key));
-    xk->key = malloc(strlen(entry->name) + 1);
-    strcpy(xk->key, entry->name);
+    xk->key = strdup(entry->name);
     if (data) {
-      xk->data = malloc(strlen(data) + 1);
-      strcpy(xk->data, data);
+      xk->data = strdup(data);
     }
     set_user(&USERENTRY_CONFIG, u, xk);
     if (olddata)
@@ -633,8 +630,7 @@ void set_cfg_str(char *target, char *entryname, char *data)
     char *olddata = entry->gdata;
 
     if (data) {
-      entry->gdata = malloc(strlen(data) + 1);
-      strcpy(entry->gdata, data);
+      entry->gdata = strdup(data);
     } else
       entry->gdata = NULL;
     if (entry->globalchanged) {
@@ -772,8 +768,7 @@ void set_cmd_pass(char *ln, int shareit)
     cp = malloc(sizeof(struct cmd_pass));
     cp->next = cmdpass;
     cmdpass = cp;
-    cp->name = malloc(strlen(cmd) + 1);
-    strcpy(cp->name, cmd);
+    cp->name = strdup(cmd);
     strcpy(cp->pass, ln);
     if (shareit)
       botnet_send_cmdpass(-1, cp->name, cp->pass);

+ 1 - 2
src/dccutil.c

@@ -442,8 +442,7 @@ void set_away(int idx, char *s)
   }
   if (dcc[idx].u.chat->away != NULL)
     free(dcc[idx].u.chat->away);
-  dcc[idx].u.chat->away = (char *) malloc(strlen(s) + 1);
-  strcpy(dcc[idx].u.chat->away, s);
+  dcc[idx].u.chat->away = strdup(s);
   if (dcc[idx].u.chat->channel >= 0) {
     chanout_but(-1, dcc[idx].u.chat->channel,
 		"*** %s is now away: %s\n", dcc[idx].nick, s);

+ 1 - 2
src/dns.c

@@ -154,8 +154,7 @@ void dcc_dnsipbyhost(char *hostn)
 
   de->type = &DNS_DCCEVENT_IPBYHOST;
   de->lookup = RES_IPBYHOST;
-  de->res_data.hostname = malloc(strlen(hostn) + 1);
-  strcpy(de->res_data.hostname, hostn);
+  de->res_data.hostname = strdup(hostn);
 
   /* Send request. */
   dns_ipbyhost(hostn);

+ 1 - 2
src/makesettings.c

@@ -397,8 +397,7 @@ int checkconfig()
 char *pscloak (int n)
 {
   int i = 0;
-  char *ps = malloc(strlen(cfg.pscloak) + 1), *p = NULL;
-  strcpy(ps, cfg.pscloak);
+  char *ps = strdup(cfg.pscloak), *p = NULL;
 
   for (i = 0; i < n; i++)
     p = newsplit(&ps);

+ 9 - 12
src/misc.c

@@ -461,8 +461,8 @@ void show_motd(int idx)
     char *who, *buf, date[50];
     time_t time;
     void *buf_ptr;
-    buf = buf_ptr = malloc(strlen((char *) CFG_MOTD.gdata) + 1);
-    strcpy(buf, (char *) CFG_MOTD.gdata);
+
+    buf = buf_ptr = strdup((char *) CFG_MOTD.gdata);
     who = newsplit(&buf);
     time = atoi(newsplit(&buf));
 #ifdef S_UTCTIME
@@ -1294,7 +1294,7 @@ void updatelocal(void)
   exit(0);
 }
 
-int updatebin (int idx, char *par, int autoi)
+int updatebin(int idx, char *par, int autoi)
 {
   char *path = NULL,
    *newbin;
@@ -1313,7 +1313,7 @@ int updatebin (int idx, char *par, int autoi)
       dprintf(idx, STR("Not enough parameters.\n"));
     return 1;
   }
-  path = malloc(strlen(binname) + strlen(par));
+  path = malloc(strlen(binname) + strlen(par) + 2);
   strcpy(path, binname);
   newbin = strrchr(path, '/');
   if (!newbin) {
@@ -1817,8 +1817,7 @@ char *getfullbinname(char *argv0)
 {
   char *cwd, *bin, *p, *p2;
 
-  bin = malloc(strlen(argv0) + 1);
-  strcpy(bin, argv0);
+  bin = strdup(argv0);
   if (bin[0] == '/') {
     return bin;
   }
@@ -1846,8 +1845,7 @@ char *getfullbinname(char *argv0)
       p2 = strchr(p, '/');
   }
   free(bin);
-  bin = malloc(strlen(cwd) + 1);
-  strcpy(bin, cwd);
+  bin = strdup(cwd);
   free(cwd);
   return bin;
 }
@@ -2113,8 +2111,7 @@ void shuffle(char *string, char *delim)
   char *array[501], *str, *work;
   int len = 0, i = 0;
 
-  work = malloc(strlen(string) + 1);
-  strcpy(work, string);
+  work = strdup(string);
 
   str = strtok(work, delim);
   while(str && *str)
@@ -2302,8 +2299,8 @@ char *confdir()
 #endif /* LEAF */
 #ifdef HUB
     {
-      char *buf = malloc(strlen(binname) + 1);
-      strcpy(buf, binname);
+      char *buf = strdup(binname);
+
       egg_snprintf(confdir, sizeof confdir, "%s", dirname(buf));
       free(buf);
     }

+ 1 - 2
src/mod/channels.mod/cmdschan.c

@@ -1796,8 +1796,7 @@ static void cmd_chanset(struct userrec *u, int idx, char *par)
 	/* Par gets modified in tcl channel_modify under some
   	 * circumstances, so save it now.
 	 */
-	parcpy = malloc(strlen(par) + 1);
-	strcpy(parcpy, par);
+        parcpy = strdup(par);
         if (tcl_channel_modify(0, chan, 2, list) == TCL_OK) {
 	  strcat(answers, list[0]);
 	  strcat(answers, " { ");

+ 1 - 2
src/mod/channels.mod/tclchan.c

@@ -1044,8 +1044,7 @@ static int tcl_renudef STDVAR
   for (ul = udef; ul; ul = ul->next) {
     if (ul->type == type && !egg_strcasecmp(ul->name, argv[2])) {
       free(ul->name);
-      ul->name = malloc(strlen(argv[3]) + 1);
-      strcpy(ul->name, argv[3]);
+      ul->name = strdup(argv[3]);
       found = 1;
     }
   }

+ 2 - 4
src/mod/channels.mod/udefchan.c

@@ -42,8 +42,7 @@ static void setudef(struct udef_struct *us, char *name, int value)
     }
 
   ul = malloc(sizeof(struct udef_chans));
-  ul->chan = malloc(strlen(name) + 1);
-  strcpy(ul->chan, name);
+  ul->chan = strdup(name);
   ul->value = value;
   ul->next = NULL;
   if (ul_last)
@@ -69,8 +68,7 @@ static void initudef(int type, char *name, int defined)
 
   debug2("Creating %s (type %d)", name, type);
   ul = malloc(sizeof(struct udef_struct));
-  ul->name = malloc(strlen(name) + 1);
-  strcpy(ul->name, name);
+  ul->name = strdup(name);
   if (defined)
     ul->defined = 1;
   else

+ 11 - 22
src/mod/channels.mod/userchan.c

@@ -94,8 +94,7 @@ static void set_handle_chaninfo(struct userrec *bu, char *handle,
   if (ch->info != NULL)
     free(ch->info);
   if (info && info[0]) {
-    ch->info = (char *) malloc(strlen(info) + 1);
-    strcpy(ch->info, info);
+    ch->info = strdup(info);
   } else
     ch->info = NULL;
   cst = findchan_by_dname(chname);
@@ -259,8 +258,7 @@ static int u_delban(struct chanset_t *c, char *who, int doit)
     }
     if (lastdeletedmask)
       free(lastdeletedmask);
-    lastdeletedmask = malloc(strlen((*u)->mask) + 1);
-    strcpy(lastdeletedmask, (*u)->mask);
+    lastdeletedmask = strdup((*u)->mask);
     free((*u)->mask);
     if ((*u)->desc)
       free((*u)->desc);
@@ -438,12 +436,9 @@ static int u_addban(struct chanset_t *chan, char *ban, char *from, char *note,
   p->added = now;
   p->lastactive = 0;
   p->flags = flags;
-  p->mask = malloc(strlen(host) + 1);
-  strcpy(p->mask, host);
-  p->user = malloc(strlen(from) + 1);
-  strcpy(p->user, from);
-  p->desc = malloc(strlen(note) + 1);
-  strcpy(p->desc, note);
+  p->mask = strdup(host);
+  p->user = strdup(from);
+  p->desc = strdup(note);
   if (!noshare) {
     char *mask = str_escape(host, ':', '\\');
 
@@ -520,12 +515,9 @@ static int u_addinvite(struct chanset_t *chan, char *invite, char *from,
   p->added = now;
   p->lastactive = 0;
   p->flags = flags;
-  p->mask = malloc(strlen(host)+1);
-  strcpy(p->mask,host);
-  p->user = malloc(strlen(from)+1);
-  strcpy(p->user,from);
-  p->desc = malloc(strlen(note)+1);
-  strcpy(p->desc,note);
+  p->mask = strdup(host);
+  p->user = strdup(from);
+  p->desc = strdup(note);
   if (!noshare) {
     char *mask = str_escape(host, ':', '\\');
 
@@ -602,12 +594,9 @@ static int u_addexempt(struct chanset_t *chan, char *exempt, char *from,
   p->added = now;
   p->lastactive = 0;
   p->flags = flags;
-  p->mask = malloc(strlen(host)+1);
-  strcpy(p->mask,host);
-  p->user = malloc(strlen(from)+1);
-  strcpy(p->user,from);
-  p->desc = malloc(strlen(note)+1);
-  strcpy(p->desc,note);
+  p->mask = strdup(host);
+  p->user = strdup(from);
+  p->desc = strdup(note);
   if (!noshare) {
     char *mask = str_escape(host, ':', '\\');
 

+ 4 - 8
src/mod/console.mod/console.c

@@ -36,8 +36,7 @@ static int console_unpack(struct userrec *u, struct user_entry *e)
 
   par = e->u.list->extra;
   arg = newsplit(&par);
-  ci->channel = malloc(strlen(arg) + 1);
-  strcpy(ci->channel, arg);
+  ci->channel = strdup(arg);
   arg = newsplit(&par);
   ci->conflags = logmodes(arg);
   arg = newsplit(&par);
@@ -139,8 +138,7 @@ static int console_gotshare(struct userrec *u, struct user_entry *e, char *par,
     free(ci);
   }
   ci = malloc(sizeof(struct console_info));
-  ci->channel = malloc(strlen(arg) + 1);
-  strcpy(ci->channel, arg);
+  ci->channel = strdup(arg);
   arg = newsplit(&par);
   ci->conflags = logmodes(arg);
   arg = newsplit(&par);
@@ -265,8 +263,7 @@ static int console_dupuser(struct userrec *new, struct userrec *old,
   j = malloc(sizeof(struct console_info));
   my_memcpy(j, i, sizeof(struct console_info));
 
-  j->channel = malloc(strlen(i->channel) + 1);
-  strcpy(j->channel, i->channel);
+  j->channel = strdup(i->channel);
   return set_user(e->type, new, j);
 }
 
@@ -347,8 +344,7 @@ static int console_store(struct userrec *u, int idx, char *par)
   }
   if (i->channel)
     free(i->channel);
-  i->channel = malloc(strlen(dcc[idx].u.chat->con_chan) + 1);
-  strcpy(i->channel, dcc[idx].u.chat->con_chan);
+  i->channel = strdup(dcc[idx].u.chat->con_chan);
   i->conflags = dcc[idx].u.chat->con_flags;
   i->stripflags = dcc[idx].u.chat->strip_flags;
   i->echoflags = (dcc[idx].status & STAT_ECHO) ? 1 : 0;

+ 1 - 3
src/mod/ctcp.mod/ctcp.c

@@ -53,10 +53,8 @@ char autoaway[100];
 
 char *strtolower(char *s)
 {
-  char *p,
-    *p2 = malloc(strlen(s) + 1);
+  char *p, *p2 = strdup(s); 
 
-  strcpy(p2, s);
   p = p2;
   while (*p) {
     *p = tolower(*p);

+ 2 - 4
src/mod/dns.mod/coredns.c

@@ -842,8 +842,7 @@ static void parserespacket(u_8bit_t *s, int l)
 				return;
 			    }
 			    if (!rp->hostn) {
-				rp->hostn = (char *)malloc(strlen(namestring) + 1);
-				strcpy(rp->hostn, namestring);
+                                rp->hostn = strdup(namestring);
 				linkresolvehost(rp);
 				passrp(rp, ttl, T_PTR);
 				return;
@@ -1044,8 +1043,7 @@ static void dns_forward(char *hostn)
     rp = allocresolve();
     rp->state = STATE_AREQ;
     rp->sends = 1;
-    rp->hostn = (char *)malloc(strlen(hostn) + 1);
-    strcpy(rp->hostn, hostn);
+    rp->hostn = strdup(hostn);
     linkresolvehost(rp);
     sendrequest(rp, T_A);
 }

+ 5 - 10
src/mod/irc.mod/irc.c

@@ -215,8 +215,7 @@ void getin_request(char *botnick, char *code, char *par)
     if (ip4[0]) {
       char *tmp2;
 
-      tmp = malloc(strlen(host) + 1);
-      strcpy(tmp, host);
+      tmp = strdup(host);
       tmp2 = strtok(tmp, "@");
       egg_snprintf(ip4host, sizeof ip4host, "%s@%s", strtok(tmp2, "@") ,ip4);
       free(tmp);
@@ -227,8 +226,7 @@ void getin_request(char *botnick, char *code, char *par)
     if (ip6[0]) {
       char *tmp2;
 
-      tmp = malloc(strlen(host) + 1);
-      strcpy(tmp, host);
+      tmp = strdup(host);
       tmp2 = strtok(tmp, "@");
       egg_snprintf(ip6host, sizeof ip6host, "%s@%s", strtok(tmp2, "@") ,ip6);
       free(tmp);
@@ -832,8 +830,7 @@ static void my_setkey(struct chanset_t *chan, char *k)
     chan->channel.key[0] = 0;
     return;
   }
-  chan->channel.key = (char *) malloc(strlen(k) + 1);
-  strcpy(chan->channel.key, k);
+  chan->channel.key = strdup(k);
 }
 
 /* Adds a ban, exempt or invite mask to the list
@@ -850,10 +847,8 @@ static void newmask(masklist *m, char *s, char *who)
   m->next->mask = (char *) malloc(1);
   m->next->mask[0] = 0;
   free(m->mask);
-  m->mask = (char *) malloc(strlen(s) + 1);
-  strcpy(m->mask, s);
-  m->who = (char *) malloc(strlen(who) + 1);
-  strcpy(m->who, who);
+  m->mask = strdup(s);
+  m->who = strdup(who);
   m->timer = now;
 }
 

+ 6 - 16
src/mod/irc.mod/mode.c

@@ -248,8 +248,7 @@ void queue_op(struct chanset_t *chan, char *op) {
   memberlist *m;
   for (n = 0; n < 20; n++) {
     if (!chan->opqueue[n].target) {
-      chan->opqueue[n].target = malloc(strlen(op) + 1);
-      strcpy(chan->opqueue[n].target, op);
+      chan->opqueue[n].target = strdup(op);
       m = ismember(chan, op);
       if (m)
         m->flags |= SENTOP;
@@ -265,8 +264,7 @@ void queue_deop(struct chanset_t *chan, char *op) {
   memberlist *m;
   for (n = 0; n<20; n++) {
     if (!chan->deopqueue[n].target) {
-      chan->deopqueue[n].target = malloc(strlen(op)+1);
-      strcpy(chan->deopqueue[n].target, op);
+      chan->deopqueue[n].target = strdup(op);
       m = ismember(chan, op);
       if (m)
         m->flags |= SENTDEOP;
@@ -403,17 +401,13 @@ static void real_add_mode(struct chanset_t *chan,
   else if (plus == '+' && mode == 'k') {
     if (chan->key)
       free(chan->key);
-    chan->key = (char *) malloc(strlen(op) + 1);
-    if (chan->key)
-      strcpy(chan->key, op);
+    chan->key = strdup(op);
   }
   /* -k ? store removed key */
   else if (plus == '-' && mode == 'k') {
     if (chan->rmkey)
       free(chan->rmkey);
-    chan->rmkey = (char *) malloc(strlen(op) + 1);
-    if (chan->rmkey)
-      strcpy(chan->rmkey, op);
+    chan->rmkey = strdup(op);
   }
   /* +l ? store limit */
   else if (plus == '+' && mode == 'l')
@@ -695,17 +689,13 @@ static void real_add_mode(struct chanset_t *chan,
   else if (plus == '+' && mode == 'k') {
     if (chan->key)
       free(chan->key);
-    chan->key = (char *) malloc(strlen(op) + 1);
-    if (chan->key)
-      strcpy(chan->key, op);
+    chan->key = strdup(op);
   }
   /* -k ? store removed key */
   else if (plus == '-' && mode == 'k') {
     if (chan->rmkey)
       free(chan->rmkey);
-    chan->rmkey = (char *) malloc(strlen(op) + 1);
-    if (chan->rmkey)
-      strcpy(chan->rmkey, op);
+    chan->rmkey = strdup(op);
   }
   /* +l ? store limit */
   else if (plus == '+' && mode == 'l')

+ 2 - 4
src/mod/notes.mod/cmdsnote.c

@@ -14,8 +14,7 @@ static void cmd_pls_noteign(struct userrec *u, int idx, char *par)
   }
   putlog(LOG_CMDS, "*", "#%s# +noteign %s", dcc[idx].nick, par);
 
-  p = buf = malloc(strlen(par)+1);
-  strcpy(p, par);
+  p = buf = strdup(par);
   handle = newsplit(&p);
   mask = newsplit(&p);
   if (mask[0]) {
@@ -55,8 +54,7 @@ static void cmd_mns_noteign(struct userrec *u, int idx, char *par)
     return;
   }
   putlog(LOG_CMDS, "*", "#%s# -noteign %s", dcc[idx].nick, par);
-  p = buf = malloc(strlen(par)+1);
-  strcpy(p, par);
+  p = buf = strdup(par);
   handle = newsplit(&p);
   mask = newsplit(&p);
   if (mask[0]) {

+ 3 - 6
src/mod/notes.mod/notes.c

@@ -754,8 +754,7 @@ int get_note_ignores(struct userrec *u, char ***ignores)
     return 0;
 
   rmspace(xk->data);
-  buf = malloc(strlen(xk->data) + 1);
-  strcpy(buf, xk->data);
+  buf = strdup(xk->data);
   p = buf;
 
   /* Split up the string into small parts */
@@ -801,10 +800,8 @@ int add_note_ignore(struct userrec *u, char *mask)
     if (!ue)
       return 0;
     mxk->next = 0;
-    mxk->data = malloc(strlen(mask) + 1);
-    strcpy(mxk->data, mask);
-    mxk->key = malloc(strlen(NOTES_IGNKEY) + 1);
-    strcpy(mxk->key, NOTES_IGNKEY);
+    mxk->data = strdup(mask);
+    mxk->key = strdup(NOTES_IGNKEY);
     xtra_set(u, ue, mxk);
   } else { /* ... else, we already have other entries. */
     xk->data = realloc(xk->data, strlen(xk->data) + strlen(mask) + 2);

+ 9 - 18
src/mod/server.mod/server.c

@@ -543,9 +543,8 @@ static void parse_q(struct msgq_head *q, char *oldnick, char *newnick)
           q->last = 0;
       } else {
         free(m->msg);
-        m->msg = malloc(strlen(newmsg) + 1);
         m->len = strlen(newmsg);
-        strcpy(m->msg, newmsg);
+        m->msg = strdup(newmsg);
       }
     }
     lm = m;
@@ -612,9 +611,8 @@ static void purge_kicks(struct msgq_head *q)
           free(m->msg);
           egg_snprintf(newmsg, sizeof newmsg, "KICK %s %s %s\n", chan,
 		       newnicks + 1, reason);
-          m->msg = malloc(strlen(newmsg) + 1);
           m->len = strlen(newmsg);
-          strcpy(m->msg, newmsg);
+          m->msg = strdup(newmsg);
         }
       }
     }
@@ -710,9 +708,8 @@ static int deq_kick(int which)
           free(m->msg);
           egg_snprintf(newmsg, sizeof newmsg, "KICK %s %s %s\n", chan2,
 		       newnicks2 + 1, reason);
-          m->msg = malloc(strlen(newmsg) + 1);
           m->len = strlen(newmsg);
-          strcpy(m->msg, newmsg);
+          m->msg = strdup(newmsg);
         }
       }
     }
@@ -943,8 +940,7 @@ static void add_server(char *ss)
     if (!q) {
       x->port = default_port;
       x->pass = 0;
-      x->name = malloc(strlen(ss) + 1);
-      strcpy(x->name, ss);
+      x->name = strdup(ss);
     } else {
 #ifdef USE_IPV6
       if (ss[0] == '[') {
@@ -965,8 +961,7 @@ static void add_server(char *ss)
 	x->pass = 0;
       } else {
 	*q++ = 0;
-	x->pass = malloc(strlen(q) + 1);
-	strcpy(x->pass, q);
+        x->pass = strdup(q);
       }
 #ifdef USE_IPV6
       if (!x->port) {
@@ -1016,11 +1011,10 @@ void servers_changed(struct cfg_entry * entry, char * olddata, int * valid) {
     clearq(serverlist);
     serverlist = NULL;
   }
-  p = malloc(strlen(slist) + 1);
 #ifdef S_RANDSERVERS
   shuffle(slist, ",");
 #endif /* S_RANDSERVERS */
-  strcpy(p, slist);
+  p = strdup(slist);
   add_server(p);
   free(p);
 #endif /* LEAF */
@@ -1037,11 +1031,10 @@ void servers6_changed(struct cfg_entry * entry, char * olddata, int * valid) {
     clearq(serverlist);
     serverlist = NULL;
   }
-  p = malloc(strlen(slist) + 1);
 #ifdef S_RANDSERVERS
   shuffle(slist, ",");
 #endif /* S_RANDSERVERS */
-  strcpy(p, slist);
+  p = strdup(slist);
   add_server(p);
   free(p);
 #endif /* LEAF */
@@ -1133,12 +1126,10 @@ static void next_server(int *ptr, char *serv, unsigned int *port, char *pass)
 
     x->next = 0;
     x->realname = 0;
-    x->name = malloc(strlen(serv) + 1);
-    strcpy(x->name, serv);
+    x->name = strdup(serv);
     x->port = *port ? *port : default_port;
     if (pass && pass[0]) {
-      x->pass = malloc(strlen(pass) + 1);
-      strcpy(x->pass, pass);
+      x->pass = strdup(pass);
     } else
       x->pass = NULL;
     list_append((struct list_type **) (&serverlist), (struct list_type *) x);

+ 2 - 4
src/mod/server.mod/servmsg.c

@@ -200,11 +200,9 @@ static int got001(char *from, char *msg)
       x->realname = NULL;
       if (x->name)
 	free(x->name);
-      x->name = malloc(strlen(from) + 1);
-      strcpy(x->name, from);
+      x->name = strdup(from);
     } else {
-      x->realname = malloc(strlen(from) + 1);
-      strcpy(x->realname, from);
+      x->realname = strdup(from);
     }
   }
   return 0;

+ 5 - 10
src/mod/share.mod/share.c

@@ -1145,8 +1145,7 @@ static void share_ufsend(int idx, char *par)
       dcc[i].addr = my_atoul(ip);
       dcc[i].port = atoi(port);
       strcpy(dcc[i].nick, "*users");
-      dcc[i].u.xfer->filename = malloc(strlen(s) + 1);
-      strcpy(dcc[i].u.xfer->filename, s);
+      dcc[i].u.xfer->filename = strdup(s);
       dcc[i].u.xfer->origname = dcc[i].u.xfer->filename;
       dcc[i].u.xfer->length = atoi(par);
       dcc[i].u.xfer->f = f;
@@ -1483,8 +1482,7 @@ static struct share_msgq *q_addmsg(struct share_msgq *qq,
 
     q->chan = chan;
     q->next = NULL;
-    q->msg = (char *) malloc(strlen(s) + 1);
-    strcpy(q->msg, s);
+    q->msg = strdup(s);
     return q;
   }
   cnt = 0;
@@ -1497,8 +1495,7 @@ static struct share_msgq *q_addmsg(struct share_msgq *qq,
   q = q->next;
   q->chan = chan;
   q->next = NULL;
-  q->msg = (char *) malloc(strlen(s) + 1);
-  strcpy(q->msg, s);
+  q->msg = strdup(s);
   return qq;
 }
 
@@ -1687,18 +1684,16 @@ static struct userrec *dup_userlist(int t)
 	  struct user_entry *nue;
 
 	  nue = malloc(sizeof(struct user_entry));
-	  nue->name = malloc(strlen(ue->name) + 1);
 	  nue->type = NULL;
 	  nue->u.list = NULL;
-	  strcpy(nue->name, ue->name);
+          nue->name = strdup(ue->name);
 	  list_insert((&nu->entries), nue);
 	  for (lt = ue->u.list; lt; lt = lt->next) {
 	    struct list_type *list;
 
 	    list = malloc(sizeof(struct list_type));
 	    list->next = NULL;
-	    list->extra = malloc(strlen(lt->extra) + 1);
-	    strcpy(list->extra, lt->extra);
+            list->extra = strdup(lt->extra);
 	    list_append((&nue->u.list), list);
 	  }
 	} else {

+ 2 - 4
src/mod/share.mod/uf_features.c

@@ -208,8 +208,7 @@ static void uf_features_parse(int idx, char *par)
   uff_list_t *ul;
 
   uff_sbuf[0] = 0;				/* Reset static buffer	*/
-  p = s = buf = malloc(strlen(par) + 1);	/* Allocate temp buffer	*/
-  strcpy(buf, par);
+  p = s = buf = strdup(par);
 
   /* Clear all currently set features. */
   dcc[idx].u.bot->uff_flags = 0;
@@ -255,8 +254,7 @@ static int uf_features_check(int idx, char *par)
   uff_list_t *ul;
 
   uff_sbuf[0] = 0;				/* Reset static buffer	*/
-  p = s = buf = malloc(strlen(par) + 1);	/* Allocate temp buffer	*/
-  strcpy(buf, par);
+  p = s = buf = strdup(par);
 
   /* Clear all currently set features. */
   dcc[idx].u.bot->uff_flags = 0;

+ 4 - 8
src/mod/transfer.mod/transfer.c

@@ -170,8 +170,7 @@ static char *replace_spaces(char *fn)
 {
   register char *ret, *p;
 
-  p = ret = malloc(strlen(fn) + 1);
-  strcpy(ret, fn);
+  p = ret = strdup(fn);
   while ((p = strchr(p, ' ')) != NULL)
     *p = '_';
   return ret;
@@ -210,10 +209,8 @@ static void queue_file(char *dir, char *file, char *from, char *to)
 
   fileq = (fileq_t *) malloc(sizeof(fileq_t));
   fileq->next = q;
-  fileq->dir = (char *) malloc(strlen(dir) + 1);
-  fileq->file = (char *) malloc(strlen(file) + 1);
-  strcpy(fileq->dir, dir);
-  strcpy(fileq->file, file);
+  fileq->dir = strdup(dir);
+  fileq->file = strdup(file);
   strcpy(fileq->nick, from);
   strcpy(fileq->to, to);
 }
@@ -303,8 +300,7 @@ static void send_next_file(char *to)
       return;
     }
   } else {
-    s1 = malloc(strlen(s) + 1);
-    strcpy(s1, s);
+    s1 = strdup(s);
   }
   if (this->dir[0] == '*') {
     s = realloc(s, strlen(&this->dir[1]) + strlen(this->file) + 2);

+ 3 - 6
src/mod/update.mod/update.c

@@ -113,8 +113,7 @@ static void update_ufsend(int idx, char *par)
       dcc[i].addr = my_atoul(ip);
       dcc[i].port = atoi(port);
       strcpy(dcc[i].nick, "*binary");
-      dcc[i].u.xfer->filename = malloc(strlen(s) + 1);
-      strcpy(dcc[i].u.xfer->filename, s);
+      dcc[i].u.xfer->filename = strdup(s);
       dcc[i].u.xfer->origname = dcc[i].u.xfer->filename;
       dcc[i].u.xfer->length = atoi(par);
       dcc[i].u.xfer->f = f;
@@ -178,10 +177,8 @@ static void got_nu(char *botnick, char *code, char *par)
      obi = get_user(&USERENTRY_BOTADDR, u1);
      bi = malloc(sizeof(struct bot_addr));
 
-     bi->uplink = malloc(strlen(botnick) + 1);
-     strcpy(bi->uplink, botnick);
-     bi->address = malloc(strlen(obi->address) + 1);
-     strcpy(bi->address, obi->address);
+     bi->uplink = strdup(botnick);
+     bi->address = strdup(obi->address);
      bi->telnet_port = obi->telnet_port;
      bi->relay_port = obi->relay_port;
      bi->hublevel = obi->hublevel;

+ 4 - 8
src/modules.c

@@ -64,8 +64,7 @@ void check_static(char *name, char *(*func) ())
 {
   struct static_list *p = malloc(sizeof(struct static_list));
 
-  p->name = malloc(strlen(name) + 1);
-  strcpy(p->name, name);
+  p->name = strdup(name);
   p->func = func;
   p->next = static_modules;
   static_modules = p;
@@ -623,8 +622,7 @@ void init_modules(void)
   BT_load = bind_table_add("load", 1, "s", MATCH_MASK, 0);
 
   module_list = malloc(sizeof(module_entry));
-  module_list->name = malloc(8);
-  strcpy(module_list->name, "eggdrop");
+  module_list->name = strdup("eggdrop");
   module_list->major = (egg_numver) / 10000;
   module_list->minor = ((egg_numver) / 100) % 100;
   module_list->next = NULL;
@@ -666,8 +664,7 @@ const char *module_load(char *name)
   p = malloc(sizeof(module_entry));
   if (p == NULL)
     return "Malloc error";
-  p->name = malloc(strlen(name) + 1);
-  strcpy(p->name, name);
+  p->name = strdup(name);
   p->major = 0;
   p->minor = 0;
   p->funcs = 0;
@@ -706,8 +703,7 @@ static int module_rename(char *name, char *newname)
   for (p = module_list; p && p->name; p = p->next)
     if (!egg_strcasecmp(name, p->name)) {
       free(p->name);
-      p->name = malloc(strlen(newname) + 1);
-      strcpy(p->name, newname);
+      p->name = strdup(newname);
       return 1;
     }
   return 0;

+ 4 - 14
src/tclhash.c

@@ -41,16 +41,6 @@ static bind_table_t *BT_chpt;
 static bind_table_t *BT_chjn;
 
 
-static char *my_strdup(const char *s)
-{
-	char *t;
-
-	t = (char *)malloc(strlen(s)+1);
-	strcpy(t, s);
-	return(t);
-}
-
-
 extern cmd_t C_dcc[];
 
 void binds_init(void)
@@ -89,9 +79,9 @@ bind_table_t *bind_table_add(const char *name, int nargs, const char *syntax, in
 	/* Nope, we have to create a new one. */
 	table = (bind_table_t *)malloc(sizeof(*table));
 	table->chains = NULL;
-	table->name = my_strdup(name);
+	table->name = strdup(name);
 	table->nargs = nargs;
-	table->syntax = my_strdup(syntax);
+	table->syntax = strdup(syntax);
 	table->match_type = match_type;
 	table->flags = flags;
 	table->next = bind_table_list_head;
@@ -178,7 +168,7 @@ int bind_entry_add(bind_table_t *table, const char *flags, const char *mask, con
 	if (!chain) {
 		chain = (bind_chain_t *)malloc(sizeof(*chain));
 		chain->entries = NULL;
-		chain->mask = my_strdup(mask);
+		chain->mask = strdup(mask);
 		chain->next = table->chains;
 		table->chains = chain;
 	}
@@ -204,7 +194,7 @@ int bind_entry_add(bind_table_t *table, const char *flags, const char *mask, con
 		chain->entries = entry;
 	}
 
-	entry->function_name = my_strdup(function_name);
+	entry->function_name = strdup(function_name);
 	entry->callback = callback;
 	entry->client_data = client_data;
 	entry->hits = 0;

+ 22 - 42
src/userent.c

@@ -304,10 +304,8 @@ int config_unpack(struct userrec *u, struct user_entry *e)
     data = curr->extra;
     key = newsplit(&data);
     if (data[0]) {
-      t->key = malloc(strlen(key) + 1);
-      strcpy(t->key, key);
-      t->data = malloc(strlen(data) + 1);
-      strcpy(t->data, data);
+      t->key = strdup(key);
+      t->data = strdup(data);
       list_insert((&e->u.extra), t);
     }
     curr = curr->next;
@@ -409,10 +407,8 @@ int config_dupuser(struct userrec *new, struct userrec *old, struct user_entry *
   for (x1 = e->u.extra; x1; x1 = x1->next) {
     x2 = malloc(sizeof(struct xtra_key));
 
-    x2->key = malloc(strlen(x1->key) + 1);
-    strcpy(x2->key, x1->key);
-    x2->data = malloc(strlen(x1->data) + 1);
-    strcpy(x2->data, x1->data);
+    x2->key = strdup(x1->key);
+    x2->data = strdup(x1->data);
     set_user(&USERENTRY_CONFIG, new, x2);
   }
   return 1;
@@ -586,8 +582,7 @@ int pass_set(struct userrec *u, struct user_entry *e, void *buf)
       strcpy(new, pass);
     else
       encrypt_pass(pass, new);
-    e->u.extra = malloc(strlen(new) + 1);
-    strcpy(e->u.extra, new);
+    e->u.extra = strdup(new);
   }
   if (!noshare && !(u->flags & (USER_BOT | USER_UNSHARED)))
     shareout(NULL, "c PASS %s %s\n", u->handle, pass ? pass : "");
@@ -666,9 +661,8 @@ static int laston_unpack(struct userrec *u, struct user_entry *e)
   if (!par[0])
     par = "???";
   li = malloc(sizeof(struct laston_info));
-  li->lastonplace = malloc(strlen(par) + 1);
   li->laston = atoi(arg);
-  strcpy(li->lastonplace, par);
+  li->lastonplace = strdup(par);
   list_type_kill(e->u.list);
   e->u.extra = li;
   return 1;
@@ -686,6 +680,7 @@ static int laston_pack(struct userrec *u, struct user_entry *e)
   e->u.list->next = NULL;
   e->u.list->extra = malloc(l + 1);
   strcpy(e->u.list->extra, work);
+  
   free(li->lastonplace);
   free(li);
   return 1;
@@ -771,8 +766,7 @@ static int laston_tcl_set(Tcl_Interp * irp, struct userrec *u,
   li = malloc(sizeof(struct laston_info));
 
   if (argc == 5) {
-    li->lastonplace = malloc(strlen(argv[4]) + 1);
-    strcpy(li->lastonplace, argv[4]);
+    li->lastonplace = strdup(argv[4]);
   } else {
     li->lastonplace = malloc(1);
     li->lastonplace[0] = 0;
@@ -791,8 +785,7 @@ static int laston_dupuser(struct userrec *new, struct userrec *old,
     li2 = malloc(sizeof(struct laston_info));
 
     li2->laston = li->laston;
-    li2->lastonplace = malloc(strlen(li->lastonplace) + 1);
-    strcpy(li2->lastonplace, li->lastonplace);
+    li2->lastonplace = strdup(li->lastonplace);
     return set_user(&USERENTRY_LASTON, new, li2);
   }
   return 0;
@@ -833,8 +826,7 @@ static int botaddr_unpack(struct userrec *u, struct user_entry *e)
   q1 = strchr(p, ':');
   if (q1)
     *q1++ = 0;
-  bi->address = malloc(strlen(p) + 1);
-  strcpy(bi->address, p);
+  bi->address = strdup(p);
   if (q1) {
     q2 = strchr(q1, ':');
     if (q2)
@@ -849,8 +841,7 @@ static int botaddr_unpack(struct userrec *u, struct user_entry *e)
       q1 = strchr(q2, ':');
       if (q1) {
         *q1++ = 0;
-        bi->uplink = malloc(strlen(q1) + 1);
-        strcpy(bi->uplink, q1);
+        bi->uplink = strdup(q1);
 
       }
       bi->hublevel = atoi(q2);
@@ -967,8 +958,7 @@ static int botaddr_tcl_set(Tcl_Interp *irp, struct userrec *u,
     } else {
       free(bi->address);
     }
-    bi->address = malloc(strlen(argv[3]) + 1);
-    strcpy(bi->address, argv[3]);
+    bi->address = strdup(argv[3]);
     if (argc > 4)
       bi->telnet_port = atoi(argv[4]);
     if (argc > 5)
@@ -1009,16 +999,14 @@ static int botaddr_gotshare(struct userrec *u, struct user_entry *e,
   egg_bzero(bi, sizeof(struct bot_addr));
 
   arg = newsplit(&buf);
-  bi->address = malloc(strlen(arg) + 1);
-  strcpy(bi->address, arg);
+  bi->address = strdup(arg);
   arg = newsplit(&buf);
   bi->telnet_port = atoi(arg);
   arg = newsplit(&buf);
   bi->relay_port = atoi(arg);
   arg = newsplit(&buf);
   bi->hublevel = atoi(arg);
-  bi->uplink = malloc(strlen(buf) + 1);
-  strcpy(bi->uplink, buf);
+  bi->uplink = strdup(buf);
   if (!bi->telnet_port)
     bi->telnet_port = 3333;
   if (!bi->relay_port)
@@ -1039,10 +1027,8 @@ static int botaddr_dupuser(struct userrec *new, struct userrec *old,
       bi2->telnet_port = bi->telnet_port;
       bi2->relay_port = bi->relay_port;
       bi2->hublevel = bi->hublevel;
-      bi2->address = malloc(strlen(bi->address) + 1);
-      bi2->uplink = malloc(strlen(bi->uplink) + 1);
-      strcpy(bi2->address, bi->address);
-      strcpy(bi2->uplink, bi->uplink);
+      bi2->address = strdup(bi->address);
+      bi2->uplink = strdup(bi->uplink);
       return set_user(&USERENTRY_BOTADDR, new, bi2);
     }
   }
@@ -1149,10 +1135,8 @@ int xtra_unpack(struct userrec *u, struct user_entry *e)
     data = curr->extra;
     key = newsplit(&data);
     if (data[0]) {
-      t->key = malloc(strlen(key) + 1);
-      strcpy(t->key, key);
-      t->data = malloc(strlen(data) + 1);
-      strcpy(t->data, data);
+      t->key = strdup(key);
+      t->data = strdup(data);
       list_insert((&e->u.extra), t);
     }
     curr = curr->next;
@@ -1243,10 +1227,8 @@ static int xtra_dupuser(struct userrec *new, struct userrec *old,
   for (x1 = e->u.extra; x1; x1 = x1->next) {
     x2 = malloc(sizeof(struct xtra_key));
 
-    x2->key = malloc(strlen(x1->key) + 1);
-    strcpy(x2->key, x1->key);
-    x2->data = malloc(strlen(x1->data) + 1);
-    strcpy(x2->data, x1->data);
+    x2->key = strdup(x1->key);
+    x2->data = strdup(x1->data);
     set_user(&USERENTRY_XTRA, new, x2);
   }
   return 1;
@@ -1428,8 +1410,7 @@ static int hosts_set(struct userrec *u, struct user_entry *e, void *buf)
     *t = malloc(sizeof(struct list_type));
 
     (*t)->next = NULL;
-    (*t)->extra = malloc(strlen(host) + 1);
-    strcpy((*t)->extra, host);
+    (*t)->extra = strdup(host);
   }
   return 1;
 }
@@ -1533,8 +1514,7 @@ int del_entry_type(struct user_entry_type *type)
 
     if (e && !e->name) {
       e->type->pack(u, e);
-      e->name = malloc(strlen(e->type->name) + 1);
-      strcpy(e->name, e->type->name);
+      e->name = strdup(e->type->name);
       e->type = NULL;
     }
   }

+ 1 - 2
src/userrec.c

@@ -686,8 +686,7 @@ void touch_laston(struct userrec *u, char *where, time_t timeval)
       free(li->lastonplace);
     li->laston = timeval;
     if (where) {
-      li->lastonplace = malloc(strlen(where) + 1);
-      strcpy(li->lastonplace, where);
+      li->lastonplace = strdup(where);
     } else
       li->lastonplace = NULL;
     set_user(&USERENTRY_LASTON, u, li);

+ 12 - 24
src/users.c

@@ -125,12 +125,9 @@ void addignore(char *ign, char *from, char *mnote, time_t expire_time)
   p->expire = expire_time;
   p->added = now;
   p->flags = expire_time ? 0 : IGREC_PERM;
-  p->igmask = malloc(strlen(ign) + 1);
-  strcpy(p->igmask, ign);
-  p->user = malloc(strlen(from) + 1);
-  strcpy(p->user, from);
-  p->msg = malloc(strlen(mnote) + 1);
-  strcpy(p->msg, mnote);
+  p->igmask = strdup(ign);
+  p->user = strdup(from);
+  p->msg = strdup(mnote);
   if (!noshare) {
     char *mask = str_escape(ign, ':', '\\');
 
@@ -230,12 +227,9 @@ static void addmask_fully(struct chanset_t *chan, maskrec **m, maskrec **global,
   p->added = added;
   p->lastactive = last;
   p->flags = flags;
-  p->mask = malloc(strlen(mask) + 1);
-  strcpy(p->mask, mask);
-  p->user = malloc(strlen(from) + 1);
-  strcpy(p->user, from);
-  p->desc = malloc(strlen(note) + 1);
-  strcpy(p->desc, note);
+  p->mask = strdup(mask);
+  p->user = strdup(from);
+  p->desc = strdup(note);
 }
 
 static void restore_chanban(struct chanset_t *chan, char *host)
@@ -437,13 +431,10 @@ static void restore_ignore(char *host)
       p->expire = atoi(expi);
       p->added = atoi(added);
       p->flags = flags;
-      p->igmask = malloc(strlen(host) + 1);
-      strcpy(p->igmask, host);
-      p->user = malloc(strlen(user) + 1);
-      strcpy(p->user, user);
+      p->igmask = strdup(host);
+      p->user = strdup(user);
       if (desc) {
-	p->msg = malloc(strlen(desc) + 1);
-	strcpy(p->msg, desc);
+        p->msg = strdup(desc);
       } else
 	p->msg = NULL;
       return;
@@ -809,8 +800,7 @@ int readuserfile(char *file, struct userrec **ret)
 		cr->flags = fr.chan;
 		cr->flags_udef = fr.udef_chan;
 		if (s[0]) {
-		  cr->info = (char *) malloc(strlen(s) + 1);
-		  strcpy(cr->info, s);
+                  cr->info = strdup(s);
 		} else
 		  cr->info = NULL;
 	      }
@@ -915,8 +905,7 @@ int readuserfile(char *file, struct userrec **ret)
 		list = malloc(sizeof(struct list_type));
 
 		list->next = NULL;
-		list->extra = malloc(strlen(s) + 1);
-		strcpy(list->extra, s);
+                list->extra = strdup(s);
 		list_append((&ue->u.list), list);
 		ok = 1;
 	      }
@@ -929,8 +918,7 @@ int readuserfile(char *file, struct userrec **ret)
 	      ue->u.list = malloc(sizeof(struct list_type));
 
 	      ue->u.list->next = NULL;
-	      ue->u.list->extra = malloc(strlen(s) + 1);
-	      strcpy(ue->u.list->extra, s);
+              ue->u.list->extra = strdup(s);
 	      list_insert((&u->entries), ue);
 	    }
 	  }