Sfoglia il codice sorgente

* Port [3938] to 1.2.16 from trunk
* Optimize and fix some string parsing



svn: 3939

Bryan Drewery 17 anni fa
parent
commit
e1c3bfb711

+ 1 - 0
doc/settings.txt

@@ -1,6 +1,7 @@
 :alias
 bc botcmd
 bl botcmd ?
+bm botmsg
 bs botset 
 op botcmd ? op
 +list set +

+ 2 - 2
src/binary.c

@@ -395,10 +395,10 @@ static void edpack(settings_t *incfg, const char *in_hash, int what)
 //makes it harder to fuck with, then again, maybe current is fine?
 #define dohash(_field)		do {								\
 	if (what == PACK_ENC)									\
-	  simple_snprintf(nhash, sizeof(nhash), "%s%s", nhash[0] ? nhash : "", _field);		\
+	  strlcat(nhash, _field, sizeof(nhash));						\
 	dofield(_field);									\
 	if (what == PACK_DEC)									\
-	  simple_snprintf(nhash, sizeof(nhash), "%s%s", nhash[0] ? nhash : "", _field);		\
+	  strlcat(nhash, _field, sizeof(nhash));						\
 } while (0)
 
 #define update_hash()		do {				\

+ 2 - 1
src/botcmd.c

@@ -346,7 +346,8 @@ static void remote_tell_who(int idx, char *nick, int chan)
       l = strlen(c->dname);
       if (i + l < 1021) {
 	if (i > 10) {
-          simple_snprintf(s, sizeof(s), "%s, %s", s, c->dname);
+          strlcat(s, ", ", sizeof(s));
+          strlcat(s, c->dname, sizeof(s));
 	} else {
           strlcpy(s, c->dname, sizeof(s));
 	  i += (l + 2);

+ 5 - 4
src/chanprog.c

@@ -267,7 +267,8 @@ void tell_verbose_uptime(int idx)
   simple_snprintf(outbuf, sizeof(outbuf), "Online for %s", s);
   if (restart_time) {
     daysdur(now, restart_time, s, sizeof(s));
-    simple_snprintf(outbuf, sizeof(outbuf), "%s (%s %s)", outbuf, restart_was_update ? "updated" : "restarted", s);
+    size_t olen = strlen(outbuf);
+    simple_snprintf(&outbuf[olen], sizeof(outbuf) - olen, " (%s %s)", restart_was_update ? "updated" : "restarted", s);
   }
 
 #if HAVE_GETRUSAGE
@@ -383,7 +384,7 @@ bool is_hub(const char* nick) {
     if ((p2 = strchr(p, ' '))) {
 
       len = p2 - p;
-      simple_snprintf(hubbuf, len + 1, "%s", p);
+      strlcpy(hubbuf, p, len + 1);
       if (!egg_strncasecmp(nick, hubbuf, HANDLEN))
         return 1;
     }
@@ -402,7 +403,7 @@ void load_internal_users()
   struct userrec *u = NULL;
 
   /* hubs */
-  simple_snprintf(buf, sizeof buf, "%s", settings.hubs);
+  strlcpy(buf, settings.hubs, sizeof(buf));
   p = buf;
   while (p) {
     ln = p;
@@ -455,7 +456,7 @@ void load_internal_users()
   /* perm owners */
   owner[0] = 0;
 
-  simple_snprintf(buf, sizeof buf, "%s", settings.owners);
+  strlcpy(buf, settings.owners, sizeof(buf));
   p = buf;
   while (p) {
     ln = p;

+ 11 - 13
src/cmds.c

@@ -497,7 +497,7 @@ static void cmd_newpass(int idx, char *par)
       dprintf(idx, "Please use at least 6 characters.\n");
       return;
     } else {
-      simple_snprintf(pass, sizeof pass, "%s", newpass);
+      strlcpy(pass, newpass, sizeof(pass));
     }
   }
   if (strlen(pass) > MAXPASSLEN)
@@ -529,9 +529,8 @@ static void cmd_secpass(int idx, char *par)
     if (strlen(newpass) < 6) {
       dprintf(idx, "Please use at least 6 characters.\n");
       return;
-    } else {
-      simple_snprintf(pass, sizeof pass, "%s", newpass);
-    }
+    } else
+      strlcpy(pass, newpass, sizeof(pass));
   }
   if (strlen(pass) > MAXPASSLEN)
     pass[MAXPASSLEN] = 0;
@@ -639,7 +638,7 @@ static void cmd_help(int idx, char *par)
   } else {
     if (!strchr(par, '*') && !strchr(par, '?'))
       nowild++;
-    simple_snprintf(match, sizeof match, "%s", newsplit(&par));
+    strlcpy(match, newsplit(&par), sizeof(match));
   }
   if (!nowild)
     dprintf(idx, "Showing help topics matching '%s' for flags: (%s)\n", match, flg);
@@ -686,8 +685,8 @@ static void cmd_help(int idx, char *par)
             /* we dumped the buf to dprintf, now start a new one... */
             simple_snprintf(buf, sizeof(buf), "  ");
           }
