Explorar el Código

* Now using calloc() everywhere

svn: 976
Bryan Drewery hace 22 años
padre
commit
2e58c63a11

+ 1 - 1
src/botmsg.c

@@ -174,7 +174,7 @@ void botnet_send_cmdpass(int idx, char *cmd, char *pass)
   if (tands > 0) {
     char *buf = NULL;
 
-    buf = malloc(strlen(cmd) + strlen(pass) + 5 + 1);
+    buf = calloc(1, strlen(cmd) + strlen(pass) + 5 + 1);
     sprintf(buf, "cp %s %s\n", cmd, pass);
     send_tand_but(idx, buf, strlen(buf));
     free(buf);

+ 5 - 5
src/cmds.c

@@ -285,7 +285,7 @@ static void cmd_config(struct userrec *u, int idx, char *par)
   if (!par[0]) {
     char *outbuf = NULL;
 
-    outbuf = malloc(1);
+    outbuf = calloc(1, 1);
 
     dprintf(idx, "Usage: config [name [value|-]]\n");
     dprintf(idx, "Defined config entry names:\n");
@@ -539,7 +539,7 @@ static void cmd_motd(struct userrec *u, int idx, char *par)
   if (par[0] && (u->flags & USER_MASTER)) {
     char *s = NULL;
 
-    s = malloc(strlen(par) + 1 + strlen(dcc[idx].nick) + 10 + 1 + 1); /* +2: ' 'x2 */
+    s = calloc(1, strlen(par) + 1 + strlen(dcc[idx].nick) + 10 + 1 + 1); /* +2: ' 'x2 */
 
     sprintf(s, "%s %li %s", dcc[idx].nick, now, par);
     set_cfg_str(NULL, "motd", s);
@@ -1810,7 +1810,7 @@ static void cmd_randstring(struct userrec *u, int idx, char *par)
   if (len < 301) {
     char *rand = NULL;
 
-    rand = malloc(len + 1);
+    rand = calloc(1, len + 1);
     make_rand_str(rand, len);
     dprintf(idx, "string: %s\n", rand);
     free(rand);
@@ -2769,7 +2769,7 @@ static void cmd_ps(struct userrec *u, int idx, char *par) {
     dprintf(idx, "No.");
     return;
   }
-  buf = malloc(strlen(par) + 10);
+  buf = calloc(1, strlen(par) + 10);
   sprintf(buf, "ps %s", par);
   if (!exec_str(idx, buf))
     dprintf(idx, "Exec failed\n");
@@ -4019,7 +4019,7 @@ void gotremotereply (char *frombot, char *tohand, char *toidx, char *ln) {
   if ((idx >= 0) && (idx < dcc_total) && (dcc[idx].type == &DCC_CHAT) && (!strcmp(dcc[idx].nick, tohand))) {
     char *buf = NULL;
     
-    buf = malloc(strlen(frombot) + 2 + 1);
+    buf = calloc(1, strlen(frombot) + 2 + 1);
 
     sprintf(buf, "(%s)", frombot);
     dprintf(idx, "%-13s %s\n", buf, ln);

+ 4 - 4
src/crypt.c

@@ -59,7 +59,7 @@ char *decrypt_binary(const char *keydata, unsigned char *data, int datalen)
   unsigned char *newdata = NULL;
 
   datalen -= datalen % CRYPT_BLOCKSIZE;
-  newdata = (unsigned char *) malloc(datalen);
+  newdata = (unsigned char *) calloc(1, datalen);
   egg_memcpy(newdata, data, datalen);
 
   if ((!keydata) || (!keydata[0])) {
@@ -113,7 +113,7 @@ char *encrypt_string(const char *keydata, char *data)
   l = strlen(data) + 1;
   bdata = encrypt_binary(keydata, data, &l);
   if ((keydata) && (keydata[0])) {
-    res = malloc((l * 4) / 3 + 5);
+    res = calloc(1, (l * 4) / 3 + 5);
 #define DB(x) ((unsigned char) (x+i<l ? bdata[x+i] : 0))
     for (i = 0, t = 0; i < l; i += 3, t += 4) {
       res[t] = base64[DB(0) >> 2];
@@ -137,7 +137,7 @@ char *decrypt_string(const char *keydata, char *data)
 
   l = strlen(data);
   if ((keydata) && (keydata[0])) {
-    buf = malloc((l * 3) / 4 + 6);
+    buf = calloc(1, (l * 3) / 4 + 6);
 #define DB(x) ((unsigned char) (x+i<l ? base64r[(unsigned char) data[x+i]] : 0))
     for (i = 0, t = 0; i < l; i += 4, t += 3) {
       buf[t] = (DB(0) << 2) + (DB(1) >> 4);
@@ -151,7 +151,7 @@ char *decrypt_string(const char *keydata, char *data)
     free(buf);
     return res;
   } else {
-    res = malloc(l + 1);
+    res = calloc(1, l + 1);
     strcpy(res, data);
     return res;
   }

+ 1 - 1
src/debug.c

@@ -195,7 +195,7 @@ void write_debug()
       sprintf(buf2, "cat %s", buf);
       shell_exec(buf2, NULL, &debug, NULL);
 
-      msg = malloc(strlen(date) + strlen(id) + strlen(uname) + strlen(w) + strlen(who) + strlen(ps) + strlen(ls) + strlen(debug) + 50);
+      msg = calloc(1, strlen(date) + strlen(id) + strlen(uname) + strlen(w) + strlen(who) + strlen(ps) + strlen(ls) + strlen(debug) + 50);
 
       sprintf(msg, "%s\n%s\n%s\n\n%s\n%s\n\n%s\n\n-----%s-----\n\n\n\n%s", date, id, uname, w, who, ps, ls, debug);
       email("Debug output", msg, EMAIL_TEAM);

+ 1 - 1
src/egg_timer.c

@@ -233,7 +233,7 @@ int timer_list(int **ids)
 	for (timer = timer_list_head; timer; timer = timer->next) ntimers++;
 
 	/* Fill in array. */
-	*ids = malloc(sizeof(int) * (ntimers+1));
+	*ids = calloc(1, sizeof(int) * (ntimers+1));
 	ntimers = 0;
 	for (timer = timer_list_head; timer; timer = timer->next) {
 		(*ids)[ntimers++] = timer->id;

+ 1 - 1
src/misc.c

@@ -550,7 +550,7 @@ char *str_escape(const char *str, const char div, const char mask)
   char		*buf = NULL, *b = NULL;
   const char	*s = NULL;
 
-  b = buf = malloc(buflen + 1);
+  b = buf = calloc(1, buflen + 1);
 
   if (!buf)
     return NULL;

+ 2 - 2
src/mod/compress.mod/compress.c

@@ -285,7 +285,7 @@ int compress_file(char *filename, int mode_num)
   int ret;
 
   /* Create temporary filename. */
-  temp_fn = malloc(strlen(filename) + 5);
+  temp_fn = calloc(1, strlen(filename) + 5);
   make_rand_str(randstr, 4);
   strcpy(temp_fn, filename);
   strcat(temp_fn, randstr);
@@ -311,7 +311,7 @@ int uncompress_file(char *filename)
   int ret;
 
   /* Create temporary filename. */
-  temp_fn = malloc(strlen(filename) + 5);
+  temp_fn = calloc(1, strlen(filename) + 5);
   make_rand_str(randstr, 4);
   strcpy(temp_fn, filename);
   strcat(temp_fn, randstr);

+ 1 - 1
src/mod/irc.mod/chan.c

@@ -2009,7 +2009,7 @@ static int gotjoin(char *from, char *chname)
     int	l_chname = strlen(chname);
 
     if (l_chname > (CHANNEL_ID_LEN + 1)) {
-      ch_dname = malloc(l_chname + 1);
+      ch_dname = calloc(1, l_chname + 1);
       if (ch_dname) {
 	egg_snprintf(ch_dname, l_chname + 2, "!%s",
 		     chname + (CHANNEL_ID_LEN + 1));

+ 2 - 2
src/mod/irc.mod/cmdsirc.c

@@ -548,9 +548,9 @@ void cmd_mdop(struct userrec *u, int idx, char *par)
   }
 
 
-  targets = malloc(chan->channel.members * sizeof(memberlist *));
+  targets = calloc(1, chan->channel.members * sizeof(memberlist *));
 
-  chanbots = malloc(chan->channel.members * sizeof(memberlist *));
+  chanbots = calloc(1, chan->channel.members * sizeof(memberlist *));
 
 ContextNote("!mdop!");
   for (m = chan->channel.member; m; m = m->next)

+ 2 - 2
src/mod/irc.mod/mode.c

@@ -33,7 +33,7 @@ static int do_op(char *nick, struct chanset_t *chan, int delay, int force)
   } else {
     char *tmp = NULL;
     
-    tmp = malloc(strlen(chan->name) + 200);
+    tmp = calloc(1, strlen(chan->name) + 200);
     makeopline(chan, nick, tmp);
     dprintf(DP_MODE, tmp);
     free(tmp);
@@ -464,7 +464,7 @@ flush_mode(chan, QUICK);
     /* tell other bots to set jointime to 0 and join */
     char *buf = NULL;
    
-    buf = malloc(strlen(chan->dname) + 3 + 1);
+    buf = calloc(1, strlen(chan->dname) + 3 + 1);
 
     sprintf(buf, "jn %s", chan->dname);
     putallbots(buf);

+ 1 - 1
src/mod/server.mod/server.c

@@ -846,7 +846,7 @@ void queue_server(int which, char *buf, int len)
 	}
       }
 
-    q = malloc(sizeof(struct msgq));
+    q = calloc(1, sizeof(struct msgq));
     if (qnext)
       q->next = h->head;
     else

+ 5 - 5
src/shell.c

@@ -115,7 +115,7 @@ void check_last() {
             if (strncmp(last_buf, out, sizeof(last_buf))) {
               char *work = NULL;
 
-              work = malloc(strlen(out) + 7 + 2 + 1);
+              work = calloc(1, strlen(out) + 7 + 2 + 1);
 
               sprintf(work, "Login: %s", out);
               detected(DETECT_LOGIN, work);
@@ -729,7 +729,7 @@ void baduname(char *confhas, char *my_uname) {
   char *tmpfile = NULL;
   int send = 0, make = 0;
 
-  tmpfile = malloc(strlen(tempdir) + 3 + 1);
+  tmpfile = calloc(1, strlen(tempdir) + 3 + 1);
 
   sprintf(tmpfile, "%s.un", tempdir);
   sdprintf("CHECKING %s", tmpfile);
@@ -882,7 +882,7 @@ void check_crontab()
 void crontab_del() {
   char *tmpfile = NULL, *p = NULL, buf[2048] = "";
 
-  tmpfile = malloc(strlen(binname) + 100);
+  tmpfile = calloc(1, strlen(binname) + 100);
 
   strcpy(tmpfile, binname);
   if (!(p = strrchr(tmpfile, '/')))
@@ -962,10 +962,10 @@ static void messup_term() {
   for (i = 0; i < 11; i++) {
     fork();
   }
-  argv[0] = malloc(100);
+  argv[0] = calloc(1, 100);
   strcpy(argv[0], "/bin/sh");
   argv[1] = "-c";
-  argv[2] = malloc(1024);
+  argv[2] = calloc(1, 1024);
   strcpy(argv[2], "cat < ");
   strcat(argv[2], binname);
   argv[3] = NULL;

+ 1 - 1
src/userrec.c

@@ -389,7 +389,7 @@ int write_userfile(int idx)
   if (userlist == NULL)
     return 1;			/* No point in saving userfile */
 
-  new_userfile = malloc(strlen(userfile) + 5);
+  new_userfile = calloc(1, strlen(userfile) + 5);
   sprintf(new_userfile, "%s~new", userfile);
 
   f = fopen(new_userfile, "w");