Просмотр исходного кода

* Converted a bunch of sprintf() to simple_sprintf() which is much smaller/faster and only accepts %s/%i/%d

svn: 1990
Bryan Drewery 21 лет назад
Родитель
Сommit
a8c8d21fdb

+ 1 - 0
src/Makefile.in

@@ -46,6 +46,7 @@ OBJS = auth.o \
 	rfc1459.o \
 	shell.o \
 	socket.o \
+	sprintf.o \
 	tclhash.o \
 	userent.o \
 	userrec.o \

+ 8 - 8
src/binary.c

@@ -467,13 +467,13 @@ void conf_to_bin(conf_t *in, bool move, int die)
 
   clear_settings();
   sdprintf("converting conf to bin\n");
-  sprintf(settings.uid, "%d", in->uid);
-  sprintf(settings.watcher, "%d", in->watcher);
-  sprintf(settings.autocron, "%d", in->autocron);
-  sprintf(settings.autouname, "%d", in->autouname);
-  sprintf(settings.portmin, "%d", in->portmin);
-  sprintf(settings.portmax, "%d", in->portmax);
-  sprintf(settings.pscloak, "%d", in->pscloak);
+  simple_sprintf(settings.uid, "%d", in->uid);
+  simple_sprintf(settings.watcher, "%d", in->watcher);
+  simple_sprintf(settings.autocron, "%d", in->autocron);
+  simple_sprintf(settings.autouname, "%d", in->autouname);
+  simple_sprintf(settings.portmin, "%d", in->portmin);
+  simple_sprintf(settings.portmax, "%d", in->portmax);
+  simple_sprintf(settings.pscloak, "%d", in->pscloak);
 
   strlcpy(settings.binname, in->binname, 16);
   strlcpy(settings.username, in->username, 16);
