Bladeren bron

* Fixed a bunch of unchecked buffers

svn: 1097
Bryan Drewery 22 jaren geleden
bovenliggende
commit
4b0ffb20c2
2 gewijzigde bestanden met toevoegingen van 33 en 23 verwijderingen
  1. 1 0
      doc/UPDATES
  2. 32 23
      src/cmds.c

+ 1 - 0
doc/UPDATES

@@ -39,6 +39,7 @@ This is a summary of ChangeLog basically.
 35.Added cmd_matchbot for matching bots, cmd_match now only does users.
 35.Added cmd_matchbot for matching bots, cmd_match now only does users.
 36.Fixed +d|d bots still being opped.
 36.Fixed +d|d bots still being opped.
 37.Fixed a bug with bot links that was causing too many open files errors.
 37.Fixed a bug with bot links that was causing too many open files errors.
+38.Fixed a ton of unchecked buffers in cmds.c.
 
 
 1.1.7
 1.1.7
 
 

+ 32 - 23
src/cmds.c

@@ -462,7 +462,7 @@ static void cmd_cmdpass(struct userrec *u, int idx, char *par)
       return;
       return;
     }
     }
     encrypt_pass(pass, epass);
     encrypt_pass(pass, epass);
-    sprintf(tmp, "%s %s", cmd, epass);
+    egg_snprintf(tmp, sizeof tmp, "%s %s", cmd, epass);
     if (has_cmd_pass(cmd))
     if (has_cmd_pass(cmd))
       dprintf(idx, "Changed command password for %s\n", cmd);
       dprintf(idx, "Changed command password for %s\n", cmd);
     else
     else
@@ -525,10 +525,12 @@ static void cmd_motd(struct userrec *u, int idx, char *par)
   putlog(LOG_CMDS, "*", "#%s# motd %s", dcc[idx].nick, par);
   putlog(LOG_CMDS, "*", "#%s# motd %s", dcc[idx].nick, par);
   if (par[0] && (u->flags & USER_MASTER)) {
   if (par[0] && (u->flags & USER_MASTER)) {
     char *s = NULL;
     char *s = NULL;
+    size_t size;
+  
+    size = strlen(par) + 1 + strlen(dcc[idx].nick) + 10 + 1 + 1;
+    s = calloc(1, size); /* +2: ' 'x2 */
 
 
-    s = calloc(1, strlen(par) + 1 + strlen(dcc[idx].nick) + 10 + 1 + 1); /* +2: ' 'x2 */
-
-    sprintf(s, "%s %li %s", dcc[idx].nick, now, par);
+    egg_snprintf(s, size, "%s %li %s", dcc[idx].nick, now, par);
     set_cfg_str(NULL, "motd", s);
     set_cfg_str(NULL, "motd", s);
     free(s);
     free(s);
     dprintf(idx, "Motd set\n");
     dprintf(idx, "Motd set\n");
@@ -643,7 +645,7 @@ static void cmd_newpass(struct userrec *u, int idx, char *par)
       dprintf(idx, "Please use at least 6 characters.\n");
       dprintf(idx, "Please use at least 6 characters.\n");
       return;
       return;
     } else {
     } else {
-      sprintf(pass, "%s", new);
+      egg_snprintf(pass, sizeof pass, "%s", new);
     }
     }
   }
   }
   if (strlen(pass) > 15)
   if (strlen(pass) > 15)
@@ -677,7 +679,7 @@ static void cmd_secpass(struct userrec *u, int idx, char *par)
       dprintf(idx, "Please use at least 6 characters.\n");
       dprintf(idx, "Please use at least 6 characters.\n");
       return;
       return;
     } else {
     } else {
-      sprintf(pass, "%s", new);
+      egg_snprintf(pass, sizeof pass, "%s", new);
     }
     }
   }
   }
   if (strlen(pass) > 15)
   if (strlen(pass) > 15)
@@ -791,7 +793,7 @@ static void cmd_help(struct userrec *u, int idx, char *par)
   } else {
   } else {
     if (!strchr(par, '*') && !strchr(par, '?'))
     if (!strchr(par, '*') && !strchr(par, '?'))
       nowild++;
       nowild++;
-    sprintf(match, "%s", newsplit(&par));
+    egg_snprintf(match, sizeof match, "%s", newsplit(&par));
   }
   }
   if (!nowild)
   if (!nowild)
     dprintf(idx, "Showing help topics matching '%s' for flags: (%s)\n", match, flg);
     dprintf(idx, "Showing help topics matching '%s' for flags: (%s)\n", match, flg);
@@ -1485,7 +1487,7 @@ static void cmd_chpass(struct userrec *u, int idx, char *par)
         good = 1;
         good = 1;
       } else {
       } else {
         if (goodpass(new, idx, NULL)) {
         if (goodpass(new, idx, NULL)) {
-          sprintf(pass, "%s", new);
+          egg_snprintf(pass, sizeof pass, "%s", new);
           good = 1;
           good = 1;
         }
         }
       }
       }