-          //This overlaps, behavior undefined with snprintf.
-          sprintf(buf, "%s%-14.14s", buf[0] ? buf : "", cmdlist[n].name);
+          size_t blen = strlen(buf);
+          egg_snprintf(&buf[blen], sizeof(buf) - blen, "%-14.14s", cmdlist[n].name);
           first = 0;
           end = 0;
           i++;
@@ -832,8 +831,8 @@ static void print_users(char *work, int idx, int *cnt, int *tt, int bot, int fla
           (!bot || (bot == 2 && bot_hublevel(u) < 999) || (bot == 1 && bot_hublevel(u) == 999))) {
       if (!*cnt)
         egg_snprintf(work, worksiz, "%-11s: ", str);
-      else
-        simple_snprintf(work, worksiz, "%s, ", work[0] ? work : "");
+      else 
+        strlcat(work, ", ", worksiz);
 
       strlcat(work, u->handle, worksiz);
       (*cnt)++;
@@ -1241,7 +1240,7 @@ static void cmd_chpass(int idx, char *par)
       good = 1;
     } else {
       if (goodpass(newpass, idx, NULL)) {
-        simple_snprintf(pass, sizeof pass, "%s", newpass);
+        strlcpy(pass, newpass, sizeof(pass));
         good = 1;
       }
     }
@@ -1293,9 +1292,8 @@ static void cmd_chsecpass(int idx, char *par)
       if (strlen(newpass) < 6) {
         dprintf(idx, "Please use at least 6 characters.\n");
         return;
-      } else {
-        simple_snprintf(pass, sizeof pass, "%s", newpass);
-      }
+      } else
+        strlcpy(pass, newpass, sizeof(pass));
     }
     if (strlen(pass) > MAXPASSLEN)
       pass[MAXPASSLEN] = 0;

+ 5 - 3
src/core_binds.c

@@ -120,7 +120,7 @@ bool check_aliases(int idx, const char *cmd, const char *args)
       /* Rewrite the cmd including the inserted cmdpass if the cmd has one, and the user provided any param */
       if (argsdup && argsdup[0] && has_cmd_pass(p)) {
         pass = newsplit(&argsdup);
-        simple_snprintf(myargs, size, "%s", pass);
+        strlcpy(myargs, pass, size);
         if (a && a[0]) {
           strlcat(myargs, " ", size);
           strlcat(myargs, a, size);
@@ -132,9 +132,11 @@ bool check_aliases(int idx, const char *cmd, const char *args)
       } else {
         /* Otherwise, just construct it based on cmd and params if provided */
         if (argsdup && argsdup[0]) {
-          simple_snprintf(myargs, size, "%s %s", a, argsdup);
+          strlcpy(myargs, a, size);
+          strlcat(myargs, " ", size);
+          strlcat(myargs, argsdup, size);
         } else 
-          simple_snprintf(myargs, size, "%s", a);
+          strlcpy(myargs, a, size);
       }
 
       if (a && a[0])

+ 1 - 1
src/dcc.c

@@ -1718,7 +1718,7 @@ dcc_telnet_pass(int idx, int atr)
       
       for (i = 0; enclink[i].name; i++) {
         if (enclink[i].type == LINK_CLEARTEXT && !link_cleartext) continue;
-        simple_snprintf(buf, sizeof(buf), "%s%d ", buf[0] ? buf : "", enclink[i].type);
+        simple_snprintf(&buf[strlen(buf)], sizeof(buf) - strlen(buf), "%d ", enclink[i].type);
       }
       dprintf(-dcc[idx].sock, "neg? %s %s\n", rand, buf);
     } else {

+ 29 - 25
src/dccutil.c

@@ -88,14 +88,14 @@ add_cr(char *buf)
   return WBUF;
 }
 
-static void
-colorbuf(char *buf, size_t len, int idx)
+static size_t
+colorbuf(char *buf, size_t len, int idx, size_t bufsiz)
 {
 //  char *buf = *bufp;
   int cidx = coloridx(idx);
   static int cflags;
   int schar = 0;
-  char buf3[1024] = "", buf2[1024] = "", c = 0;
+  char buf3[1024] = "", buf2[15] = "", c = 0;
 
   for (size_t i = 0; i < len; i++) {
     c = buf[i];
@@ -118,33 +118,36 @@ colorbuf(char *buf, size_t len, int idx)
         switch (c) {
           case 'b':
             if (cflags & CFLGS_BOLD) {
-              simple_snprintf(buf2, sizeof(buf2), "%s", BOLD_END(idx));
+              strlcpy(buf2, BOLD_END(idx), sizeof(buf2));
               cflags &= ~CFLGS_BOLD;
             } else {
               cflags |= CFLGS_BOLD;
-              simple_snprintf(buf2, sizeof(buf2), "%s", BOLD(idx));
+              strlcpy(buf2, BOLD(idx), sizeof(buf2));
             }
             break;
           case 'u':
             if (cflags & CFLGS_UNDERLINE) {
-              simple_snprintf(buf2, sizeof(buf2), "%s", UNDERLINE_END(idx));
+              strlcpy(buf2, UNDERLINE_END(idx), sizeof(buf2));
               cflags &= ~CFLGS_UNDERLINE;
             } else {
-              simple_snprintf(buf2, sizeof(buf2), "%s", UNDERLINE(idx));
+              strlcpy(buf2, UNDERLINE(idx), sizeof(buf2));
               cflags |= CFLGS_UNDERLINE;
             }
             break;
           case 'f':
             if (cflags & CFLGS_FLASH) {
-              simple_snprintf(buf2, sizeof(buf2), "%s", FLASH_END(idx));
+              strlcpy(buf2, FLASH_END(idx), sizeof(buf2));
               cflags &= ~CFLGS_FLASH;
             } else {
-              simple_snprintf(buf2, sizeof(buf2), "%s", FLASH(idx));
+              strlcpy(buf2, FLASH(idx), sizeof(buf2));
               cflags |= CFLGS_FLASH;
             }
             break;
           default:
-            simple_snprintf(buf2, sizeof(buf2), "$%c", c);    /* No identifier, put the '$' back in */
+            /* No identifier, put the '$' back in */
+            buf2[0] = '$';
+            buf2[1] = c;
+            buf2[2] = 0;
             break;
         }
       } else {                    /* These are character replacements */
@@ -165,7 +168,8 @@ colorbuf(char *buf, size_t len, int idx)
             simple_snprintf(buf2, sizeof(buf2), "%s%c%s", GREEN(idx), c, COLOR_END(idx));
             break;
           default:
-            simple_snprintf(buf2, sizeof(buf2), "%c", c);
+            buf2[0] = c;
+            buf2[1] = 0;
             break;
         }
       }