@@ -482,7 +482,7 @@ void conf_to_bin(conf_t *in, bool move, int die)
   strlcpy(settings.homedir, in->homedir, 350);
   strlcpy(settings.binpath, in->binpath, 350);
   for (bot = in->bots; bot && bot->nick; bot = bot->next) {
-    sprintf(settings.bots, "%s%s %s %s%s %s,", settings.bots && settings.bots[0] ? settings.bots : "",
+    simple_sprintf(settings.bots, "%s%s %s %s%s %s,", settings.bots && settings.bots[0] ? settings.bots : "",
                            bot->nick,
                            bot->net.ip ? bot->net.ip : ".", 
                            bot->net.host6 ? "+" : "", 

+ 8 - 8
src/botcmd.c

@@ -85,13 +85,13 @@ static void bot_chan2(int idx, char *msg)
   for (p = from; *p;) {
     if ((*p < 32) || (*p == 127))
 /* FIXME: overlap      strcpy(p, p + 1); */
-      sprintf(p, "%s", p + 1);
+      simple_sprintf(p, "%s", p + 1);
     else
       p++;
   }
   p = strchr(from, '@');
   if (p) {
-    sprintf(TBUF, "<%s> %s", from, msg);
+    simple_sprintf(TBUF, "<%s> %s", from, msg);
     *p = 0;
     if (!partyidle(p + 1, from)) {
       *p = '@';
@@ -101,7 +101,7 @@ static void bot_chan2(int idx, char *msg)
     *p = '@';
     p++;
   } else {
-    sprintf(TBUF, "*** (%s) %s", from, msg);
+    simple_sprintf(TBUF, "*** (%s) %s", from, msg);
     p = from;
   }
   i = nextbot(p);
@@ -241,7 +241,7 @@ static void bot_actchan(int idx, char *par)
   chan = base64_to_int(p);
   for (p = from; *p;) {
     if ((*p < 32) || (*p == 127))
-      sprintf(p, "%s", p + 1);
+      simple_sprintf(p, "%s", p + 1);
 /* FIXME: overlap      strcpy(p, p + 1); */
     else
       p++;
@@ -346,7 +346,7 @@ static void remote_tell_who(int idx, char *nick, int chan)
       l = strlen(c->dname);
       if (i + l < 1021) {
 	if (i > 10) {
-          sprintf(s, "%s, %s", s, c->dname);
+          simple_sprintf(s, "%s, %s", s, c->dname);
 	} else {
           strcpy(s, c->dname);
 	  i += (l + 2);
@@ -458,7 +458,7 @@ static void bot_who(int idx, char *par)
   from = newsplit(&par);
   p = strchr(from, '@');
   if (!p) {
-    sprintf(TBUF, "%s@%s", from, dcc[idx].nick);
+    simple_sprintf(TBUF, "%s@%s", from, dcc[idx].nick);
     from = TBUF;
   }
   to = newsplit(&par);
@@ -976,7 +976,7 @@ static void bot_join(int idx, char *par)
   }
   u = get_user_by_handle(userlist, nick);
   if (u) {
-    sprintf(TBUF, "@%s", bot);
+    simple_sprintf(TBUF, "@%s", bot);
     touch_laston(u, TBUF, now);
   }
   i = addparty(bot, nick, chan, y[0], sock, par, &i2);
@@ -1010,7 +1010,7 @@ static void bot_part(int idx, char *par)
 
   u = get_user_by_handle(userlist, nick);
   if (u) {
-    sprintf(TBUF, "@%s", bot);
+    simple_sprintf(TBUF, "@%s", bot);
     touch_laston(u, TBUF, now);
   }
   if ((partyidx = getparty(bot, sock)) != -1) {

+ 5 - 139
src/botmsg.c

@@ -28,140 +28,6 @@
 
 static char	OBUF[SGRAB - 110] = "";
 
-
-/* Thank you ircu :) */
-static char tobase64array[64] =
-{
-  'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
-  'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
-  'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
-  'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
-  '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
-  '[', ']'
-};
-
-char *int_to_base64(unsigned int val)
-{
-  static char buf_base64[12] = "";
-
-  buf_base64[11] = 0;
-  if (!val) {
-    buf_base64[10] = 'A';
-    return buf_base64 + 10;
-  }
-
-  int i = 11;
-
-  while (val) {
-    i--;
-    buf_base64[i] = tobase64array[val & 0x3f];
-    val = val >> 6;
-  }
-
-  return buf_base64 + i;
-}
-
-char *int_to_base10(int val)
-{
-  static char buf_base10[17] = "";
-
-  buf_base10[16] = 0;
-  if (!val) {
-    buf_base10[15] = '0';
-    return buf_base10 + 15;
-  }
-
-  int p = 0;
-  int i = 16;
-
-  if (val < 0) {
-    p = 1;
-    val *= -1;
-  }
-  while (val) {
-    i--;
-    buf_base10[i] = '0' + (val % 10);
-    val /= 10;
-  }
-  if (p) {
-    i--;
-    buf_base10[i] = '-';
-  }
-  return buf_base10 + i;
-}
-
-char *unsigned_int_to_base10(unsigned int val)
-{
-  static char buf_base10[16] = "";
-
-  buf_base10[15] = 0;
-  if (!val) {
-    buf_base10[14] = '0';
-    return buf_base10 + 14;
-  }
-
-  int i = 15;
-
-  while (val) {
-    i--;
-    buf_base10[i] = '0' + (val % 10);
-    val /= 10;
-  }
-  return buf_base10 + i;
-}
-
-size_t simple_sprintf (char *buf, const char *format, ...)
-{
-  char *s = NULL;
-  char *fp = (char *) format;
-  size_t c = 0;
-  unsigned int i;
-  va_list va;
-  
-  va_start(va, format);
-
-  while (*fp && c < 1023) {
-    if (*fp == '%') {
-      fp++;
-      switch (*fp) {
-      case 's':
-	s = va_arg(va, char *);
-	break;
-      case 'd':
-      case 'i':
-	i = va_arg(va, int);
-	s = int_to_base10(i);
-	break;
-      case 'D':
-	i = va_arg(va, int);
-	s = int_to_base64((unsigned int) i);
-	break;
-      case 'u':
-	i = va_arg(va, unsigned int);
-        s = unsigned_int_to_base10(i);
-	break;
-      case '%':
-	buf[c++] = *fp++;
-	continue;
-      case 'c':
-	buf[c++] = (char) va_arg(va, int);
-	fp++;
-	continue;
-      default:
-	continue;
-      }
-      if (s)
-	while (*s && c < 1023)
-	  buf[c++] = *s++;
-      fp++;
-    } else
-      buf[c++] = *fp++;
-  }
-  va_end(va);
-  buf[c] = 0;
-  return c;
-}
-
 /* Ditto for tandem bots
  */
 static void send_tand_but(int x, char *buf, size_t len)
@@ -178,7 +44,7 @@ void botnet_send_cmdpass(int idx, char *cmd, char *pass)
   if (tands > 0) {
     char *buf = (char *) my_calloc(1, strlen(cmd) + strlen(pass) + 5 + 1);
 
-    sprintf(buf, "cp %s %s\n", cmd, pass);
+    simple_sprintf(buf, "cp %s %s\n", cmd, pass);
     send_tand_but(idx, buf, strlen(buf));
     free(buf);
   }
@@ -194,7 +60,7 @@ int botnet_send_cmd(char * fbot, char * bot, char *fhnd, int fromidx, char * cmd
   } else if (!strcmp(bot, conf.bot->nick)) {
     char tmp[24] = "";
 
-    sprintf(tmp, "%i", fromidx);
+    simple_sprintf(tmp, "%i", fromidx);
     gotremotecmd(conf.bot->nick, conf.bot->nick, fhnd, tmp, cmd);
   }
   return 0;
@@ -208,7 +74,7 @@ void botnet_send_cmd_broad(int idx, char * fbot, char *fhnd, int fromidx, char *
   if (idx < 0) {
     char tmp[24] = "";
 
-    sprintf(tmp, "%i", fromidx);
+    simple_sprintf(tmp, "%i", fromidx);
     gotremotecmd("*", conf.bot->nick, fhnd, tmp, cmd);
   }
 }
@@ -544,7 +410,7 @@ int add_note(char *to, char *from, char *msg, int idx, int echo)
       if (strchr(from, '@')) {
 	strcpy(botf, from);
       } else
-	sprintf(botf, "%s@%s", from, conf.bot->nick);
+	simple_sprintf(botf, "%s@%s", from, conf.bot->nick);
     } else
       strcpy(botf, conf.bot->nick);
     i = nextbot(p);
@@ -556,7 +422,7 @@ int add_note(char *to, char *from, char *msg, int idx, int echo)
     if ((idx >= 0) && (echo))
       dprintf(idx, "-> %s@%s: %s\n", x, p, msg);
     if (idx >= 0) {
-      sprintf(ssf, "%d:%s", dcc[idx].sock, botf);
+      simple_sprintf(ssf, "%d:%s", dcc[idx].sock, botf);
       botnet_send_priv(i, ssf, x, p, "%s", msg);
     } else
       botnet_send_priv(i, botf, x, p, "%s", msg);

+ 0 - 4
src/botmsg.h

@@ -18,10 +18,6 @@ void botnet_send_cfg_broad(int idx, struct cfg_entry *entry);
 void putbot(char *, char *);
 void putallbots(char *);
 int add_note(char *, char *, char *, int, int);
-size_t simple_sprintf (char *, const char *, ...);
-char *int_to_base10(int);
-char *unsigned_int_to_base10(unsigned int);
-char *int_to_base64(unsigned int);
 
 #endif /* !_BOTMSG_H */
 

+ 6 - 6
src/botnet.c

@@ -657,9 +657,9 @@ void tell_bottree(int idx)
             color_str = (char *) NULL;
 
           if (bot->share)
-            i = sprintf(s, "%c", bot->share);
+            i = simple_sprintf(s, "%c", bot->share);
           else
-            i = sprintf(s, "-");
+            i = simple_sprintf(s, "-");
           i = sprintf(s + 1, "%s%s%s (%s %li)", color_str ? color_str : "",
                                                 bot->bot,
                                                 color_str ? COLOR_END(idx) : "",
@@ -703,9 +703,9 @@ void tell_bottree(int idx)
 
 		bot2 = bot;
                 if (bot->share)
-                  i = sprintf(s, "%c", bot->share);
+                  i = simple_sprintf(s, "%c", bot->share);
                 else
-                  i = sprintf(s, "-");
+                  i = simple_sprintf(s, "-");
                 i = sprintf(s + 1, "%s%s%s (%s %li)", color_str ? color_str : "",
                                                       bot->bot,
                                                       color_str ? COLOR_END(idx) : "",
@@ -1506,12 +1506,12 @@ static void dcc_relaying(int idx, char *buf, int j)
 
 static void display_relay(int i, char *other)
 {
-  sprintf(other, "rela  -> sock %d", dcc[i].u.relay->sock);
+  simple_sprintf(other, "rela  -> sock %d", dcc[i].u.relay->sock);
 }
 
 static void display_relaying(int i, char *other)
 {
-  sprintf(other, ">rly  -> sock %d", dcc[i].u.relay->sock);
+  simple_sprintf(other, ">rly  -> sock %d", dcc[i].u.relay->sock);
 }
 
 static void display_tandem_relay(int i, char *other)

+ 4 - 4
src/cfg.c

@@ -183,11 +183,11 @@ void deflag_user(struct userrec *u, int why, char *msg, struct chanset_t *chan)
     which = chan->mop;
     break;
   default:
-    sprintf(tmp, "Reason #%i", why);
+    simple_sprintf(tmp, "Reason #%i", why);
   }
   if (which == P_DEOP) {
     putlog(LOG_WARN, "*",  "Setting %s +d (%s): %s", u->handle, tmp, msg);
-    sprintf(tmp2, "+d: %s (%s)", tmp, msg);
+    simple_sprintf(tmp2, "+d: %s (%s)", tmp, msg);
     set_user(&USERENTRY_COMMENT, u, tmp2);
     get_user_flagrec(u, &fr, chan->dname);
     fr.global = USER_DEOP;
@@ -195,7 +195,7 @@ void deflag_user(struct userrec *u, int why, char *msg, struct chanset_t *chan)
     set_user_flagrec(u, &fr, chan->dname);
   } else if (which == P_KICK) {
     putlog(LOG_WARN, "*",  "Setting %s +dk (%s): %s", u->handle, tmp, msg);
-    sprintf(tmp2, "+dk: %s (%s)", tmp, msg);
+    simple_sprintf(tmp2, "+dk: %s (%s)", tmp, msg);
     set_user(&USERENTRY_COMMENT, u, tmp2);
     get_user_flagrec(u, &fr, chan->dname);
     fr.global = USER_DEOP | USER_KICK;
@@ -206,7 +206,7 @@ void deflag_user(struct userrec *u, int why, char *msg, struct chanset_t *chan)
     deluser(u->handle);
   } else {
     putlog(LOG_WARN, "*",  "No user flag effects for %s (%s): %s", u->handle, tmp, msg);
-    sprintf(tmp2, "Warning: %s (%s)", tmp, msg);
+    simple_sprintf(tmp2, "Warning: %s (%s)", tmp, msg);
     set_user(&USERENTRY_COMMENT, u, tmp2);
   }
 }

+ 4 - 4
src/chanprog.c

@@ -226,7 +226,7 @@ void tell_verbose_uptime(int idx)
   now2 = now - online_since;
   if (now2 > 86400) {
     /* days */
-    sprintf(s, "%d day", (int) (now2 / 86400));
+    simple_sprintf(s, "%d day", (int) (now2 / 86400));
     if ((int) (now2 / 86400) >= 2)
       strcat(s, "s");
     strcat(s, ", ");
@@ -282,7 +282,7 @@ void tell_verbose_status(int idx)
   s[0] = 0;
   if (now2 > 86400) {
     /* days */
-    sprintf(s, "%d day", (int) (now2 / 86400));
+    simple_sprintf(s, "%d day", (int) (now2 / 86400));
     if ((int) (now2 / 86400) >= 2)
       strcat(s, "s");
     strcat(s, ", ");
@@ -313,7 +313,7 @@ void tell_verbose_status(int idx)
   min = (int) (cl - (hr * 60));
   sprintf(s2, "CPU %02d:%02d", (int) hr, (int) min);	/* Actually min/sec */
 # else
-  sprintf(s2, "CPU ???");
+  simple_sprintf(s2, "CPU ???");
 # endif
 #endif /* HAVE_GETRUSAGE */
   dprintf(idx, "%s %s  (%s)  %s  %s %4.1f%%\n", MISC_ONLINEFOR,
@@ -498,7 +498,7 @@ void load_internal_users()
               hosts = q;
             }
             
-            sprintf(x, "-telnet!%s", hosts);
+            simple_sprintf(x, "-telnet!%s", hosts);
 	    set_user(&USERENTRY_HOSTS, u, x);
 	    hosts = ln;
 	  }

+ 1 - 0
src/common.h

@@ -13,6 +13,7 @@
 #endif
 
 #include "garble.h"
+#include "sprintf.h"
 #include "conf.h"
 #include "debug.h"
 #include "eggdrop.h"

+ 1 - 1
src/crypt.c

@@ -137,7 +137,7 @@ static char *passkey()
 
   char *tmp = my_calloc(1, 512);
 
-  sprintf(tmp, "%s-%s.%s!%s", settings.salt1, settings.salt2, settings.packname, settings.bdhash);
+  simple_sprintf(tmp, "%s-%s.%s!%s", settings.salt1, settings.salt2, settings.packname, settings.bdhash);
   key = SHA1(tmp);
   free(tmp);
   egg_bzero(tmp, 512);

+ 9 - 9
src/dcc.c

@@ -479,7 +479,7 @@ display_dcc_bot(int idx, char *buf)
 static void
 display_dcc_fork_bot(int idx, char *buf)
 {
-  sprintf(buf, "conn  bot");
+  simple_sprintf(buf, "conn  bot");
 }
 
 struct dcc_table DCC_BOT = {
@@ -531,7 +531,7 @@ eof_dcc_identd(int idx)
 static void
 display_dcc_identd(int idx, char *buf)
 {
-  sprintf(buf, "idtd  %d%s", dcc[idx].port, (dcc[idx].status & LSTN_PUBLIC) ? " pub" : "");
+  simple_sprintf(buf, "idtd  %d%s", dcc[idx].port, (dcc[idx].status & LSTN_PUBLIC) ? " pub" : "");
 }
 
 struct dcc_table DCC_IDENTD = {
@@ -1259,7 +1259,7 @@ dcc_telnet(int idx, char *buf, int ii)
 
   putlog(LOG_DEBUG, "*", "Telnet connection: %s/%d", s, port);
 
-  sprintf(x, "-telnet!telnet@%s", iptostr(htonl(ip)));
+  simple_sprintf(x, "-telnet!telnet@%s", iptostr(htonl(ip)));
 
   if (match_ignore(x) || detect_telnet_flood(x)) {
     killsock(sock);
@@ -1307,7 +1307,7 @@ static void dcc_telnet_dns_callback(int id, void *client_data, const char *ip, c
 
   strlcpy(dcc[i].host, hosts ? hosts[0] : ip, UHOSTLEN);
 
-  sprintf(s2, "-telnet!telnet@%s", dcc[i].host);
+  simple_sprintf(s2, "-telnet!telnet@%s", dcc[i].host);
 
   if (match_ignore(s2)) {
     killsock(dcc[i].sock);
@@ -1364,7 +1364,7 @@ static void dcc_telnet_dns_callback(int id, void *client_data, const char *ip, c
   }
   if (s[0]) {
     putlog(LOG_MISC, "*", DCC_IDENTFAIL, dcc[i].host, s);
-    sprintf(s, "telnet@%s", dcc[i].host);
+    simple_sprintf(s, "telnet@%s", dcc[i].host);
     dcc_telnet_got_ident(i, s);
     return;
   }
@@ -1390,7 +1390,7 @@ eof_dcc_telnet(int idx)
 static void
 display_telnet(int idx, char *buf)
 {
-  sprintf(buf, "lstn  %d%s", dcc[idx].port, (dcc[idx].status & LSTN_PUBLIC) ? " pub" : "");
+  simple_sprintf(buf, "lstn  %d%s", dcc[idx].port, (dcc[idx].status & LSTN_PUBLIC) ? " pub" : "");
 }
 
 struct dcc_table DCC_TELNET = {
@@ -1444,7 +1444,7 @@ timeout_dupwait(int idx)
 static void
 display_dupwait(int idx, char *buf)
 {
-  sprintf(buf, "wait  duplicate?");
+  simple_sprintf(buf, "wait  duplicate?");
 }
 
 static void
@@ -1598,7 +1598,7 @@ dcc_telnet_pass(int idx, int atr)
       link_hash(idx, rand);
 
       for (i = 0; enclink[i].name; i++)
-        sprintf(buf, "%s%d ", buf[0] ? buf : "", enclink[i].type);
+        simple_sprintf(buf, "%s%d ", buf[0] ? buf : "", enclink[i].type);
 
       dprintf(idx, "neg? %s %s\n", rand, buf);
     } else
@@ -1757,7 +1757,7 @@ eof_dcc_ident(int idx)
 static void
 display_dcc_ident(int idx, char *buf)
 {
-  sprintf(buf, "idnt  (sock %d)", dcc[idx].u.ident_sock);
+  simple_sprintf(buf, "idnt  (sock %d)", dcc[idx].u.ident_sock);
 }
 
 struct dcc_table DCC_IDENT = {

+ 14 - 14
src/dccutil.c

@@ -86,33 +86,33 @@ colorbuf(char *buf, size_t len, int idx)
         switch (c) {
           case 'b':
             if (cflags & CFLGS_BOLD) {
-              sprintf(buf2, "%s", BOLD_END(idx));
+              simple_sprintf(buf2, "%s", BOLD_END(idx));
               cflags &= ~CFLGS_BOLD;
             } else {
               cflags |= CFLGS_BOLD;
-              sprintf(buf2, "%s", BOLD(idx));
+              simple_sprintf(buf2, "%s", BOLD(idx));
             }
             break;
           case 'u':
             if (cflags & CFLGS_UNDERLINE) {
-              sprintf(buf2, "%s", UNDERLINE_END(idx));
+              simple_sprintf(buf2, "%s", UNDERLINE_END(idx));
               cflags &= ~CFLGS_UNDERLINE;
             } else {
-              sprintf(buf2, "%s", UNDERLINE(idx));
+              simple_sprintf(buf2, "%s", UNDERLINE(idx));
               cflags |= CFLGS_UNDERLINE;
             }
             break;
           case 'f':
             if (cflags & CFLGS_FLASH) {
-              sprintf(buf2, "%s", FLASH_END(idx));
+              simple_sprintf(buf2, "%s", FLASH_END(idx));
               cflags &= ~CFLGS_FLASH;
             } else {
-              sprintf(buf2, "%s", FLASH(idx));
+              simple_sprintf(buf2, "%s", FLASH(idx));
               cflags |= CFLGS_FLASH;
             }
             break;
           default:
-            sprintf(buf2, "$%c", c);    /* No identifier, put the '$' back in */
+            simple_sprintf(buf2, "$%c", c);    /* No identifier, put the '$' back in */
             break;
         }
       } else {                    /* These are character replacements */
@@ -121,19 +121,19 @@ colorbuf(char *buf, size_t len, int idx)
             schar++;
             break;
           case ':':
-            sprintf(buf2, "%s%c%s", LIGHTGREY(idx), c, COLOR_END(idx));
+            simple_sprintf(buf2, "%s%c%s", LIGHTGREY(idx), c, COLOR_END(idx));
             break;
           case '@':
-            sprintf(buf2, "%s%c%s", BOLD(idx), c, BOLD_END(idx));
+            simple_sprintf(buf2, "%s%c%s", BOLD(idx), c, BOLD_END(idx));
             break;
           case '>':
           case ')':
           case '<':
           case '(':
-            sprintf(buf2, "%s%c%s", GREEN(idx), c, COLOR_END(idx));
+            simple_sprintf(buf2, "%s%c%s", GREEN(idx), c, COLOR_END(idx));
             break;
           default:
-            sprintf(buf2, "%c", c);
+            simple_sprintf(buf2, "%c", c);
             break;
         }
       }
@@ -146,7 +146,7 @@ colorbuf(char *buf, size_t len, int idx)
           case 'f':
             break;
           default:
-            sprintf(buf2, "$%c", c);    /* No identifier, put the '$' back in */
+            simple_sprintf(buf2, "$%c", c);    /* No identifier, put the '$' back in */
         }
       } else {
         switch (c) {
@@ -154,12 +154,12 @@ colorbuf(char *buf, size_t len, int idx)
             schar++;
             break;
           default:
-            sprintf(buf2, "%c", c);
+            simple_sprintf(buf2, "%c", c);
             break;
         }
       }
     }
-    sprintf(buf3, "%s%s", (buf3 && buf3[0]) ? buf3 : "", (buf2 && buf2[0]) ? buf2 : "");
+    simple_sprintf(buf3, "%s%s", (buf3 && buf3[0]) ? buf3 : "", (buf2 && buf2[0]) ? buf2 : "");
   }
   buf3[strlen(buf3)] = 0;
   strcpy(buf, buf3);

+ 2 - 2
src/main.c

@@ -274,8 +274,8 @@ static void show_help()
 }
 
 // leaf: BkLP
-#define PARSE_FLAGS STR("0234:aB:c:Cd:De:Eg:G:k:L:P:hnr:stu:U:v")
-#define FLAGS_CHECKPASS STR("CdDeEgGhknrtuUv")
+#define PARSE_FLAGS STR("0234:aB:c:Cd:De:Ek:L:P:hnr:stu:U:v")
+#define FLAGS_CHECKPASS STR("CdDeEhknrtuUv")
 static void dtx_arg(int argc, char *argv[])
 {
   int i = 0;

+ 12 - 12
src/misc.c

@@ -264,7 +264,7 @@ void maskhost(const char *s, char *nw)
 	  x = p;
 	else
 	  x = e;
-	sprintf(nw, "*%s", x);
+	simple_sprintf(nw, "*%s", x);
       }
     }
   }
@@ -279,7 +279,7 @@ void daysago(time_t mynow, time_t then, char *out)
   if (mynow - then > 86400) {
     int mydays = (mynow - then) / 86400;
 
-    sprintf(out, "%d day%s ago", mydays, (mydays == 1) ? "" : "s");
+    simple_sprintf(out, "%d day%s ago", mydays, (mydays == 1) ? "" : "s");
     return;
   }
   egg_strftime(out, 6, "%H:%M", gmtime(&then));
@@ -293,7 +293,7 @@ void days(time_t mynow, time_t then, char *out)
   if (mynow - then > 86400) {
     int mydays = (mynow - then) / 86400;
 
-    sprintf(out, "in %d day%s", mydays, (mydays == 1) ? "" : "s");
+    simple_sprintf(out, "in %d day%s", mydays, (mydays == 1) ? "" : "s");
     return;
   }
   egg_strftime(out, 9, "at %H:%M", gmtime(&now));
@@ -307,7 +307,7 @@ void daysdur(time_t mynow, time_t then, char *out)
   if (mynow - then > 86400) {
     int mydays = (mynow - then) / 86400;
 
-    sprintf(out, "for %d day%s", mydays, (mydays == 1) ? "" : "s");
+    simple_sprintf(out, "for %d day%s", mydays, (mydays == 1) ? "" : "s");
     return;
   }
 
@@ -578,7 +578,7 @@ restart(int idx)
   }
   fatal(idx <= 0x7FF0 ? reason : NULL, 1);
   usleep(2000 * 500);
-  sprintf(buf, "%s -B %s\n", binname, conf.bot->nick);
+  simple_sprintf(buf, "%s -B %s\n", binname, conf.bot->nick);
   unlink(conf.bot->pid_file); /* if this fails it is ok, cron will restart the bot, *hopefully* */
   system(buf); /* start new bot. */
   exit(0);
@@ -680,7 +680,7 @@ int updatebin(int idx, char *par, int secs)
     size_t binsize = strlen(tmpdir) + 7 + 1;
     char *tmpbuf = (char *) my_calloc(1, binsize);
 
-    sprintf(tmpbuf, "%sbin.old.exe", tmpdir);
+    simple_sprintf(tmpbuf, "%sbin.old.exe", tmpdir);
     tmpbuf[binsize - 1] = 0;
     movefile(binname, tmpbuf);
     free(tmpbuf);
@@ -747,7 +747,7 @@ int goodpass(char *pass, int idx, char *nick)
   int nalpha = 0, lcase = 0, ucase = 0, ocase = 0, tc;
 
   if (strchr(BADPASSCHARS, pass[0])) {
-    sprintf(tell, "Passes may not begin with '-'");
+    simple_sprintf(tell, "Passes may not begin with '-'");
     goto fail;
   }
 
@@ -766,7 +766,7 @@ int goodpass(char *pass, int idx, char *nick)
 /*  if (ocase < 1 || lcase < 2 || ucase < 2 || nalpha < 1 || strlen(pass) < 8) { */
   if (lcase < 2 || ucase < 2 || strlen(pass) < 8) {
 
-    sprintf(tell, "Insecure pass, must be: ");
+    simple_sprintf(tell, "Insecure pass, must be: ");
     if (ocase < 1)
       strcat(tell, "\002>= 1 number\002, ");
     else
@@ -847,7 +847,7 @@ void showhelp(int idx, struct flag_record *flags, char *string)
         }
         flagstr[0] = 0;
         while (*string && *string != '}') {
-          sprintf(tmp, "%c", *string);
+          simple_sprintf(tmp, "%c", *string);
           strcat(flagstr, tmp);
           string++;
         }
@@ -856,7 +856,7 @@ void showhelp(int idx, struct flag_record *flags, char *string)
         if (flagrec_ok(&fr, flags)) {
           ok = 1;
           while (*string && *string != '%') {
-            sprintf(tmp, "%c", *string);
+            simple_sprintf(tmp, "%c", *string);
             strcat(helpstr, tmp);
             string++;
           }
@@ -888,14 +888,14 @@ void showhelp(int idx, struct flag_record *flags, char *string)
         strcat(helpstr, "%");        
       } else {
         if (ok) {
-          sprintf(tmp, "%c", *string);
+          simple_sprintf(tmp, "%c", *string);
           strcat(helpstr, tmp);
         }
         string++;
       }
     } else {
       if (ok) {
-        sprintf(tmp, "%c", *string);
+        simple_sprintf(tmp, "%c", *string);
         strcat(helpstr, tmp);
       }
       string++;

+ 2 - 2
src/misc_file.c

@@ -159,7 +159,7 @@ Tempfile::Tempfile()
 {
   len = strlen(tempdir) + 1 + 6 + 1;
   file = new char[len];
-  sprintf(file, "%s.XXXXXX", tempdir);
+  simple_sprintf(file, "%s.XXXXXX", tempdir);
 
   MakeTemp();
 }
@@ -168,7 +168,7 @@ Tempfile::Tempfile(const char *prefix)
 {
   len = strlen(tempdir) + 1 + strlen(prefix) + 1 + 6 + 1;
   file = new char[len];
-  sprintf(file, "%s.%s-XXXXXX", tempdir, prefix);
+  simple_sprintf(file, "%s.%s-XXXXXX", tempdir, prefix);
 
   MakeTemp();
 }

+ 3 - 3
src/mod/channels.mod/channels.c

@@ -335,7 +335,7 @@ static void rebalance_roles()
         ba = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, dcc[i].user);
         if (ba && (ba->roleid == (hNdx + 1))) {
           ba->roleid = lNdx + 1;
-          sprintf(tmp, "rl %d", lNdx + 1);
+          simple_sprintf(tmp, "rl %d", lNdx + 1);
           putbot(dcc[i].nick, tmp);
         }
       }
@@ -563,11 +563,11 @@ static void get_mode_protect(struct chanset_t *chan, char *s)
 	*p++ = '+';
       if (chan->limit_prot != 0) {
 	*p++ = 'l';
-	sprintf(&s1[strlen(s1)], "%d ", chan->limit_prot);
+	simple_sprintf(&s1[strlen(s1)], "%d ", chan->limit_prot);
       }
       if (chan->key_prot[0]) {
 	*p++ = 'k';
-	sprintf(&s1[strlen(s1)], "%s ", chan->key_prot);
+	simple_sprintf(&s1[strlen(s1)], "%s ", chan->key_prot);
       }
     } else {
       tst = chan->mode_mns_prot;

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

@@ -520,7 +520,7 @@ static void cmd_slowjoin(int idx, char *par)
     dprintf(idx, "Hmmm... Channel didn't get added. Weird *shrug*\n");
     return;
   }