@@ -1542,7 +1544,7 @@ static void cmd_chsecpass(struct userrec *u, int idx, char *par)
           dprintf(idx, "Please use at least 6 characters.\n");
           dprintf(idx, "Please use at least 6 characters.\n");
           return;
           return;
         } else {
         } else {
-          sprintf(pass, "%s", new);
+          egg_snprintf(pass, sizeof pass, "%s", new);
         }
         }
       }
       }
       if (strlen(pass) > 15)
       if (strlen(pass) > 15)
@@ -2543,6 +2545,11 @@ static void cmd_chattr(struct userrec *u, int idx, char *par)
     pls.match = user.match;
     pls.match = user.match;
     break_down_flags(chg, &pls, &mns);
     break_down_flags(chg, &pls, &mns);
 
 
+/* FIXME: Remove after 1.1.8 */
+    pls.global &=~(USER_BOT);
+    mns.global &=~(USER_BOT);
+
+
     if ((pls.global & USER_UPDATEHUB) && (bot_hublevel(u2) == 999)) {
     if ((pls.global & USER_UPDATEHUB) && (bot_hublevel(u2) == 999)) {
       dprintf(idx, "Only a hub can be set as the updatehub.\n");
       dprintf(idx, "Only a hub can be set as the updatehub.\n");
       pls.global &= ~(USER_UPDATEHUB);
       pls.global &= ~(USER_UPDATEHUB);
@@ -2815,6 +2822,7 @@ static void cmd_w(struct userrec *u, int idx, char *par) {
 
 
 static void cmd_ps(struct userrec *u, int idx, char *par) {
 static void cmd_ps(struct userrec *u, int idx, char *par) {
   char *buf = NULL;
   char *buf = NULL;
+  size_t size;
 
 
   putlog(LOG_CMDS, "*", "#%s# ps %s", dcc[idx].nick, par);
   putlog(LOG_CMDS, "*", "#%s# ps %s", dcc[idx].nick, par);
   if (strchr(par, '|') || strchr(par, '<') || strchr(par, ';') || strchr(par, '>')) {
   if (strchr(par, '|') || strchr(par, '<') || strchr(par, ';') || strchr(par, '>')) {
@@ -2822,8 +2830,9 @@ static void cmd_ps(struct userrec *u, int idx, char *par) {
     dprintf(idx, "No.");
     dprintf(idx, "No.");
     return;
     return;
   }
   }
-  buf = calloc(1, strlen(par) + 10);
-  sprintf(buf, "ps %s", par);
+  size = strlen(par) + 9 + 1;
+  buf = calloc(1, size);
+  egg_snprintf(buf, size, "ps %s", par);
   if (!exec_str(idx, buf))
   if (!exec_str(idx, buf))
     dprintf(idx, "Exec failed\n");
     dprintf(idx, "Exec failed\n");
   free(buf);
   free(buf);
@@ -2847,7 +2856,7 @@ static void cmd_last(struct userrec *u, int idx, char *par) {
     dprintf(idx, "Can't determine user id for process\n");
     dprintf(idx, "Can't determine user id for process\n");
     return;
     return;
   }
   }
-  sprintf(buf, "last %s", user);
+  egg_snprintf(buf, sizeof buf, "last %s", user);
   if (!exec_str(idx, buf))
   if (!exec_str(idx, buf))
     dprintf(idx, "Failed to execute /bin/sh last\n");
     dprintf(idx, "Failed to execute /bin/sh last\n");
 }
 }
@@ -3740,7 +3749,7 @@ static void cmd_botmsg(struct userrec * u, int idx, char * par) {
     dprintf(idx, "No such bot linked\n");
     dprintf(idx, "No such bot linked\n");
     return;
     return;
   }
   }
-  sprintf(tmp, "msg %s %s", tnick, par);
+  egg_snprintf(tmp, sizeof tmp, "msg %s %s", tnick, par);
   botnet_send_cmd(conf.bot->nick, tbot, u->handle, idx, tmp);
   botnet_send_cmd(conf.bot->nick, tbot, u->handle, idx, tmp);
 }
 }
 
 
@@ -3753,7 +3762,7 @@ static void cmd_netmsg(struct userrec * u, int idx, char * par) {
     dprintf(idx, "Usage: netmsg <nick|#channel> <message>\n");
     dprintf(idx, "Usage: netmsg <nick|#channel> <message>\n");
     return;
     return;
   }
   }
-  sprintf(tmp, "msg %s %s", tnick, par);
+  egg_snprintf(tmp, sizeof tmp, "msg %s %s", tnick, par);
   botnet_send_cmd_broad(-1, conf.bot->nick, u->handle, idx, tmp);
   botnet_send_cmd_broad(-1, conf.bot->nick, u->handle, idx, tmp);
 }
 }
 
 