@@ -178,7 +182,10 @@ colorbuf(char *buf, size_t len, int idx)
           case 'f':
             break;
           default:
-            simple_snprintf(buf2, sizeof(buf2), "$%c", c);    /* No identifier, put the '$' back in */
+            /* No identifier, put the '$' back in */
+            buf2[0] = '$';
+            buf2[1] = c;
+            buf2[2] = 0;
         }
       } else {
         switch (c) {
@@ -186,15 +193,16 @@ colorbuf(char *buf, size_t len, int idx)
             schar++;
             break;
           default:
-            simple_snprintf(buf2, sizeof(buf2), "%c", c);
+            buf2[0] = c;
+            buf2[1] = 0;
             break;
         }
       }
     }
-    simple_snprintf(buf3, sizeof(buf3), "%s%s", buf3[0] ? buf3 : "", buf2[0] ? buf2 : "");
+    if (buf2[0])
+      strlcat(buf3, buf2, sizeof(buf3));
   }
-  buf3[strlen(buf3)] = 0;
-  strlcpy(buf, buf3, 1024);
+  return strlcpy(buf, buf3, bufsiz);
 }
 
 /* Dump a potentially super-long string of text.
@@ -273,9 +281,7 @@ dprintf(int idx, const char *format, ...)
     tputs(-idx, buf, len);
   } else if (idx > 0x7FF0) {
     if (idx == DP_STDOUT || idx == DP_STDOUT) {
-      colorbuf(buf, len, -1);
-      buf[sizeof(buf) - 1] = 0;
-      len = strlen(buf);
+      len = colorbuf(buf, len, -1, sizeof(buf));
     }
 
     switch (idx) {
@@ -311,14 +317,12 @@ dprintf(int idx, const char *format, ...)
     }
     return;
   } else {                      /* normal chat text */
-    colorbuf(buf, len, idx);
-    buf[sizeof(buf) - 1] = 0;
-    len = strlen(buf);
+    len = colorbuf(buf, len, idx, sizeof(buf));
 
     if (len > 1000) {           /* Truncate to fit */
-      buf[1000] = 0;
-      strlcat(buf, "\n", sizeof(buf));
-      len = 1001;
+      len = 1000;
+      buf[len - 1] = '\n';
+      buf[len] = 0;
     }
     if (dcc[idx].simul >= 0 && !dcc[idx].irc) {
       bounce_simul(idx, buf);

+ 5 - 3
src/log.c

@@ -262,7 +262,7 @@ void putlog(int type, const char *chname, const char *format, ...)
     if (type == last_type && 
         !egg_strncasecmp(chname, last_chname, sizeof(last_chname)) && 
         !egg_strncasecmp(va_out, last_log, sizeof(last_log))) {
-      log_repeats++;
+      ++log_repeats;
 
       return;
     }
@@ -291,9 +291,11 @@ void putlog(int type, const char *chname, const char *format, ...)
 
     egg_strftime(stamp, sizeof(stamp), LOG_TS, t);
     /* Place the timestamp in the string to be printed */
-    simple_snprintf(out, sizeof out, "%s %s", stamp, va_out);
+    strlcpy(out, stamp, sizeof(out));
+    strlcat(out, " ", sizeof(out));
+    strlcat(out, va_out, sizeof(out));
   } else
-    simple_snprintf(out, sizeof out, "%s", va_out);
+    strlcpy(out, va_out, sizeof(out));
 
   /* strcat(out, "\n"); */
 

+ 7 - 5
src/mod/channels.mod/channels.c