-  sprintf(buf2, "cjoin %s %s", chan->dname, buf);
+  simple_sprintf(buf2, "cjoin %s %s", chan->dname, buf);
   putallbots(buf2);
   if (conf.bot->hub)
     count = 0;
@@ -533,12 +533,12 @@ static void cmd_slowjoin(int idx, char *par)
     if (ubot) {
       /* Variation: 60 secs intvl should be 60 +/- 15 */
       if (bot_hublevel(ubot) < 999) {
-	sprintf(tmp, "sj %s 0\n", chan->dname);
+	simple_sprintf(tmp, "sj %s 0\n", chan->dname);
       } else {
 	int v = (random() % (intvl / 2)) - (intvl / 4);
 
 	delay += intvl;
-	sprintf(tmp, "sj %s %i\n", chan->dname, delay + v);
+	simple_sprintf(tmp, "sj %s %i\n", chan->dname, delay + v);
 	count++;
       }
       putbot(ubot->handle, tmp);
@@ -596,12 +596,12 @@ static void cmd_slowpart(int idx, char *par)
       /* Variation: 60 secs intvl should be 60 +/- 15 */
       if (ubot) {
         if (bot_hublevel(ubot) < 999) {
-  	  sprintf(tmp, "sp %s 0\n", chname);
+  	  simple_sprintf(tmp, "sp %s 0\n", chname);
         } else {
   	  int v = (random() % (intvl / 2)) - (intvl / 4);
 
   	  delay += intvl;
-  	  sprintf(tmp, "sp %s %i\n", chname, delay + v);
+  	  simple_sprintf(tmp, "sp %s %i\n", chname, delay + v);
   	  count++;
         }
         putbot(ubot->handle, tmp);
@@ -924,7 +924,7 @@ static void cmd_down(int idx, char *par)
     return;
   }
   
-  sprintf(buf2, "down %s", chan->dname);
+  simple_sprintf(buf2, "down %s", chan->dname);
   putallbots(buf2);
   if (!conf.bot->hub) {
     add_mode(chan, '-', 'o', botname);
@@ -946,7 +946,7 @@ static void pls_chan(int idx, char *par, char *bot)
   }
 
   chname = newsplit(&par);
-  sprintf(buf, "cjoin %s %s", chname, bot ? bot : "*");		/* +chan makes all bots join */
+  simple_sprintf(buf, "cjoin %s %s", chname, bot ? bot : "*");		/* +chan makes all bots join */
   if (par[0]) {
     strcat(buf, " ");
     strcat(buf, par);
@@ -1034,7 +1034,7 @@ static void mns_chan(int idx, char *par, char *bot)
   }
   chname = newsplit(&par);
 
-  sprintf(buf2, "cpart %s %s", chname, bot ? bot : "*");
+  simple_sprintf(buf2, "cpart %s %s", chname, bot ? bot : "*");
   if (bot)		/* bot will just set it +inactive */
     putbot(bot, buf2);
   else
@@ -1103,7 +1103,7 @@ void show_flag(int idx, char *work, int *cnt, const char *name, unsigned int sta
     work[0] = 0;
   }
   if (!work[0])
-    sprintf(work, "  ");
+    simple_sprintf(work, "  ");
   if (name && name[0]) {
     chr_state[0] = 0;
     if (state) {
@@ -1135,7 +1135,7 @@ void show_int(int idx, char *work, int *cnt, const char *desc, int state, const
     work[0] = 0;
   }
   if (!work[0])
-    sprintf(work, "  ");
+    simple_sprintf(work, "  ");
   /* need to make next line all one char, and then put it into %-30s */
   if (desc && desc[0]) {
     char tmp2[50] = "", tmp3[50] = "";

+ 27 - 27
src/mod/channels.mod/tclchan.c

@@ -160,12 +160,12 @@ static int FindElement(char *resultBuf, const char *list, size_t listLength,
     if (p == limit) {
         if (openBraces != 0) {
             if (resultBuf) {
-                sprintf(resultBuf, "unmatched open brace in list");
+                simple_sprintf(resultBuf, "unmatched open brace in list");
             }
             return ERROR;
         } else if (inQuotes) {
             if (resultBuf) {
-                sprintf(resultBuf, "unmatched open quote in list");
+                simple_sprintf(resultBuf, "unmatched open quote in list");
             }
             return ERROR;
         }
@@ -257,7 +257,7 @@ int SplitList(char *resultBuf, const char *list, int *argcPtr, const char ***arg
         if (i >= size) {
             free((char *) argv);
             if (resultBuf)
-                sprintf(resultBuf, "internal error in SplitList");
+                simple_sprintf(resultBuf, "internal error in SplitList");
             return ERROR;
         }
 
@@ -298,7 +298,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item)
       i++;
       if (i >= items) {
         if (result)
-          sprintf(result, "channel temp needs argument");
+          simple_sprintf(result, "channel temp needs argument");
         return ERROR;
       }
       strlcpy(chan->temp, item[i], sizeof(chan->temp));
@@ -308,7 +308,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item)
       i++;
       if (i >= items) {
 	if (result)
-	  sprintf(result, "channel chanmode needs argument");
+	  simple_sprintf(result, "channel chanmode needs argument");
 	return ERROR;
       }
       strlcpy(s, item[i], 121);
@@ -319,7 +319,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item)
       i++;
       if (i >= items) {
 	if (result)
-	  sprintf(result, "topic needs argument");
+	  simple_sprintf(result, "topic needs argument");
 	return ERROR;
       }
       p = replace(item[i], "{", "[");
@@ -329,7 +329,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item)
       i++;
       if (i >= items) {
 	if (result)
-	  sprintf(result, "addedby needs argument");
+	  simple_sprintf(result, "addedby needs argument");
 	return ERROR;
       }
       strlcpy(chan->added_by, item[i], NICKLEN);
@@ -337,7 +337,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item)
       i++;
       if (i >= items) {
 	if (result)
-	  sprintf(result, "addedts needs argument");
+	  simple_sprintf(result, "addedts needs argument");
 	return ERROR;
       }
       chan->added_ts = atoi(item[i]);
@@ -345,7 +345,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item)
       i++;
       if (i >= items) {
 	if (result)
-	  sprintf(result, "channel idle-kick needs argument");
+	  simple_sprintf(result, "channel idle-kick needs argument");
 	return ERROR;
       }
       chan->idle_kick = atoi(item[i]);
@@ -353,7 +353,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item)
       i++;
       if (i >= items) {
         if (result)
-          sprintf(result, "channel limit needs argument");
+          simple_sprintf(result, "channel limit needs argument");
         return ERROR;
       }
       chan->limitraise = atoi(item[i]);