@@ -3764,7 +3773,7 @@ void rcmd_msg(char * tobot, char * frombot, char * fromhand, char * fromidx, cha
   nick = newsplit(&par);
   nick = newsplit(&par);
   dprintf(DP_SERVER, "PRIVMSG %s :%s\n", nick, par);
   dprintf(DP_SERVER, "PRIVMSG %s :%s\n", nick, par);
   if (!strcmp(tobot, conf.bot->nick)) {
   if (!strcmp(tobot, conf.bot->nick)) {
-    sprintf(buf, "Sent message to %s", nick);
+    egg_snprintf(buf, sizeof buf, "Sent message to %s", nick);
     botnet_send_cmdreply(conf.bot->nick, frombot, fromhand, fromidx, buf);
     botnet_send_cmdreply(conf.bot->nick, frombot, fromhand, fromidx, buf);
   }
   }
 #endif /* LEAF */
 #endif /* LEAF */
@@ -3790,7 +3799,7 @@ static void cmd_netlag(struct userrec * u, int idx, char * par) {
 void rcmd_ping(char * frombot, char *fromhand, char * fromidx, char * par) {
 void rcmd_ping(char * frombot, char *fromhand, char * fromidx, char * par) {
   char tmp[64] = "";
   char tmp[64] = "";
 
 
-  sprintf(tmp, "pong %s", par);
+  egg_snprintf(tmp, sizeof tmp, "pong %s", par);
   botnet_send_cmd(conf.bot->nick, frombot, fromhand, atoi(fromidx), tmp);
   botnet_send_cmd(conf.bot->nick, frombot, fromhand, atoi(fromidx), tmp);
 }
 }
 
 
@@ -3826,7 +3835,7 @@ static void cmd_netps(struct userrec * u, int idx, char * par) {
     dprintf(idx, "No.");
     dprintf(idx, "No.");
     return;
     return;
   }
   }
-  sprintf(buf, "exec ps %s", par);
+  egg_snprintf(buf, sizeof par, "exec ps %s", par);
   botnet_send_cmd_broad(-1, conf.bot->nick, dcc[idx].nick, idx, buf);
   botnet_send_cmd_broad(-1, conf.bot->nick, dcc[idx].nick, idx, buf);
 }
 }
 
 
@@ -3839,7 +3848,7 @@ static void cmd_netlast(struct userrec * u, int idx, char * par) {
     dprintf(idx, "No.");
     dprintf(idx, "No.");
     return;
     return;
   }
   }
-  sprintf(buf, "exec last %s", par);
+  egg_snprintf(buf, sizeof par, "exec last %s", par);
   botnet_send_cmd_broad(-1, conf.bot->nick, dcc[idx].nick, idx, buf);
   botnet_send_cmd_broad(-1, conf.bot->nick, dcc[idx].nick, idx, buf);
 }
 }
 #endif /* HUB */
 #endif /* HUB */
@@ -3930,13 +3939,13 @@ void rcmd_exec(char * frombot, char * fromhand, char * fromidx, char * par) {
       botnet_send_cmdreply(conf.bot->nick, frombot, fromhand, fromidx, "Can't determine user id for process");
       botnet_send_cmdreply(conf.bot->nick, frombot, fromhand, fromidx, "Can't determine user id for process");
       return;
       return;
     }
     }
-    sprintf(scmd, "last %s", user);
+    egg_snprintf(scmd, sizeof scmd, "last %s", user);
   } else if (!strcmp(cmd, "ps")) {
   } else if (!strcmp(cmd, "ps")) {
-    sprintf(scmd, "ps %s", par);
+    egg_snprintf(scmd, sizeof scmd, "ps %s", par);
   } else if (!strcmp(cmd, "raw")) {
   } else if (!strcmp(cmd, "raw")) {
-    sprintf(scmd, "%s", par);
+    egg_snprintf(scmd, sizeof scmd, "%s", par);
   } else if (!strcmp(cmd, "kill")) {
   } else if (!strcmp(cmd, "kill")) {
-    sprintf(scmd, "kill %s", par);
+    egg_snprintf(scmd, sizeof scmd, "kill %s", par);
   } else if (!strcmp(cmd, "crontab")) {
   } else if (!strcmp(cmd, "crontab")) {
     char *code = newsplit(&par);
     char *code = newsplit(&par);
 
 
@@ -4014,7 +4023,7 @@ static void cmd_botjump(struct userrec * u, int idx, char * par) {
     dprintf(idx, "No such linked bot\n");
     dprintf(idx, "No such linked bot\n");
     return;
     return;
   }
   }
-  sprintf(buf, "jump %s", par);
+  egg_snprintf(buf, sizeof buf, "jump %s", par);
   botnet_send_cmd(conf.bot->nick, tbot, dcc[idx].nick, idx, buf);
   botnet_send_cmd(conf.bot->nick, tbot, dcc[idx].nick, idx, buf);
 }
 }