@@ -211,7 +211,9 @@ void rcmd_chans(char *fbot, char *fhand, char *fidx) {
   if (server_online) {
     for (chan = chanset; chan; chan = chan->next) {
       if (!channel_active(chan) && (shouldjoin(chan) || chan->channel.jointime)) {
-        simple_snprintf(buf, sizeof(buf), "%s%s%s", buf[0] ? buf : "", buf[0] ? " " : "", chan->dname);
+        if (buf[0])
+          strlcat(buf, " ", sizeof(buf));
+        strlcat(buf, chan->dname, sizeof(buf));
       }
     }
 
@@ -593,7 +595,7 @@ static void set_mode_protect(struct chanset_t *chan, char *set)
     chan->closed_invite = 0;
 }
 
-static void get_mode_protect(struct chanset_t *chan, char *s)
+static void get_mode_protect(struct chanset_t *chan, char *s, size_t ssiz)
 {
   char *p = s, s1[121] = "";
   int tst;
@@ -652,8 +654,8 @@ static void get_mode_protect(struct chanset_t *chan, char *s)
   *p = 0;
   if (s1[0]) {
     s1[strlen(s1) - 1] = 0;
-    strlcat(s, " ", sizeof(s));
-    strlcat(s, s1, sizeof(s));
+    strlcat(s, " ", ssiz);
+    strlcat(s, s1, ssiz);
   }
 }
 
@@ -808,7 +810,7 @@ void channels_report(int idx, int details)
 	s[strlen(s) - 2] = 0;
       if (!s[0])
 	strlcpy(s, "lurking", sizeof(s));
-      get_mode_protect(chan, s2);
+      get_mode_protect(chan, s2, sizeof(s2));
       if (channel_closed(chan)) {
         if (chan->closed_invite)
           strlcat(s2, "i", sizeof(s2));

+ 1 - 1
src/mod/channels.mod/channels.h

@@ -18,7 +18,7 @@
 
 static void check_expired_masks(void);
 static void tell_masks(const char type, int idx, bool show_inact, char *match, bool all = 0);
-static void get_mode_protect(struct chanset_t *chan, char *s);
+static void get_mode_protect(struct chanset_t *chan, char *s, size_t ssiz);
 static void set_mode_protect(struct chanset_t *chan, char *set);
 static int count_mask(maskrec *);
 

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

@@ -1188,7 +1188,7 @@ static void cmd_chaninfo(int idx, char *par)
     } else
       date[0] = 0;
     if (chan->added_by && chan->added_by[0])
-      simple_snprintf(nick, sizeof nick, "%s", chan->added_by);
+      strlcpy(nick, chan->added_by, sizeof(nick));
     else
       nick[0] = 0;
     putlog(LOG_CMDS, "*", "#%s# chaninfo %s", dcc[idx].nick, chname);
@@ -1197,7 +1197,7 @@ static void cmd_chaninfo(int idx, char *par)
     else
       dprintf(idx, "Settings for channel %s:\n", chan->dname);
 /* FIXME: SHOW_CHAR() here */
-    get_mode_protect(chan, work);
+    get_mode_protect(chan, work, sizeof(work));
     dprintf(idx, "Protect modes (chanmode): %s\n", work[0] ? work : "None");
     dprintf(idx, "Protect topic (topic)   : %s\n", chan->topic[0] ? chan->topic : "");
 /* Chanchar template

+ 37 - 31
src/mod/channels.mod/tclchan.c

@@ -277,7 +277,7 @@ int SplitList(char *resultBuf, const char *list, int *argcPtr, const char ***arg
         if (i >= size) {
             free((char *) argv);
             if (resultBuf)
-                simple_snprintf(resultBuf, RESULT_LEN, "internal error in SplitList");
+                strlcpy(resultBuf, "internal error in SplitList", RESULT_LEN);
             return ERROR;
         }
 
@@ -312,13 +312,16 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item,
       old_mode_pls_prot = chan->mode_pls_prot;
   char s[121] = "", result_extra[RESULT_LEN / 2] = "";
 
+  if (result)
+    result[0] = 0;
+
   for (register int i = 0; i < items; i++) {
 /* Chanchar template
     } else if (!strcmp(item[i], "temp")) {
       i++;
       if (i >= items) {
         if (result)
-          simple_snprintf(result, RESULT_LEN, "channel temp needs argument");
+          strlcpy(result, "channel temp needs argument", RESULT_LEN);
         return ERROR;
       }
       strlcpy(chan->temp, item[i], sizeof(chan->temp));
@@ -328,10 +331,10 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item,
       i++;
       if (i >= items) {
 	if (result)
-	  simple_snprintf(result, RESULT_LEN, "channel chanmode needs argument");
+	  strlcpy(result, "channel chanmode needs argument", RESULT_LEN);
 	return ERROR;
       }
-      strlcpy(s, item[i], 121);
+      strlcpy(s, item[i], sizeof(s));
       set_mode_protect(chan, s);
     } else if (!strcmp(item[i], "topic")) {
       char *p = NULL;
@@ -339,17 +342,17 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item,
       i++;
       if (i >= items) {
 	if (result)
-	  simple_snprintf(result, RESULT_LEN, "topic needs argument");
+	  strlcpy(result, "topic needs argument", RESULT_LEN);
 	return ERROR;
       }
       p = replace(item[i], "{", "[");
       p = replace(p, "}", "]");
-      strlcpy(chan->topic, p, 121);
+      strlcpy(chan->topic, p, sizeof(chan->topic));
     } else if (!cmd && !strcmp(item[i], "addedby")) {
       i++;
       if (i >= items) {
 	if (result)
-	  simple_snprintf(result, RESULT_LEN, "addedby needs argument");
+	  strlcpy(result, "addedby needs argument", RESULT_LEN);
 	return ERROR;
       }
       strlcpy(chan->added_by, item[i], NICKLEN);
@@ -357,7 +360,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item,
       i++;
       if (i >= items) {
 	if (result)
-	  simple_snprintf(result, RESULT_LEN, "addedts needs argument");
+	  strlcpy(result, "addedts needs argument", RESULT_LEN);
 	return ERROR;
       }
       chan->added_ts = atoi(item[i]);
@@ -365,7 +368,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item,
       i++;
       if (i >= items) {
         if (result)
-          simple_snprintf(result, RESULT_LEN, "channel limit needs argument");
+          strlcpy(result, "channel limit needs argument", RESULT_LEN);
         return ERROR;
       }
       chan->limitraise = atoi(item[i]);
@@ -375,7 +378,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item,
       i++;
       if (i >= items) {
         if (result)
-          simple_snprintf(result, RESULT_LEN, "channel revenge-mode needs argument");
+          strlcpy(result, "channel revenge-mode needs argument", RESULT_LEN);
         return ERROR;
       }
       chan->revenge_mode = atoi(item[i]);
@@ -384,7 +387,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item,
       i++;
       if (i >= items) {
         if (result)
-          simple_snprintf(result, RESULT_LEN, "channel ban-time needs argument");
+          strlcpy(result, "channel ban-time needs argument", RESULT_LEN);
         return ERROR;
       }
       chan->ban_time = atoi(item[i]);
@@ -392,7 +395,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item,
       i++;
       if (i >= items) {
         if (result)
-          simple_snprintf(result, RESULT_LEN, "channel exempt-time needs argument");
+          strlcpy(result, "channel exempt-time needs argument", RESULT_LEN);
         return ERROR;
       }
       chan->exempt_time = atoi(item[i]);
@@ -400,7 +403,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item,
       i++;
       if (i >= items) {
         if (result)
-          simple_snprintf(result, RESULT_LEN, "channel invite-time needs argument");
+          strlcpy(result, "channel invite-time needs argument", RESULT_LEN);
         return ERROR;
       }
       chan->invite_time = atoi(item[i]);
@@ -408,7 +411,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item,
       i++;
       if (i >= items) {
         if (result)
-          simple_snprintf(result, RESULT_LEN, "channel closed-ban needs argument");
+          strlcpy(result, "channel closed-ban needs argument", RESULT_LEN);
         return ERROR;
       }
       chan->closed_ban = atoi(item[i]);
@@ -416,7 +419,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item,
       i++;
       if (i >= items) {
         if (result)
-          simple_snprintf(result, RESULT_LEN, "channel closed-invite needs argument");
+          strlcpy(result, "channel closed-invite needs argument", RESULT_LEN);
         return ERROR;
       }
       chan->closed_invite = atoi(item[i]);
@@ -426,7 +429,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item,
       i++;
       if (i >= items) {
         if (result)
-          simple_snprintf(result, RESULT_LEN, "channel closed-private needs argument");
+          strlcpy(result, "channel closed-private needs argument", RESULT_LEN);
         return ERROR;
       }
       chan->closed_private = atoi(item[i]);
@@ -436,7 +439,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item,
       i++;
       if (i >= items) {
         if (result)
-          simple_snprintf(result, RESULT_LEN, "channel voice-ident needs argument");
+          strlcpy(result, "channel voice-ident needs argument", RESULT_LEN);
         return ERROR;
       }
       chan->voice_non_ident = atoi(item[i]);
@@ -444,7 +447,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item,
       i++;
       if (i >= items) {
         if (result)
-          simple_snprintf(result, RESULT_LEN, "channel bad-cookie needs argument");
+          strlcpy(result, "channel bad-cookie needs argument", RESULT_LEN);
         return ERROR;
       }
       chan->bad_cookie = deflag_translate(item[i]);
@@ -452,7 +455,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item,
       i++;
       if (i >= items) {
         if (result)
-          simple_snprintf(result, RESULT_LEN, "channel manop needs argument");
+          strlcpy(result, "channel manop needs argument", RESULT_LEN);
         return ERROR;
       }
       chan->manop = deflag_translate(item[i]);
@@ -460,7 +463,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item,
       i++;
       if (i >= items) {
         if (result)
-          simple_snprintf(result, RESULT_LEN, "channel mdop needs argument");
+          strlcpy(result, "channel mdop needs argument", RESULT_LEN);
         return ERROR;
       }
       chan->mdop = deflag_translate(item[i]);
@@ -468,7 +471,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item,
       i++;
       if (i >= items) {
         if (result)
-          simple_snprintf(result, RESULT_LEN, "channel mop needs argument");
+          strlcpy(result, "channel mop needs argument", RESULT_LEN);
         return ERROR;
       }
       chan->mop = deflag_translate(item[i]);
@@ -476,7 +479,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item,
       i++;
       if (i >= items) {
         if (result)
-          simple_snprintf(result, RESULT_LEN, "channel flood-exempt needs argument");
+          strlcpy(result, "channel flood-exempt needs argument", RESULT_LEN);
         return ERROR;
       }
       if (!str_isdigit(item[i])) {
@@ -492,7 +495,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item,
       i++;
       if (i >= items) {
         if (result)
-          simple_snprintf(result, RESULT_LEN, "channel flood-lock-time needs argument");
+          strlcpy(result, "channel flood-lock-time needs argument", RESULT_LEN);
         return ERROR;
       }
       chan->flood_lock_time = atoi(item[i]);
@@ -500,7 +503,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item,
       i++;
       if (i >= items) {
         if (result)
-          simple_snprintf(result, RESULT_LEN, "channel auto-delay needs argument");
+          strlcpy(result, "channel auto-delay needs argument", RESULT_LEN);
         return ERROR;
       }
       chan->auto_delay = atoi(item[i]);
@@ -511,7 +514,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item,
  *    i++;
  *    if (i >= items) {
  *      if (result)
- *        simple_snprintf(result, RESULT_LEN, "channel temp needs argument");
+ *        strlcpy(result, "channel temp needs argument", RESULT_LEN);
  *      return ERROR;
  *    }
  *    chan->temp = atoi(item[i]);
@@ -754,9 +757,13 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item,
         }
       }
     } else {
-      if (result && item[i][0]) /* ignore "" */
-        simple_snprintf(result, RESULT_LEN, "illegal channel option: ");
-        simple_snprintf(result_extra, sizeof(result_extra), "%s %s", result_extra[0] ? result_extra : "", item[i]);
+      if (result && item[i][0]) { /* ignore "" */
+        if (!result[0])
+          strlcpy(result, "illegal channel option: ", RESULT_LEN);
+        if (result_extra[0])
+          strlcat(result_extra, " ", sizeof(result_extra));
+        strlcat(result_extra, item[i], sizeof(result_extra));
+      }
       error = 1;
     }
   }