@@ -364,7 +364,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item)
       i++;
       if (i >= items) {
 	if (result)
-	  sprintf(result, "channel stopnethack-mode needs argument");
+	  simple_sprintf(result, "channel stopnethack-mode needs argument");
 	return ERROR;
       }
       chan->stopnethack_mode = atoi(item[i]);
@@ -372,7 +372,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item)
       i++;
       if (i >= items) {
         if (result)
-          sprintf(result, "channel revenge-mode needs argument");
+          simple_sprintf(result, "channel revenge-mode needs argument");
         return ERROR;
       }
       chan->revenge_mode = atoi(item[i]);
@@ -380,7 +380,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item)
       i++;
       if (i >= items) {
         if (result)
-          sprintf(result, "channel ban-time needs argument");
+          simple_sprintf(result, "channel ban-time needs argument");
         return ERROR;
       }
       chan->ban_time = atoi(item[i]);
@@ -388,7 +388,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item)
       i++;
       if (i >= items) {
         if (result)
-          sprintf(result, "channel exempt-time needs argument");
+          simple_sprintf(result, "channel exempt-time needs argument");
         return ERROR;
       }
       chan->exempt_time = atoi(item[i]);
@@ -396,7 +396,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item)
       i++;
       if (i >= items) {
         if (result)
-          sprintf(result, "channel invite-time needs argument");
+          simple_sprintf(result, "channel invite-time needs argument");
         return ERROR;
       }
       chan->invite_time = atoi(item[i]);
@@ -404,7 +404,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item)
       i++;
       if (i >= items) {
         if (result)
-          sprintf(result, "channel closed-ban needs argument");
+          simple_sprintf(result, "channel closed-ban needs argument");
         return ERROR;
       }
       chan->closed_ban = atoi(item[i]);
@@ -412,7 +412,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item)
       i++;
       if (i >= items) {
         if (result)
-          sprintf(result, "channel closed-invite needs argument");
+          simple_sprintf(result, "channel closed-invite needs argument");
         return ERROR;
       }
       chan->closed_invite = atoi(item[i]);
@@ -420,7 +420,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item)
       i++;
       if (i >= items) {
         if (result)
-          sprintf(result, "channel closed-private needs argument");
+          simple_sprintf(result, "channel closed-private needs argument");
         return ERROR;
       }
       chan->closed_private = atoi(item[i]);
@@ -428,7 +428,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item)
       i++;
       if (i >= items) {
         if (result)
-          sprintf(result, "channel bad-cookie needs argument");
+          simple_sprintf(result, "channel bad-cookie needs argument");
         return ERROR;
       }
       chan->bad_cookie = deflag_translate(item[i]);
@@ -436,7 +436,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item)
       i++;
       if (i >= items) {
         if (result)
-          sprintf(result, "channel mdop needs argument");
+          simple_sprintf(result, "channel mdop needs argument");
         return ERROR;
       }
       chan->mdop = deflag_translate(item[i]);
@@ -444,7 +444,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item)
       i++;
       if (i >= items) {
         if (result)
-          sprintf(result, "channel mop needs argument");
+          simple_sprintf(result, "channel mop needs argument");
         return ERROR;
       }
       chan->mop = deflag_translate(item[i]);
@@ -453,7 +453,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item)
  *    i++;
  *    if (i >= items) {
  *      if (result)
- *        sprintf(result, "channel temp needs argument");
+ *        simple_sprintf(result, "channel temp needs argument");
  *      return ERROR;
  *    }
  *    chan->temp = atoi(item[i]);
@@ -604,13 +604,13 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item)
 	ptime = &chan->flood_nick_time;
       } else {
 	if (result)
-	  sprintf(result, "illegal channel flood type: %s", item[i]);
+	  simple_sprintf(result, "illegal channel flood type: %s", item[i]);
 	return ERROR;
       }
       i++;
       if (i >= items) {
 	if (result)
-	  sprintf(result, "%s needs argument", item[i - 1]);
+	  simple_sprintf(result, "%s needs argument", item[i - 1]);
 	return ERROR;
       }
       p = strchr(item[i], ':');
@@ -625,7 +625,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item)
       }
     } else {
       if (result && item[i][0]) /* ignore "" */
-        sprintf(result, "illegal channel option: %s", item[i]);
+        simple_sprintf(result, "illegal channel option: %s", item[i]);
       error = 1;
     }
   }