@@ -871,13 +878,13 @@ int channel_add(char *result, char *newname, char *options)
 {
   if (!newname || !newname[0] || !strchr(CHANMETA, newname[0])) {
     if (result)
-      simple_snprintf(result, RESULT_LEN, "invalid channel prefix");
+      strlcpy(result, "invalid channel prefix", RESULT_LEN);
     return ERROR;
   }
 
   if (strchr(newname, ',') != NULL) {
     if (result)
-      simple_snprintf(result, RESULT_LEN, "invalid channel name");
+      strlcpy(result, "invalid channel name", RESULT_LEN);
     return ERROR;
   }
 
@@ -891,7 +898,6 @@ int channel_add(char *result, char *newname, char *options)
   strlcat(buf, glob_chanset, sizeof(buf));
   strlcat(buf, " ", sizeof(buf));
   strlcat(buf, options, sizeof(buf));
-  buf[strlen(buf)] = 0;
 
   if (SplitList(result, buf, &items, &item) != OK)
     return ERROR;

+ 2 - 2
src/mod/channels.mod/userchan.c

@@ -737,7 +737,7 @@ bool write_chans(FILE *f, int idx)
     char inactive = 0;
 
     putlog(LOG_DEBUG, "*", "writing channel %s to userfile..", chan->dname);
-    get_mode_protect(chan, w);
+    get_mode_protect(chan, w, sizeof(w));
 
     /* if a bot should explicitly NOT join, just set it +inactive ... */
     if (idx >= 0 && !botshouldjoin(dcc[idx].user, chan))
@@ -841,7 +841,7 @@ bool write_chans_compat(FILE *f, int idx)
     char inactive = 0;
 
     putlog(LOG_DEBUG, "*", "writing channel %s to userfile..", chan->dname);
-    get_mode_protect(chan, w);
+    get_mode_protect(chan, w, sizeof(w));
 
     /* if a bot should explicitly NOT join, just set it +inactive ... */
     if (idx >= 0 && !botshouldjoin(dcc[idx].user, chan))

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

@@ -615,7 +615,7 @@ static int ctcp_CHAT(char *nick, char *uhost, struct userrec *u, char *object, c
     return BIND_RET_LOG;
 
     if (u_pass_match(u, "-")) {
-      simple_snprintf(ctcp_reply, sizeof(ctcp_reply), "%s\001ERROR no password set\001", ctcp_reply);
+      strlcat(ctcp_reply, "\001ERROR no password set\001", sizeof(ctcp_reply));
       return BIND_RET_BREAK;
     }
 
@@ -626,7 +626,7 @@ static int ctcp_CHAT(char *nick, char *uhost, struct userrec *u, char *object, c
         ix = i;
     }
     if (dcc_total == max_dcc || (ix < 0 && (ix = listen_all(0, 0)) < 0))
-      simple_snprintf(ctcp_reply, sizeof(ctcp_reply), "%s\001ERROR no telnet port\001", ctcp_reply);
+      strlcat(ctcp_reply, "\001ERROR no telnet port\001", sizeof(ctcp_reply));
     else {
       if (listen_time <= 2)
         listen_time++;

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

@@ -1169,8 +1169,10 @@ static void cmd_getkey(int idx, char *par)
     simple_snprintf(outbuf, sizeof(outbuf), "%s has no key set.", chan->dname);
   else
     simple_snprintf(outbuf, sizeof(outbuf), "Key for %s is: %s", chan->dname, chan->channel.key);
-  if (chan->key_prot[0])
-    simple_snprintf(outbuf, sizeof(outbuf), "%s (Enforcing +k %s)", outbuf, chan->key_prot);
+  if (chan->key_prot[0]) {
+    size_t olen = strlen(outbuf);
+    simple_snprintf(&outbuf[olen], sizeof(outbuf) - olen, " (Enforcing +k %s)", chan->key_prot);
+  }
   dprintf(idx, "%s\n", outbuf);
 }
 

+ 5 - 2
src/mod/irc.mod/msgcmds.c

@@ -675,8 +675,11 @@ static int msgc_help(Auth *a, char *chname, char *par)
 
   for (entry = table->entries; entry && entry->next; entry = entry->next)
     if (((chname && chname[0] && entry->cflags & AUTH_CHAN) || 
-        ((!chname || !chname[0]) && entry->cflags & AUTH_MSG)) && flagrec_ok(&entry->user_flags, &fr))
-      simple_snprintf(outbuf, sizeof(outbuf), "%s%s%s", outbuf[0] ? outbuf : "", outbuf[0] ? " " : "", entry->mask);
+        ((!chname || !chname[0]) && entry->cflags & AUTH_MSG)) && flagrec_ok(&entry->user_flags, &fr)) {
+      if (outbuf[0])
+        strlcat(outbuf, " ", sizeof(outbuf));
+      strlcat(outbuf, entry->mask, sizeof(outbuf));
+    }
 
   strlcat(outbuf, "\n", sizeof(outbuf));
 