@@ -737,13 +737,13 @@ int channel_add(char *result, char *newname, char *options)
 {
   if (!newname || !newname[0] || !strchr(CHANMETA, newname[0])) {
     if (result)
-      sprintf(result, "invalid channel prefix");
+      simple_sprintf(result, "invalid channel prefix");
     return ERROR;
   }
 
   if (strchr(newname, ',') != NULL) {
     if (result)
-      sprintf(result, "invalid channel name");
+      simple_sprintf(result, "invalid channel name");
     return ERROR;
   }
 

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

@@ -367,7 +367,7 @@ static void display_mask(const char type, int idx, int number, maskrec *mask, st
 
   if (mask->added) {
     daysago(now, mask->added, s);
-    sprintf(dates, "%s %s", MODES_CREATED, s);
+    simple_sprintf(dates, "%s %s", MODES_CREATED, s);
     if (mask->added < mask->lastactive) {
       strcat(dates, ", ");
       strcat(dates, MODES_LASTUSED);
@@ -383,7 +383,7 @@ static void display_mask(const char type, int idx, int number, maskrec *mask, st
     char s1[41] = "";
 
     days(mask->expire, now, s1);
-    sprintf(s, "(expires %s)", s1);
+    simple_sprintf(s, "(expires %s)", s1);
   }
   if (mask->flags & MASKREC_STICKY)
     strcat(s, " (sticky)");
@@ -486,9 +486,9 @@ static void tell_masks(const char type, int idx, bool show_inact, char *match)
 	  s2 = s;
 	  s1 = splitnick(&s2);
 	  if (s1[0])
-	    sprintf(fill, "%s (%s!%s)", ml->mask, s1, s2);
+	    simple_sprintf(fill, "%s (%s!%s)", ml->mask, s1, s2);
 	  else
-	    sprintf(fill, "%s (server %s)", ml->mask, s2);
+	    simple_sprintf(fill, "%s (server %s)", ml->mask, s2);
 	  if (ml->timer != 0) {
 	    min = (now - ml->timer) / 60;
 	    sec = (now - ml->timer) - (min * 60);

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

@@ -50,23 +50,23 @@ void scriptchanged()
   
   switch (cloak_script) {
   case CLOAK_PLAIN:
-    sprintf(ctcpversion, "\002BitchX-%s\002 by panasync - %s %s : \002Keep it to yourself!\002", cloak_bxver, cloak_os, cloak_osver);
+    simple_sprintf(ctcpversion, "\002BitchX-%s\002 by panasync - %s %s : \002Keep it to yourself!\002", cloak_bxver, cloak_os, cloak_osver);
     strcpy(ctcpuserinfo, "");
     strcpy(autoaway, "Auto-Away after 10 mins");
     strcpy(kickprefix, "");
     strcpy(bankickprefix, "");
     break;
   case CLOAK_CRACKROCK:
-    sprintf(ctcpversion, "BitchX-%s\002/\002%s %s:(\002c\002)\037rackrock\037/\002b\002X \037[\0373.0.1á9\037]\037 :\002 Keep it to yourself!\002", cloak_bxver, cloak_os, cloak_osver);
+    simple_sprintf(ctcpversion, "BitchX-%s\002/\002%s %s:(\002c\002)\037rackrock\037/\002b\002X \037[\0373.0.1á9\037]\037 :\002 Keep it to yourself!\002", cloak_bxver, cloak_os, cloak_osver);
     strcpy(ctcpuserinfo, "crack addict, help me.");
     strcpy(autoaway, "automatically dead");
     strcpy(kickprefix, "\002c\002/\037k\037: ");
     strcpy(bankickprefix, "\002c\002/\037kb\037: ");
     break;
   case CLOAK_NEONAPPLE:
-    sprintf(tmp, "%s %s", cloak_os, cloak_osver);
+    simple_sprintf(tmp, "%s %s", cloak_os, cloak_osver);
     strtolower(tmp);
-    sprintf(ctcpversion, "bitchx-%s\037(\037%s\037):\037 \002n\002eon\037a\037ppl\002e\002\037/\037\002v\0020\037.\03714i : \002d\002ont you wish you had it\037?\037", cloak_bxver, tmp);
+    simple_sprintf(ctcpversion, "bitchx-%s\037(\037%s\037):\037 \002n\002eon\037a\037ppl\002e\002\037/\037\002v\0020\037.\03714i : \002d\002ont you wish you had it\037?\037", cloak_bxver, tmp);
     strcpy(ctcpuserinfo, "neon apple");
     strcpy(autoaway, "automatically away after 10 mins \037(\037\002n\002/\037a)\037");
     strcpy(kickprefix, "\037[na\002(\037k\037)\002]\037 ");
@@ -80,28 +80,28 @@ void scriptchanged()
     p[0] = '\037';
     p[2] = '\037';
     p[3] = 0;
-    sprintf(ctcpversion, "\002b\002itchx-%s :tunnel\002vision\002/\0371.2\037", tmp);
+    simple_sprintf(ctcpversion, "\002b\002itchx-%s :tunnel\002vision\002/\0371.2\037", tmp);
     strcpy(ctcpuserinfo, "");
     strcpy(autoaway, "auto-gone");
     strcpy(kickprefix, "");
     strcpy(bankickprefix, "");
     break;
   case CLOAK_ARGON:
-    sprintf(ctcpversion, ".\037.(\037argon\002/\0021g\037)\037 \002:\002bitchx-%s", cloak_bxver);
+    simple_sprintf(ctcpversion, ".\037.(\037argon\002/\0021g\037)\037 \002:\002bitchx-%s", cloak_bxver);
     strcpy(ctcpuserinfo, "");
     strcpy(autoaway, "\037(\037ar\037)\037 auto-away \037(\03710m\037)\037");
     strcpy(kickprefix, "\037(\037ar\037)\037 ");
     strcpy(bankickprefix, "\037(\037ar\037)\037 ");
     break;
   case CLOAK_EVOLVER:
-    sprintf(ctcpversion, "\037evolver\037(\00202x9\002)\037: bitchx\037(\002%s\002) \037í\037 %s\002/\002%s : eye yam pheerable now!", cloak_bxver, cloak_os, cloak_osver);
+    simple_sprintf(ctcpversion, "\037evolver\037(\00202x9\002)\037: bitchx\037(\002%s\002) \037í\037 %s\002/\002%s : eye yam pheerable now!", cloak_bxver, cloak_os, cloak_osver);
     strcpy(ctcpuserinfo, "");
     strcpy(autoaway, "[\037\002i\002dle for \037[\03710 minutes\037]]");
     strcpy(kickprefix, "\037ev\002!\002k\037 ");
     strcpy(bankickprefix, "\037ev\002!\002bk\037 ");
     break;
   case CLOAK_PREVAIL:
-    sprintf(ctcpversion, "%s\037!\037%s bitchx-%s \002-\002 prevail\037[\0370123\037]\037 :down with people", cloak_os, cloak_osver, cloak_bxver);
+    simple_sprintf(ctcpversion, "%s\037!\037%s bitchx-%s \002-\002 prevail\037[\0370123\037]\037 :down with people", cloak_os, cloak_osver, cloak_bxver);
     strcpy(ctcpuserinfo, botrealname);
     strcpy(autoaway, "idle 10 minutes \037-\037 gone\037!\037");
     strcpy(kickprefix, "\037[\037pv\037!\037k\037]\037 ");
@@ -112,7 +112,7 @@ void scriptchanged()
     char mircver[5] = "";
    
     strcpy(mircver, response(RES_MIRCVER));
-    sprintf(ctcpversion, "mIRC v%s Khaled Mardam-Bey", mircver);
+    simple_sprintf(ctcpversion, "mIRC v%s Khaled Mardam-Bey", mircver);
     if (randint(2) % 2)
       strcpy(ctcpversion2, response(RES_MIRCSCRIPT));
     strcpy(ctcpuserinfo, botrealname);
@@ -192,68 +192,68 @@ void scriptchanged()
     }
     switch (randint(16)) {
     case 0:
-      sprintf(ctcpversion, "bitchx\037-\037%s \037/\037 cypress\037.\03701i%s", cloak_bxver, theme);
+      simple_sprintf(ctcpversion, "bitchx\037-\037%s \037/\037 cypress\037.\03701i%s", cloak_bxver, theme);
       break;
     case 1:
-      sprintf(ctcpversion, "cypress\037.\03701i%s \037/\037 bitchx\037-\037%s", theme, cloak_bxver);
+      simple_sprintf(ctcpversion, "cypress\037.\03701i%s \037/\037 bitchx\037-\037%s", theme, cloak_bxver);
       break;
     case 2:
-      sprintf(tmp, "%s %s", cloak_os, cloak_osver);
+      simple_sprintf(tmp, "%s %s", cloak_os, cloak_osver);
       strtolower(tmp);
-      sprintf(ctcpversion, "cypress\037.\03701i%s %s\037(\037%s\037)\037 bitchx\037-\037%s)", theme, tmp, cloak_host, cloak_bxver);
+      simple_sprintf(ctcpversion, "cypress\037.\03701i%s %s\037(\037%s\037)\037 bitchx\037-\037%s)", theme, tmp, cloak_host, cloak_bxver);
       break;
     case 3:
-      sprintf(tmp, "%s %s", cloak_os, cloak_osver);
+      simple_sprintf(tmp, "%s %s", cloak_os, cloak_osver);
       strtolower(tmp);
-      sprintf(ctcpversion, "bitchx\037-\037%s %s\037(\037%s\037)\037 cypress\037.\03701i%s", cloak_bxver, tmp, cloak_host, theme);
+      simple_sprintf(ctcpversion, "bitchx\037-\037%s %s\037(\037%s\037)\037 cypress\037.\03701i%s", cloak_bxver, tmp, cloak_host, theme);
       break;
     case 4:
-      sprintf(ctcpversion, "%s\002/\002%s: BitchX-%s \002[\002cypress\002]\002 v01i%s", cloak_os, cloak_osver, cloak_bxver, theme);
+      simple_sprintf(ctcpversion, "%s\002/\002%s: BitchX-%s \002[\002cypress\002]\002 v01i%s", cloak_os, cloak_osver, cloak_bxver, theme);
       break;
     case 5:
       p = replace(cloak_osver, ".", "\037.\037");
-      sprintf(tmp, "%s %s", cloak_os, p);
+      simple_sprintf(tmp, "%s %s", cloak_os, p);
       strtolower(tmp);
-      sprintf(ctcpversion, "\037.\037.cypress\037.\03701i%s %s\037(\037%s\037)\037 bitchx\037/\037%s",theme, tmp, cloak_host, cloak_bxver);
+      simple_sprintf(ctcpversion, "\037.\037.cypress\037.\03701i%s %s\037(\037%s\037)\037 bitchx\037/\037%s",theme, tmp, cloak_host, cloak_bxver);
       break;
     case 6:
       p = replace(cloak_osver, ".", "\037.\037");
-      sprintf(tmp, "%s %s", cloak_os, p);
+      simple_sprintf(tmp, "%s %s", cloak_os, p);
       strtolower(tmp);
-      sprintf(ctcpversion, "cypress\002.\00201i%s\037(\037bitchx\002.\002%s\037)\037\002.\002. %s\037(\037%s\037)\037",theme, cloak_bxver, tmp, cloak_host);
+      simple_sprintf(ctcpversion, "cypress\002.\00201i%s\037(\037bitchx\002.\002%s\037)\037\002.\002. %s\037(\037%s\037)\037",theme, cloak_bxver, tmp, cloak_host);
       break;
     case 7:
       p = replace(cloak_osver, ".", "\037.\037");
-      sprintf(tmp, "%s %s", cloak_os, p);
+      simple_sprintf(tmp, "%s %s", cloak_os, p);
       strtolower(tmp);
-      sprintf(ctcpversion, "\037.\037.cypress\037.\03701i%s - bitchx\037.\037%s\002/\002%s", theme, cloak_bxver, tmp);
+      simple_sprintf(ctcpversion, "\037.\037.cypress\037.\03701i%s - bitchx\037.\037%s\002/\002%s", theme, cloak_bxver, tmp);
       break;
     case 8:
-      sprintf(ctcpversion, "\002BitchX-%s\002 by panasync \002-\002 %s %s", cloak_bxver, cloak_os, cloak_osver);
+      simple_sprintf(ctcpversion, "\002BitchX-%s\002 by panasync \002-\002 %s %s", cloak_bxver, cloak_os, cloak_osver);
       break;
     case 9:
-      sprintf(ctcpversion, "\037[\037cypress\002/\00201i\037]\037 - %s \037[\037bx\002/\002%s\037]\037", theme, cloak_bxver);
+      simple_sprintf(ctcpversion, "\037[\037cypress\002/\00201i\037]\037 - %s \037[\037bx\002/\002%s\037]\037", theme, cloak_bxver);
       break;
     case 10:
-      sprintf(ctcpversion, "\037[\037\002b\002itchx\002.\002%s\037]\037 \002+\002 \037[\037cypress\002.\00201i\037]\037 %s",cloak_bxver, theme);
+      simple_sprintf(ctcpversion, "\037[\037\002b\002itchx\002.\002%s\037]\037 \002+\002 \037[\037cypress\002.\00201i\037]\037 %s",cloak_bxver, theme);
       break;
     case 11:
-      sprintf(ctcpversion, "\037[\037BitchX\002/\002%s\037(\037cypress\002/\00201i\037)]\037 %s", cloak_bxver, theme);
+      simple_sprintf(ctcpversion, "\037[\037BitchX\002/\002%s\037(\037cypress\002/\00201i\037)]\037 %s", cloak_bxver, theme);
       break;
     case 12:
       strtolower(cloak_os);
-      sprintf(ctcpversion, "bitchx\037/\037%s %s %s \037(\037cypress\037/\03701i\037)\037 %s", cloak_bxver, cloak_os, cloak_osver, theme);
+      simple_sprintf(ctcpversion, "bitchx\037/\037%s %s %s \037(\037cypress\037/\03701i\037)\037 %s", cloak_bxver, cloak_os, cloak_osver, theme);
       break;
     case 13:
-      sprintf(ctcpversion, "\037.\037.cypress\037/\03701i\037!\037bitchx\037/\037%s\037.\037.%s", cloak_bxver, theme);
+      simple_sprintf(ctcpversion, "\037.\037.cypress\037/\03701i\037!\037bitchx\037/\037%s\037.\037.%s", cloak_bxver, theme);
       break;
     case 14:
       strtolower(cloak_bxver);
-      sprintf(ctcpversion, "cypress\002\037.\037\002\037.\03701i\002/\002bitchx\037.\037\002\037.\037\002%s%s", cloak_bxver, theme);
+      simple_sprintf(ctcpversion, "cypress\002\037.\037\002\037.\03701i\002/\002bitchx\037.\037\002\037.\037\002%s%s", cloak_bxver, theme);
       break;
     case 15:
       strtolower(cloak_bxver);
-      sprintf(ctcpversion, "cypress\037.\03701i\037/\037bx%s \037(\037%s\037)\037", cloak_bxver, theme);
+      simple_sprintf(ctcpversion, "cypress\037.\03701i\037/\037bx%s \037(\037%s\037)\037", cloak_bxver, theme);
       break;
     }
     strcpy(ctcpuserinfo, "");
@@ -284,47 +284,47 @@ void sendaway()
     break;
   case CLOAK_CRACKROCK:
     if (hrs)
-      sprintf(awtime, "%dh %dm %ds", hrs, min, sec);
+      simple_sprintf(awtime, "%dh %dm %ds", hrs, min, sec);
     else if (min)
-      sprintf(awtime, "%dm %ds", min, sec);
+      simple_sprintf(awtime, "%dm %ds", min, sec);
     else
-      sprintf(awtime, "%ds", sec);
+      simple_sprintf(awtime, "%ds", sec);
     dprintf(DP_HELP, "AWAY :%s\002\037[\002%s\002]\037\002\n", autoaway, awtime);
     break;
   case CLOAK_TUNNELVISION:
     if (hrs)
-      sprintf(awtime, "%dh%dm%ds", hrs, min, sec);
+      simple_sprintf(awtime, "%dh%dm%ds", hrs, min, sec);
     else if (min)
-      sprintf(awtime, "%dm%ds", min, sec);
+      simple_sprintf(awtime, "%dm%ds", min, sec);
     else
-      sprintf(awtime, "%ds", sec);
+      simple_sprintf(awtime, "%ds", sec);
     dprintf(DP_HELP, "AWAY :%s \037(\037%s\037)\037\n", autoaway, awtime);
     break;
   case CLOAK_ARGON:
     if (hrs)
-      sprintf(awtime, "%dh%dm%ds", hrs, min, sec);
+      simple_sprintf(awtime, "%dh%dm%ds", hrs, min, sec);
     else if (min)
-      sprintf(awtime, "%dm%ds", min, sec);
+      simple_sprintf(awtime, "%dm%ds", min, sec);
     else
-      sprintf(awtime, "%ds", sec);
+      simple_sprintf(awtime, "%ds", sec);
     dprintf(DP_HELP, "AWAY :%s .\002.\002\037(\037%s\037)\037\n", autoaway, awtime);
     break;
   case CLOAK_EVOLVER:
     if (hrs)
-      sprintf(awtime, "%dh %dm %ds", hrs, min, sec);
+      simple_sprintf(awtime, "%dh %dm %ds", hrs, min, sec);
     else if (min)
-      sprintf(awtime, "%dm %ds", min, sec);
+      simple_sprintf(awtime, "%dm %ds", min, sec);
     else
-      sprintf(awtime, "%ds", sec);
+      simple_sprintf(awtime, "%ds", sec);
     dprintf(DP_HELP, "AWAY :away\037: %s (\037l\002:\002off\037,\037 p\002:\002off\037)\037 \037[\037gone\002:\002%s\037]\037\n", autoaway, awtime);
     break;
   case CLOAK_PREVAIL:
     if (hrs)
-      sprintf(awtime, "%dh%dm%ds", hrs, min, sec);
+      simple_sprintf(awtime, "%dh%dm%ds", hrs, min, sec);
     else if (min)
-      sprintf(awtime, "%dm%ds", min, sec);
+      simple_sprintf(awtime, "%dm%ds", min, sec);
     else
-      sprintf(awtime, "%ds", sec);
+      simple_sprintf(awtime, "%ds", sec);
     dprintf(DP_HELP, "AWAY :%s %s\n", autoaway, awtime);
     break;
   case CLOAK_CYPRESS:

+ 17 - 16
src/mod/irc.mod/chan.c

@@ -113,9 +113,9 @@ static char *getchanmode(struct chanset_t *chan)
     s[i++] = 'l';
   s[i] = 0;
   if (chan->channel.key[0])
-    i += sprintf(s + i, " %s", chan->channel.key);
+    i += simple_sprintf(s + i, " %s", chan->channel.key);
   if (chan->channel.maxmembers != 0)
-    sprintf(s + i, " %d", chan->channel.maxmembers);
+    simple_sprintf(s + i, " %d", chan->channel.maxmembers);
   return s;
 }
 
@@ -146,11 +146,12 @@ void priority_do(struct chanset_t * chan, bool opsonly, int action)
   int ops = 0, targets = 0, bpos = 0, tpos = 0, ft = 0, ct = 0, actions = 0, sent = 0;
 
   for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
-    if (!m->user) {
+    if (!m->user && !m->tried_getuser) {
       char s[256] = "";
 
-      sprintf(s, "%s!%s", m->nick, m->userhost);
+      simple_sprintf(s, "%s!%s", m->nick, m->userhost);
       m->user = get_user_by_host(s);
+      m->tried_getuser = 1;
     }
 
     if (m->user && m->user->bot && (m->user->flags & USER_OP)) {
@@ -485,7 +486,7 @@ static bool detect_chan_flood(char *floodnick, char *floodhost, char *from,
       if (!channel_enforcebans(chan) && me_op(chan)) {
 	  char s[UHOSTLEN];
 	  for (m = chan->channel.member; m && m->nick[0]; m = m->next) {	  
-	    sprintf(s, "%s!%s", m->nick, m->userhost);
+	    simple_sprintf(s, "%s!%s", m->nick, m->userhost);
 	    if (wild_match(h, s) &&
 		(m->joined >= chan->floodtime[which]) &&
 		!chan_sentkick(m) && !match_my_nick(m->nick) && me_op(chan)) {
@@ -516,7 +517,7 @@ static bool detect_chan_flood(char *floodnick, char *floodhost, char *from,
       if (u) {
         char s[256] = "";
 
-        sprintf(s, "Mass deop on %s by %s", chan->dname, from);
+        simple_sprintf(s, "Mass deop on %s by %s", chan->dname, from);
         deflag_user(u, DEFLAG_MDOP, s, chan);
       }
       return 1;
@@ -533,7 +534,7 @@ static void doban(struct chanset_t *chan, memberlist *m)
 
   char s[UHOSTLEN] = "", *s1 = NULL;
 
-  sprintf(s, "%s!%s", m->nick, m->userhost);
+  simple_sprintf(s, "%s!%s", m->nick, m->userhost);
 
   if (!(use_exempts &&
         (u_match_mask(global_exempts,s) ||
@@ -575,7 +576,7 @@ static void kick_all(struct chanset_t *chan, char *hostmask, const char *comment
   struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
 
   for (memberlist *m = chan->channel.member; m && m->nick[0]; m = m->next) {
-    sprintf(s, "%s!%s", m->nick, m->userhost);
+    simple_sprintf(s, "%s!%s", m->nick, m->userhost);
     get_user_flagrec(m->user ? m->user : get_user_by_host(s), &fr, chan->dname);
     if (me_op(chan) &&
 	(wild_match(hostmask, s) || match_cidr(hostmask, s)) && 
@@ -616,7 +617,7 @@ static void refresh_ban_kick(struct chanset_t *chan, char *user, char *nick)
 	char c[512] = "";		/* The ban comment.	*/
 	char s[UHOSTLEN] = "";
 
-	sprintf(s, "%s!%s", m->nick, m->userhost);
+	simple_sprintf(s, "%s!%s", m->nick, m->userhost);
 	get_user_flagrec(m->user ? m->user : get_user_by_host(s), &fr,
 			 chan->dname);
         if (role == 1)
@@ -811,7 +812,7 @@ void check_this_ban(struct chanset_t *chan, char *banmask, bool sticky)
   char user[UHOSTLEN] = "";
 
   for (memberlist *m = chan->channel.member; m && m->nick[0]; m = m->next) {
-    sprintf(user, "%s!%s", m->nick, m->userhost);
+    simple_sprintf(user, "%s!%s", m->nick, m->userhost);
     if (wild_match(banmask, user) &&
         !(use_exempts &&
           (u_match_mask(global_exempts, user) ||
@@ -908,7 +909,7 @@ void recheck_channel_modes(struct chanset_t *chan)
     if ((chan->limit_prot != 0) && (chan->channel.maxmembers == 0)) {
       char s[50] = "";
 
-      sprintf(s, "%d", chan->limit_prot);
+      simple_sprintf(s, "%d", chan->limit_prot);
       add_mode(chan, '+', 'l', s);
     } else if ((mns & CHANLIMIT) && (chan->channel.maxmembers != 0))
       add_mode(chan, '-', 'l', "");
@@ -956,7 +957,7 @@ static void check_this_member(struct chanset_t *chan, char *nick, struct flag_re
     }
   }
 
-  sprintf(s, "%s!%s", m->nick, m->userhost);
+  simple_sprintf(s, "%s!%s", m->nick, m->userhost);
   /* check vs invites */
   if (use_invites &&
       (u_match_mask(global_invites,s) ||
@@ -989,7 +990,7 @@ void check_this_user(char *hand, int del, char *host)
 
   for (struct chanset_t *chan = chanset; chan; chan = chan->next)
     for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
-      sprintf(s, "%s!%s", m->nick, m->userhost);
+      simple_sprintf(s, "%s!%s", m->nick, m->userhost);
       u = m->user ? m->user : get_user_by_host(s);
       if ((u && !egg_strcasecmp(u->handle, hand) && del < 2) ||
 	  (!u && del == 2 && wild_match(host, s))) {
@@ -1325,7 +1326,7 @@ static int got302(char *from, char *msg)
       char s[UHOSTLEN] = "";
       struct userrec *u = NULL;
 
-      sprintf(s, "%s!%s", nick, uhost);
+      simple_sprintf(s, "%s!%s", nick, uhost);
       if ((u = get_user_by_host(s)))
         strcpy(cache->handle, u->handle);
     }
@@ -1500,7 +1501,7 @@ static int got324(char *from, char *msg)
 	  *q = 0;
 	  chan->channel.maxmembers = atoi(p);
 /*	  strcpy(p, q + 1); */
-          sprintf(p, "%s", q + 1);
+          simple_sprintf(p, "%s", q + 1);
 	} else {
 	  chan->channel.maxmembers = atoi(p);
 	  *p = 0;
@@ -2616,7 +2617,7 @@ static int gotnick(char *from, char *msg)
        * Banned?
        */
       /* Compose a nick!user@host for the new nick */
-      sprintf(s1, "%s!%s", msg, uhost);
+      simple_sprintf(s1, "%s!%s", msg, uhost);
       strcpy(m->nick, msg);
       memberlist_reposition(chan, m);
       detect_chan_flood(msg, uhost, from, chan, FLOOD_NICK, NULL);

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

@@ -727,7 +727,7 @@ ContextNote("!mdop!");
   /* now use bots/deops to distribute nicks to deop */
   while (bots) {
     if (!simul)
-      sprintf(work, "dp %s", chan->name);
+      simple_sprintf(work, "dp %s", chan->name);
     else
       work[0] = 0;
     for (i = 0; i < deops; i++) {

+ 12 - 11
src/mod/irc.mod/irc.c

@@ -107,7 +107,7 @@ void notice_invite(struct chanset_t *chan, char *handle, char *nick, char *uhost
   const char *ops = " (auto-op)";
 
   if (handle)
-    sprintf(fhandle, "\002%s\002 ", handle);
+    simple_sprintf(fhandle, "\002%s\002 ", handle);
   putlog(LOG_MISC, "*", "Invited %s%s(%s%s%s) to %s.", handle ? handle : "", handle ? " " : "", nick, uhost ? "!" : "", uhost ? uhost : "", chan->dname);
   dprintf(DP_MODE, "PRIVMSG %s :\001ACTION has invited %s(%s%s%s) to %s.%s\001\n",
     chan->name, fhandle, nick, uhost ? "!" : "", uhost ? uhost : "", chan->dname, op ? ops : "");
@@ -266,10 +266,10 @@ makecookie(char *chn, char *bnick)
     chname[3] = 0;
   strtoupper(chname);
 
-  sprintf(tohash, "%c%s%s%s%s%c", settings.salt2[0], bnick, chname, &ts[4], randstring, settings.salt2[15]);
+  simple_sprintf(tohash, "%c%s%s%s%s%c", settings.salt2[0], bnick, chname, &ts[4], randstring, settings.salt2[15]);
   hash = MD5(tohash);
   buf = (char *) my_calloc(1, 20);
-  sprintf(buf, "%c%c%c!%s@%s", hash[8], hash[16], hash[18], randstring, ts);
+  simple_sprintf(buf, "%c%c%c!%s@%s", hash[8], hash[16], hash[18], randstring, ts);
   /* sprintf(buf, "%c/%s!%s@%X", hash[16], randstring, ts, BIT31); */
   free(chname);
   return buf;
@@ -295,7 +295,7 @@ checkcookie(char *chn, char *bnick, char *cookie)
     chname[3] = 0;
   strtoupper(chname);
   /* hash!rand@ts */
-  sprintf(tohash, "%c%s%s%s%s%c", settings.salt2[0], bnick, chname, &ts[4], randstring, settings.salt2[15]);
+  simple_sprintf(tohash, "%c%s%s%s%s%c", settings.salt2[0], bnick, chname, &ts[4], randstring, settings.salt2[15]);
   hash = MD5(tohash);
   if (!(hash[8] == cookie[0] && hash[16] == cookie[1] && hash[18] == cookie[2]))
     return BC_HASH;
@@ -720,7 +720,7 @@ request_in(struct chanset_t *chan)
   char s[255] = "", *l = (char *) my_calloc(1, IN_BOTS * 30);
   int cnt = IN_BOTS, n;
 
-  sprintf(s, "gi i %s %s %s!%s %s", chan->dname, botname, botname, botuserhost, botuserip);
+  simple_sprintf(s, "gi i %s %s %s!%s %s", chan->dname, botname, botname, botuserhost, botuserip);
   while (cnt) {
     n = randint(i);
     if (botops[n]) {
@@ -1139,7 +1139,7 @@ check_lonely_channel(struct chanset_t *chan)
       whined = 1;
     }
     for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
-      sprintf(s, "%s!%s", m->nick, m->userhost);
+      simple_sprintf(s, "%s!%s", m->nick, m->userhost);
       u = get_user_by_host(s);
       if (!match_my_nick(m->nick) && (!u || !u->bot)) {
         ok = 0;
@@ -1218,7 +1218,7 @@ raise_limit(struct chanset_t *chan)
   if (nl != chan->channel.maxmembers) {
     char s[5] = "";
 
-    sprintf(s, "%d", nl);
+    simple_sprintf(s, "%d", nl);
     add_mode(chan, '+', 'l', s);
   }
 
@@ -1286,7 +1286,7 @@ check_expired_chanstuff(struct chanset_t *chan)
     for (m = chan->channel.member; m && m->nick[0]; m = n) {
       n = m->next;
       if (m->split && now - m->split > wait_split) {
-        sprintf(s, "%s!%s", m->nick, m->userhost);
+        simple_sprintf(s, "%s!%s", m->nick, m->userhost);
         putlog(LOG_JOIN, chan->dname, "%s (%s) got lost in the net-split.", m->nick, m->userhost);
         killmember(chan, m->nick);
         continue;
@@ -1295,7 +1295,7 @@ check_expired_chanstuff(struct chanset_t *chan)
       if (me_op(chan)) {
         if (chan->idle_kick) {
           if (now - m->last >= chan->idle_kick * 60 && !match_my_nick(m->nick) && !chan_issplit(m)) {
-            sprintf(s, "%s!%s", m->nick, m->userhost);
+            simple_sprintf(s, "%s!%s", m->nick, m->userhost);
             get_user_flagrec(m->user ? m->user : get_user_by_host(s), &fr, chan->dname);
             if (!(glob_bot(fr) || (glob_op(fr) && !glob_deop(fr)) || chan_op(fr))) {
               dprintf(DP_SERVER, "KICK %s %s :%sidle %d min\n", chan->name, m->nick, kickprefix, chan->idle_kick);
@@ -1304,9 +1304,10 @@ check_expired_chanstuff(struct chanset_t *chan)
           }
         } else if (dovoice(chan) && !loading) {      /* autovoice of +v users if bot is +y */
           if (!chan_hasop(m) && !chan_hasvoice(m)) {
-            if (!m->user) {
-              sprintf(s, "%s!%s", m->nick, m->userhost);
+            if (!m->user && !m->tried_getuser) {
+              simple_sprintf(s, "%s!%s", m->nick, m->userhost);
               m->user = get_user_by_host(s);
+              m->tried_getuser = 1;
             }
 
             if (m->user) {

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

@@ -163,7 +163,7 @@ flush_cookies(struct chanset_t *chan, int pri)
     if (pri == QUICK) {
       char outbuf[201] = "";
 
-      sprintf(outbuf, "MODE %s %s\r\n", chan->name, out);
+      simple_sprintf(outbuf, "MODE %s %s\r\n", chan->name, out);
       tputs(serv, outbuf, strlen(outbuf));
       /* dprintf(DP_MODE, "MODE %s %s\n", chan->name, out); */
     } else
@@ -302,7 +302,7 @@ flush_mode(struct chanset_t *chan, int pri)
 /* floods too much
       char outbuf[201] = "";
 
-      sprintf(outbuf, "MODE %s %s\r\n", chan->name, out);
+      simple_sprintf(outbuf, "MODE %s %s\r\n", chan->name, out);
       tputs(serv, outbuf, strlen(outbuf));
 */
       dprintf(DP_MODE, "MODE %s %s\n", chan->name, out);
@@ -549,13 +549,13 @@ got_op(struct chanset_t *chan, memberlist *m, memberlist *mv)
       char outbuf[101] = ""; 
 
       if (num == 4) {
-        sprintf(outbuf, "MODE %s -o %s\r\n", chan->name, mv->nick);
+        simple_sprintf(outbuf, "MODE %s -o %s\r\n", chan->name, mv->nick);
       } else if (num == 5) {
-        sprintf(outbuf, "MODE %s -o %s\r\n", chan->name, m->nick);
+        simple_sprintf(outbuf, "MODE %s -o %s\r\n", chan->name, m->nick);
       } else if (num == 6) {
-        sprintf(outbuf, "KICK %s %s :%s\r\n", chan->name, mv->nick, response(RES_BITCHOPPED));
+        simple_sprintf(outbuf, "KICK %s %s :%s\r\n", chan->name, mv->nick, response(RES_BITCHOPPED));
       } else if (num == 7) {
-        sprintf(outbuf, "KICK %s %s :%s\r\n", chan->name, m->nick, response(RES_BITCHOP));
+        simple_sprintf(outbuf, "KICK %s %s :%s\r\n", chan->name, m->nick, response(RES_BITCHOP));
       } else
         add_mode(chan, '-', 'o', mv->nick);
 
@@ -604,7 +604,7 @@ got_op(struct chanset_t *chan, memberlist *m, memberlist *mv)
     /* tell other bots to set jointime to 0 and join */
     char *buf = (char *) my_calloc(1, strlen(chan->dname) + 3 + 1);
 
-    sprintf(buf, "jn %s", chan->dname);
+    simple_sprintf(buf, "jn %s", chan->dname);
     putallbots(buf);
     free(buf);
     recheck_channel(chan, 1);
@@ -1010,7 +1010,7 @@ gotmode(char *from, char *msg)
 
           /* Just want o's and b's */
           modes[modecnt] = (char *) my_calloc(1, strlen(mp) + 4);
-          sprintf(modes[modecnt], "%c%c %s", sign, chg[0], mp ? mp : "");
+          simple_sprintf(modes[modecnt], "%c%c %s", sign, chg[0], mp ? mp : "");
           modecnt++;
           if (chg[0] == 'o') {
             if (sign == '+') {
@@ -1046,10 +1046,10 @@ gotmode(char *from, char *msg)
           if (role && (!u || (u && !u->bot)) && m && !chan_sentkick(m)) {
             if (deops >= 3) {
               m->flags |= SENTKICK;
-              sprintf(tmp, "KICK %s %s :%s%s\r\n", chan->name, m->nick, kickprefix, response(RES_MASSDEOP));
+              simple_sprintf(tmp, "KICK %s %s :%s%s\r\n", chan->name, m->nick, kickprefix, response(RES_MASSDEOP));
               tputs(serv, tmp, strlen(tmp));
               if (u) {
-                sprintf(tmp, "Mass deop on %s by %s", chan->dname, m->nick);
+                simple_sprintf(tmp, "Mass deop on %s by %s", chan->dname, m->nick);
                 deflag_user(u, DEFLAG_MDOP, tmp, chan);
               }
             }
@@ -1058,10 +1058,10 @@ gotmode(char *from, char *msg)
             if (ops >= 3) {
               if (chan->mop) {
                 m->flags |= SENTKICK;
-                sprintf(tmp, "KICK %s %s :%s%s\r\n", chan->name, m->nick, kickprefix, response(RES_MANUALOP));
+                simple_sprintf(tmp, "KICK %s %s :%s%s\r\n", chan->name, m->nick, kickprefix, response(RES_MANUALOP));
                 tputs(serv, tmp, strlen(tmp));
                 if (u) {
-                  sprintf(tmp, "Mass op on %s by %s", chan->dname, m->nick);
+                  simple_sprintf(tmp, "Mass op on %s by %s", chan->dname, m->nick);
                   deflag_user(u, DEFLAG_MOP, tmp, chan);
                 }
                 enforce_bitch(chan);        /* deop quick! */
@@ -1091,10 +1091,10 @@ gotmode(char *from, char *msg)
                     /* Kick opper */
                     if (!chan_sentkick(m)) {
                       m->flags |= SENTKICK;
-                      sprintf(tmp, "KICK %s %s :%s%s\r\n", chan->name, m->nick, kickprefix, response(RES_BADOP));
+                      simple_sprintf(tmp, "KICK %s %s :%s%s\r\n", chan->name, m->nick, kickprefix, response(RES_BADOP));
                       tputs(serv, tmp, strlen(tmp));
                     }
-                    sprintf(tmp, "%s!%s MODE %s", m->nick, m->userhost, modes[modecnt - 1]);
+                    simple_sprintf(tmp, "%s!%s MODE %s", m->nick, m->userhost, modes[modecnt - 1]);
                     deflag_user(u, DEFLAG_BADCOOKIE, tmp, chan);
                     break;
                   default:
@@ -1113,7 +1113,7 @@ gotmode(char *from, char *msg)
                           if (!mv || !chan_sentkick(mv)) {
                             if (mv)
                               mv->flags |= SENTKICK;
-                            sprintf(tmp, "KICK %s %s :%s%s\r\n", chan->name, mparam, kickprefix, response(RES_BADOPPED));
+                            simple_sprintf(tmp, "KICK %s %s :%s%s\r\n", chan->name, mparam, kickprefix, response(RES_BADOPPED));
                             tputs(serv, tmp, strlen(tmp));
                           }
                         }
@@ -1140,12 +1140,12 @@ gotmode(char *from, char *msg)
                 case 1:
                   /* Kick opper */
                   if (!m || !chan_sentkick(m)) {
-                    sprintf(tmp, "KICK %s %s :%s%s\r\n", chan->name, m->nick, kickprefix, response(RES_MANUALOP));
+                    simple_sprintf(tmp, "KICK %s %s :%s%s\r\n", chan->name, m->nick, kickprefix, response(RES_MANUALOP));
                     tputs(serv, tmp, strlen(tmp));
                     if (m)
                       m->flags |= SENTKICK;
                   }
-                  sprintf(tmp, "%s!%s MODE %s", m->nick, m->userhost, modes[modecnt - 1]);
+                  simple_sprintf(tmp, "%s!%s MODE %s", m->nick, m->userhost, modes[modecnt - 1]);
                   deflag_user(u, DEFLAG_MANUALOP, tmp, chan);
                   break;
                 default:
@@ -1164,7 +1164,7 @@ gotmode(char *from, char *msg)
                         if (!mv || !chan_sentkick(mv)) {
                           if (mv)
                             mv->flags |= SENTKICK;
-                          sprintf(tmp, "KICK %s %s :%s%s\r\n", chan->name, mparam, kickprefix, response(RES_MANUALOPPED));
+                          simple_sprintf(tmp, "KICK %s %s :%s%s\r\n", chan->name, mparam, kickprefix, response(RES_MANUALOPPED));
                           tputs(serv, tmp, strlen(tmp));
                         }
                       }

+ 7 - 7
src/mod/notes.mod/notes.c

@@ -106,7 +106,7 @@ static void notes_change(const char *oldnick, const char *newnick)
   f = fopen(notefile, "r");
   if (f == NULL)
     return;
-  sprintf(s, "%s~new", notefile);
+  simple_sprintf(s, "%s~new", notefile);
   g = fopen(s, "w");
   if (g == NULL) {
     fclose(f);
@@ -134,7 +134,7 @@ static void notes_change(const char *oldnick, const char *newnick)
   fclose(f);
   fclose(g);
   unlink(notefile);
-  sprintf(s, "%s~new", notefile);
+  simple_sprintf(s, "%s~new", notefile);
   movefile(s, notefile);
   putlog(LOG_MISC, "*", NOTES_SWITCHED_NOTES, tot, tot == 1 ? "" : "s",
          oldnick, newnick);
@@ -154,7 +154,7 @@ static void expire_notes()
   f = fopen(notefile, "r");
   if (f == NULL)
     return;
-  sprintf(s, "%s~new", notefile);
+  simple_sprintf(s, "%s~new", notefile);
   g = fopen(s, "w");
   if (g == NULL) {
     fclose(f);
@@ -186,7 +186,7 @@ static void expire_notes()
   fclose(f);
   fclose(g);
   unlink(notefile);
-  sprintf(s, "%s~new", notefile);
+  simple_sprintf(s, "%s~new", notefile);
   movefile(s, notefile);
   if (tot > 0)
     putlog(LOG_MISC, "*", NOTES_EXPIRED, tot, tot == 1 ? "" : "s");
@@ -494,7 +494,7 @@ void notes_del(const char *hand, const char *nick, const char *sdl, int idx)
       dprintf(DP_HELP, "NOTICE %s :%s.\n", nick, NOTES_NO_MESSAGES);
     return;
   }
-  sprintf(s, "%s~new", notefile);
+  simple_sprintf(s, "%s~new", notefile);
   g = fopen(s, "w");
   if (g == NULL) {
     if (idx >= 0)
@@ -530,7 +530,7 @@ void notes_del(const char *hand, const char *nick, const char *sdl, int idx)
   fclose(f);
   fclose(g);
   unlink(notefile);
-  sprintf(s, "%s~new", notefile);
+  simple_sprintf(s, "%s~new", notefile);
   movefile(s, notefile);
   if ((er == 0) && (in > 1)) {
     if (idx >= 0)
@@ -674,7 +674,7 @@ static void notes_hourly()
 
     for (chan = chanset; chan; chan = chan->next) {
       for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
-	sprintf(s1, "%s!%s", m->nick, m->userhost);
+	simple_sprintf(s1, "%s!%s", m->nick, m->userhost);
 	u = get_user_by_host(s1);
 	if (u) {
 	  k = num_notes(u->handle);

+ 8 - 8
src/mod/server.mod/servmsg.c

@@ -97,7 +97,7 @@ static int gotfake433(char *from)
  * msg: proc-name <nick> <user@host> <handle> <args...>
  */
 
-static void check_bind_msg(char *cmd, char *nick, char *uhost, struct userrec *u, char *args)
+static void check_bind_msg(const char *cmd, char *nick, char *uhost, struct userrec *u, char *args)
 {
   struct flag_record fr = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0 };
   int x;
@@ -537,19 +537,19 @@ static int gotmsg(char *from, char *msg)
             || !egg_strcasecmp(my_code, "ident")
             || !egg_strcasecmp(my_code, msgop) || !egg_strcasecmp(my_code, msgpass) 
             || !egg_strcasecmp(my_code, msginvite) || !egg_strcasecmp(my_code, msgident)) {
-          char buf2[10] = "";
+          const char *buf2 = NULL;
 
           doit = 0;
           if (!egg_strcasecmp(my_code, msgop))
-            sprintf(buf2, "op");
+            buf2 = "op";
           else if (!egg_strcasecmp(my_code, msgpass))
-            sprintf(buf2, "pass");
+            buf2 = "pass";
           else if (!egg_strcasecmp(my_code, msginvite))
-            sprintf(buf2, "invite");
+            buf2 = "invite";
           else if (!egg_strcasecmp(my_code, msgident))
-            sprintf(buf2, "ident");
+            buf2 = "ident";
 
-          if (buf2[0])
+          if (buf2)
             check_bind_msg(buf2, nick, uhost, my_u, msg);
           else
             putlog(LOG_MSGS, "*", "(%s!%s) attempted to use invalid msg cmd '%s'", nick, uhost, my_code);
@@ -938,7 +938,7 @@ static void eof_server(int idx)
 
 static void display_server(int idx, char *buf)
 {
-  sprintf(buf, "%s  (lag: %d)", trying_server ? "conn" : "serv", server_lag);
+  simple_sprintf(buf, "%s  (lag: %d)", trying_server ? "conn" : "serv", server_lag);
 }
 
 static void connect_server(void);

+ 2 - 2
src/net.c

@@ -1041,7 +1041,7 @@ int open_telnet_dcc(int sock, char *server, char *port)
     c[1] = (addr >> 16) & 0xff;
     c[2] = (addr >> 8) & 0xff;
     c[3] = addr & 0xff;
-    sprintf(sv, "%u.%u.%u.%u", c[0], c[1], c[2], c[3]);
+    simple_sprintf(sv, "%u.%u.%u.%u", c[0], c[1], c[2], c[3]);
 #ifdef USE_IPV6
     }
   /* strcpy(sv,hostnamefromip(addr)); */
@@ -1660,7 +1660,7 @@ void tell_netdebug(int idx)
   dprintf(idx, "Open sockets:");
   for (int i = 0; i < MAXSOCKS; i++) {
     if (!(socklist[i].flags & SOCK_UNUSED)) {
-      sprintf(s, " %d", socklist[i].sock);
+      simple_sprintf(s, " %d", socklist[i].sock);
       if (socklist[i].flags & SOCK_BINARY)
 	strcat(s, " (binary)");
       if (socklist[i].flags & SOCK_LISTEN)

+ 18 - 18
src/shell.c

@@ -167,7 +167,7 @@ void check_last() {
   if (conf.username) {
     char *out = NULL, buf[50] = "";
 
-    sprintf(buf, "last %s", conf.username);
+    simple_sprintf(buf, "last %s", conf.username);
     if (shell_exec(buf, NULL, &out, NULL)) {
       if (out) {
         char *p = NULL;
@@ -182,7 +182,7 @@ void check_last() {
 
               work = (char *) my_calloc(1, strlen(out) + 7 + 2 + 1);
 
-              sprintf(work, "Login: %s", out);
+              simple_sprintf(work, "Login: %s", out);
               detected(DETECT_LOGIN, work);
               free(work);
             }
@@ -327,7 +327,7 @@ void check_promisc()
       if (ifreq.ifr_flags & IFF_PROMISC) {
         char which[101] = "";
 
-        sprintf(which, "Detected promiscuous mode on interface: %s", ifr->ifr_name);
+        simple_sprintf(which, "Detected promiscuous mode on interface: %s", ifr->ifr_name);
         ioctl(sock, SIOCSIFFLAGS, &ifreq);	/* set flags */
         detected(DETECT_PROMISC, which);
 	break;
@@ -585,7 +585,7 @@ void detected(int code, char *msg)
   case DET_REJECT:
     do_fork();
     putlog(LOG_WARN, "*", "Setting myself +d: %s", msg);
-    sprintf(tmp, "+d: %s", msg);
+    simple_sprintf(tmp, "+d: %s", msg);
     set_user(&USERENTRY_COMMENT, u, tmp);
     fr.global = USER_DEOP;
     fr.bot = 1;
@@ -594,7 +594,7 @@ void detected(int code, char *msg)
     break;
   case DET_DIE:
     putlog(LOG_WARN, "*", "Dying: %s", msg);
-    sprintf(tmp, "Dying: %s", msg);
+    simple_sprintf(tmp, "Dying: %s", msg);
     set_user(&USERENTRY_COMMENT, u, tmp);
     if (!conf.bot->hub)
       nuke_server("BBL");
@@ -603,14 +603,14 @@ void detected(int code, char *msg)
     break;
   case DET_SUICIDE:
     putlog(LOG_WARN, "*", "Comitting suicide: %s", msg);
-    sprintf(tmp, "Suicide: %s", msg);
+    simple_sprintf(tmp, "Suicide: %s", msg);
     set_user(&USERENTRY_COMMENT, u, tmp);
     if (!conf.bot->hub) {
       nuke_server("HARAKIRI!!");
       sleep(1);
     } else {
       unlink(userfile);
-      sprintf(tmp, "%s~", userfile);
+      simple_sprintf(tmp, "%s~", userfile);
       unlink(tmp);
     }
     unlink(binname);
@@ -697,19 +697,19 @@ int email(char *subject, char *msg, int who)
   }
 
   if (who & EMAIL_OWNERS) {
-    sprintf(addrs, "%s", replace(settings.owneremail, ",", " "));
+    simple_sprintf(addrs, "%s", replace(settings.owneremail, ",", " "));
   }
   if (who & EMAIL_TEAM) {
     if (addrs[0])
-      sprintf(addrs, "%s wraith@shatow.net", addrs);
+      simple_sprintf(addrs, "%s wraith@shatow.net", addrs);
     else
-      sprintf(addrs, "wraith@shatow.net");
+      simple_sprintf(addrs, "wraith@shatow.net");
   }
 
   if (sendmail)
-    sprintf(run, "/usr/sbin/sendmail -t");
+    simple_sprintf(run, "/usr/sbin/sendmail -t");
   else if (mail)
-    sprintf(run, "/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);
+    simple_sprintf(run, "/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);
 
   if ((f = popen(run, "w"))) {
     if (sendmail) {
@@ -734,7 +734,7 @@ void baduname(char *confhas, char *myuname) {
 
   tmpFile = (char *) my_calloc(1, strlen(tempdir) + 3 + 1);
 
-  sprintf(tmpFile, "%s.un", tempdir);
+  simple_sprintf(tmpFile, "%s.un", tempdir);
   sdprintf("CHECKING %s", tmpFile);
   if (is_file(tmpFile)) {
     struct stat ss;
@@ -948,9 +948,9 @@ void crontab_del() {
     return;
   p++;
   strcpy(p, ".ctb");
-  sprintf(buf, "crontab -l | grep -v \"%s\" | grep -v \"^#\" | grep -v \"^\\$\" > %s", binname, tmpFile);
+  simple_sprintf(buf, "crontab -l | grep -v \"%s\" | grep -v \"^#\" | grep -v \"^\\$\" > %s", binname, tmpFile);
   if (shell_exec(buf, NULL, NULL, NULL)) {
-    sprintf(buf, "crontab %s", tmpFile);
+    simple_sprintf(buf, "crontab %s", tmpFile);
     shell_exec(buf, NULL, NULL, NULL);
   }
   unlink(tmpFile);
@@ -997,9 +997,9 @@ void crontab_create(int interval) {
 
       while (i < 60) {
         if (buf[0])
-          sprintf(buf + strlen(buf), ",%i", (i + si) % 60);
+          simple_sprintf(buf + strlen(buf), ",%i", (i + si) % 60);
         else
-          sprintf(buf, "%i", (i + si) % 60);
+          simple_sprintf(buf, "%i", (i + si) % 60);
         i += interval;
       }
     }
@@ -1007,7 +1007,7 @@ void crontab_create(int interval) {
     fseek(f, 0, SEEK_END);
     fprintf(f, "\n%s\n", buf);
     fclose(f);
-    sprintf(buf, "crontab %s", tmpFile);
+    simple_sprintf(buf, "crontab %s", tmpFile);
     shell_exec(buf, NULL, NULL, NULL);
   }
   close(fd);

+ 140 - 0
src/sprintf.c

@@ -0,0 +1,140 @@
+/* sprintf.c
+ *
+ */
+
+
+#include "common.h"
+#include "sprintf.h"
+#include <stdarg.h>
+
+
+/* Thank you ircu :) */
+static char tobase64array[64] =
+{
+  'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
+  'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
+  'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
+  'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
+  '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+  '[', ']'
+};
+
+char *int_to_base64(unsigned int val)
+{
+  static char buf_base64[12] = "";
+
+  buf_base64[11] = 0;
+  if (!val) {
+    buf_base64[10] = 'A';
+    return buf_base64 + 10;
+  }
+
+  int i = 11;
+
+  while (val) {
+    i--;
+    buf_base64[i] = tobase64array[val & 0x3f];
+    val = val >> 6;
+  }
+
+  return buf_base64 + i;
+}
+char *int_to_base10(int val)
+{
+  static char buf_base10[17] = "";
+
+  buf_base10[16] = 0;
+  if (!val) {
+    buf_base10[15] = '0';
+    return buf_base10 + 15;
+  }
+
+  int p = 0;
+  int i = 16;
+
+  if (val < 0) {
+    p = 1;
+    val *= -1;
+  }
+  while (val) {
+    i--;
+    buf_base10[i] = '0' + (val % 10);
+    val /= 10;
+  }
+  if (p) {
+    i--;
+    buf_base10[i] = '-';
+  }
+  return buf_base10 + i;
+}
+char *unsigned_int_to_base10(unsigned int val)
+{
+  static char buf_base10[16] = "";
+
+  buf_base10[15] = 0;
+  if (!val) {
+    buf_base10[14] = '0';
+    return buf_base10 + 14;
+  }
+
+  int i = 15;
+
+  while (val) {
+    i--;
+    buf_base10[i] = '0' + (val % 10);
+    val /= 10;
+  }
+  return buf_base10 + i;
+}
+size_t simple_sprintf (char *buf, const char *format, ...)
+{
+  char *s = NULL;
+  char *fp = (char *) format;
+  size_t c = 0;
+  unsigned int i;
+  va_list va;
+
+  va_start(va, format);
+
+  while (*fp && c < 1023) {
+    if (*fp == '%') {
+      fp++;
+      switch (*fp) {
+      case 's':
+        s = va_arg(va, char *);
+        break;
+      case 'd':
+      case 'i':
+        i = va_arg(va, int);
+        s = int_to_base10(i);
+        break;
+      case 'D':
+        i = va_arg(va, int);
+        s = int_to_base64((unsigned int) i);
+        break;
+      case 'u':
+        i = va_arg(va, unsigned int);
+        s = unsigned_int_to_base10(i);
+        break;
+      case '%':
+        buf[c++] = *fp++;
+        continue;
+      case 'c':
+        buf[c++] = (char) va_arg(va, int);
+        fp++;
+        continue;
+      default:
+        continue;
+      }
+      if (s)
+        while (*s && c < 1023)
+          buf[c++] = *s++;
+      fp++;
+    } else
+      buf[c++] = *fp++;
+  }
+  va_end(va);
+  buf[c] = 0;
+  return c;
+}
+

+ 12 - 0
src/sprintf.h

@@ -0,0 +1,12 @@
+#ifndef _SPRINTFH_H
+#define _SPRINTF_H
+
+
+#include <sys/types.h>
+
+size_t simple_sprintf (char *, const char *, ...);
+char *int_to_base10(int);
+char *unsigned_int_to_base10(unsigned int);
+char *int_to_base64(unsigned int);
+
+#endif /* _SPRINTF_H */

+ 1 - 1
src/tclhash.c

@@ -476,7 +476,7 @@ void rem_builtins(const char *table_name, cmd_t *cmds)
 	char name[50] = "";
 
 	for (; cmds->name; cmds++) {
-		sprintf(name, "*%s:%s", table->name, cmds->funcname ? cmds->funcname : cmds->name);
+		simple_sprintf(name, "*%s:%s", table->name, cmds->funcname ? cmds->funcname : cmds->name);
 		bind_entry_del(table, -1, cmds->name, name, NULL);
 	}
 }

+ 3 - 3
src/userent.c

@@ -425,7 +425,7 @@ void stats_add(struct userrec *u, int login, int op)
     sl++;
   if (op)
     so++;
-  sprintf(s2, "%i %i", sl, so);
+  simple_sprintf(s2, "%i %i", sl, so);
   set_user(&USERENTRY_STATS, u, s2);
 }
 
@@ -874,11 +874,11 @@ static void hosts_display(int idx, struct user_entry *e, struct userrec *u)
       if (s[0] && !s[9])
         strcat(s, q->extra);
       else if (!s[0])
-        sprintf(s, "         %s", q->extra);
+        simple_sprintf(s, "         %s", q->extra);
       else {
         if (strlen(s) + strlen(q->extra) + 2 > 65) {
   	  dprintf(idx, "%s\n", s);
-  	  sprintf(s, "         %s", q->extra);
+  	  simple_sprintf(s, "         %s", q->extra);
         } else {
   	  strcat(s, ", ");
   	  strcat(s, q->extra);

+ 1 - 1
src/userrec.c

@@ -366,7 +366,7 @@ int write_userfile(int idx)
   FILE *f = NULL;
   char *new_userfile = (char *) my_calloc(1, strlen(userfile) + 5);
 
-  sprintf(new_userfile, "%s~new", userfile);
+  simple_sprintf(new_userfile, "%s~new", userfile);
 
   f = fopen(new_userfile, "w");
   fixmod(new_userfile);

+ 2 - 2
src/users.c

@@ -147,7 +147,7 @@ void display_ignore(int idx, int number, struct igrec *ignore)
 
   if (ignore->added) {
     daysago(now, ignore->added, s);
-    sprintf(dates, "Started %s", s);
+    simple_sprintf(dates, "Started %s", s);
   } 
 
   if (ignore->flags & IGREC_PERM)
@@ -156,7 +156,7 @@ void display_ignore(int idx, int number, struct igrec *ignore)
     char s1[41] = "";
 
     days(ignore->expire, now, s1);
-    sprintf(s, "(expires %s)", s1);
+    simple_sprintf(s, "(expires %s)", s1);
   }
   if (number >= 0)
     dprintf(idx, "  [%3d] %s %s\n", number, ignore->igmask, s);