+ 5 - 3
src/mod/server.mod/server.c

@@ -428,7 +428,7 @@ static bool fast_deq(int which)
   }
   to = newsplit(&msg);
   len = strlen(to);
-  simple_snprintf(victims, sizeof(victims), "%s", to);
+  strlcpy(victims, to, sizeof(victims));
   while (m) {
     nm = m->next;
     if (!nm)
@@ -445,9 +445,11 @@ static bool fast_deq(int which)
         && (!stack_limit || cmd_count < stack_limit - 1)) {
       cmd_count++;
       if (stack_method == 1)
-      	simple_snprintf(victims, sizeof(victims), "%s,%s", victims, nextto);
+        strlcat(victims, ",", sizeof(victims));
       else
-      	simple_snprintf(victims, sizeof(victims), "%s %s", victims, nextto);
+        strlcat(victims, " ", sizeof(victims));
+      strlcat(victims, nextto, sizeof(victims));
+
       doit = 1;
       m->next = nm->next;
       if (!nm->next)

+ 10 - 12
src/mod/server.mod/servmsg.c

@@ -1323,22 +1323,21 @@ static char *
 hide_chans(const char *nick, struct userrec *u, char *_channels, bool publicOnly)
 {
   char *channels = strdup(_channels), *channels_p = channels;
-  char *chans = NULL, *chname = NULL, s[5] = "";
+  char *chname = NULL;
   size_t len = strlen(channels) + 100 + 1;
   struct chanset_t *chan = NULL;
   struct flag_record fr = { FR_CHAN | FR_GLOBAL, 0, 0, 0 };
 
-  chans = (char *) my_calloc(1, len);
+  char *chans = (char *) my_calloc(1, len), *p = NULL;
 
   while ((chname = newsplit(&channels))[0]) {
-    /* save and skip any modes in front of #chan */
-    s[0] = 0;
-    while (chname[0] && chname[0] != '#') {
-      simple_snprintf(s, sizeof(s), "%s%c", s[0] ? s : "", chname[0]);
-      chname++;
-    }
+    /* skip any modes in front of #chan */
+    if (!(p = strchr(chname, '#')))
+      if (!(p = strchr(chname, '&')))
+        if (!(p = strchr(chname, '!')))
+          continue;
 
-    chan = findchan_by_dname(chname);
+    chan = findchan_by_dname(p);
 
     if (chan && !publicOnly)
      get_user_flagrec(u, &fr, chan->dname, chan);
@@ -1353,9 +1352,8 @@ hide_chans(const char *nick, struct userrec *u, char *_channels, bool publicOnly
         (publicOnly && !(channel_hidden(chan)))
        ) {
       if (chans[0])
-        simple_snprintf(chans, len, "%s %s%s", chans, s, chname);
-      else
-        simple_snprintf(chans, len, "%s%s", s, chname);
+        strlcat(chans, " ", len);
+      strlcat(chans, chname, len);
     }
   }
   free(channels_p);

+ 2 - 1
src/mod/transfer.mod/transfer.c

@@ -485,7 +485,8 @@ void dcc_send(int idx, char *buf, int len)
     fclose(dcc[idx].u.xfer->f);
     siz = strlen(tempdir) + strlen(dcc[idx].u.xfer->filename) + 1;
     b = (char *) my_calloc(1, siz);
-    simple_snprintf(b, siz, "%s%s", tempdir, dcc[idx].u.xfer->filename);
+    strlcpy(b, tempdir, siz);
+    strlcat(b, dcc[idx].u.xfer->filename, siz);
     unlink(b);
     free(b);
     killsock(dcc[idx].sock);

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

@@ -252,12 +252,13 @@ void finish_update(int idx)
     fclose(f);
   }
 
-  simple_snprintf(buf, sizeof(buf), "%s%s", conf.binpath,  strrchr(dcc[idx].u.xfer->filename, '/'));
+  strlcpy(buf, conf.binpath, sizeof(buf));
+  strlcat(buf, strrchr(dcc[idx].u.xfer->filename, '/'), sizeof(buf));
 
   movefile(dcc[idx].u.xfer->filename, buf); 
   fixmod(buf);
 
-  simple_snprintf(buf, sizeof(buf), "%s", strrchr(buf, '/'));
+  strlcpy(buf, strrchr(buf, '/'), sizeof(buf));
   buf2 = buf;
   buf2++;
 

+ 6 - 5
src/set.c

@@ -789,12 +789,13 @@ static char *var_rem_list(const char *botnick, variable_t *var, const char *elem
 
     if ((num && num != i) || (!num && egg_strncasecmp(word, element, elen))) {
       /* Reconstruct the left and right part of the list...*/
-      if (data && data[0] && word && word[0])
-        simple_snprintf(data, tsiz, "%s,%s", data, word);
-      else
-        simple_snprintf(data, tsiz, "%s", word);
+      if (data && data[0] && word && word[0]) {
+        strlcat(data, ",", tsiz);
+        strlcat(data, word, tsiz);
+      } else
+        strlcpy(data, word, tsiz);
     } else  /* minus the part we are removing ... */
-      simple_snprintf(ret, sizeof(ret), "%s", word);
+      strlcpy(ret, word, sizeof(ret));
   }
 
   if (num <= i && ret[0]) {

+ 8 - 15
src/shell.c

@@ -736,32 +736,25 @@ void werr(int errnum)
 int email(char *subject, char *msg, int who)
 {
   struct utsname un;
-  char run[2048] = "", addrs[1024] = "";
-  int mail = 0, sendmail = 0;
+  char run[2048] = "", addrs[100] = "";
+  bool mail = 0, sendmail = 0;
   FILE *f = NULL;
 
   uname(&un);
   if (is_file(STR("/usr/sbin/sendmail")))
-    sendmail++;
+    sendmail = 1;
   else if (is_file(STR("/usr/bin/mail")))
-    mail++;
+    mail = 1;
   else {
     putlog(LOG_WARN, "*", STR("I Have no usable mail client."));
     return 1;
   }
 
-  if (who & EMAIL_OWNERS) {
-    simple_snprintf(addrs, sizeof(addrs), "%s", replace(settings.owneremail, ",", " "));
-  }
-  if (who & EMAIL_TEAM) {
-    if (addrs[0])
-      simple_snprintf(addrs, sizeof(addrs), STR("%s wraith@shatow.net"), addrs);
-    else
-      simple_snprintf(addrs, sizeof(addrs), STR("wraith@shatow.net"));
-  }
+  if (who & EMAIL_OWNERS)
+    strlcpy(addrs, replace(settings.owneremail, ",", " "), sizeof(addrs));
 
   if (sendmail)
-    simple_snprintf(run, sizeof(run), STR("/usr/sbin/sendmail -t"));
+    strlcpy(run, STR("/usr/sbin/sendmail -t"), sizeof(run));
   else if (mail)
     simple_snprintf(run, sizeof(run), STR("/usr/bin/mail %s -a \"From: %s@%s\" -s \"%s\" -a \"Content-Type: text/plain\""), addrs, conf.bot->nick ? conf.bot->nick : "none", un.nodename, subject);
 
@@ -875,7 +868,7 @@ char *my_username()
     pw = getpwuid(myuid);
     ContextNote(STR("getpwuid(): Success"));
     if (pw)
-      simple_snprintf(username, sizeof username, "%s", pw->pw_name);
+      strlcpy(username, pw->pw_name, sizeof(username));
 #endif /* CYGWIN_HACKS */
   }
   return username[0] ? username : NULL;

+ 0 - 1
src/shell.h

@@ -25,7 +25,6 @@
 #define ERR_MAX         23
 
 #define EMAIL_OWNERS    BIT0
-#define EMAIL_TEAM      BIT1
 
 #define DETECT_LOGIN 	1
 #define DETECT_TRACE 	2

+ 1 - 1
src/userrec.c

@@ -327,7 +327,7 @@ int u_pass_match(struct userrec *u, char *in)
 
   char *cmp = (char *) get_user(&USERENTRY_PASS, u), pass[MAXPASSLEN + 1] = "";
 
-  simple_snprintf(pass, sizeof pass, "%s", in);
+  strlcpy(pass, in, sizeof(pass));
 
   if (!cmp && (!pass[0] || (pass[0] == '-')))
     return 1;