Przeglądaj źródła

* Fix overlapping sprintf calls

Bryan Drewery 17 lat temu
rodzic
commit
8c2edb8ebb
3 zmienionych plików z 11 dodań i 12 usunięć
  1. 6 6
      src/cmds.c
  2. 1 1
      src/makeres.c
  3. 4 5
      src/shell.c

+ 6 - 6
src/cmds.c

@@ -3823,9 +3823,9 @@ static void rcmd_ver(char * fbot, char * fhand, char * fidx) {
     strlcat(tmp, "(unknown OS)", sizeof(tmp));
   } else {
     if (updated) {
-      simple_snprintf(tmp, sizeof(tmp), "%s %s %s (%s) - UPDATED", tmp, un.sysname, un.release, un.machine);
+      simple_snprintf(&tmp[strlen(tmp)], sizeof(tmp) - strlen(tmp), " %s %s (%s) - UPDATED", un.sysname, un.release, un.machine);
     } else
-      simple_snprintf(tmp, sizeof(tmp), "%s %s %s (%s)", tmp, un.sysname, un.release, un.machine);
+      simple_snprintf(&tmp[strlen(tmp)], sizeof(tmp) - strlen(tmp), " %s %s (%s)", un.sysname, un.release, un.machine);
   }
   botnet_send_cmdreply(conf.bot->nick, fbot, fhand, fidx, tmp);
 }
@@ -3861,13 +3861,13 @@ static void rcmd_curnick(char * fbot, char * fhand, char * fidx) {
     if (server_online)
       egg_snprintf(tmp, sizeof(tmp), "Currently: %-20s ", botname);
     if (jupenick[0] && strncmp(botname, jupenick, strlen(botname)))
-      simple_snprintf(tmp, sizeof(tmp), "%sJupe: %s ", tmp, jupenick);
+      simple_snprintf(&tmp[strlen(tmp)], sizeof(tmp) - strlen(tmp), "Jupe: %s ", jupenick);
     else if (jupenick[0] && strcmp(botname, origbotname))
-      simple_snprintf(tmp, sizeof(tmp), "%sJupe: %s Main: %s ", tmp, jupenick, origbotname);
+      simple_snprintf(&tmp[strlen(tmp)], sizeof(tmp) - strlen(tmp), "Jupe: %s Main: %s ", jupenick, origbotname);
     else if (strcmp(botname, origbotname))
-      simple_snprintf(tmp, sizeof(tmp), "%sMain: %s ", tmp, origbotname);
+      simple_snprintf(&tmp[strlen(tmp)], sizeof(tmp) - strlen(tmp), "Main: %s ", origbotname);
     if (!server_online)
-      simple_snprintf(tmp, sizeof(tmp), "%s(not online)", tmp);
+      strlcat(tmp, "(not online)", sizeof(tmp));
     botnet_send_cmdreply(conf.bot->nick, fbot, fhand, fidx, tmp);
   }
 }

+ 1 - 1
src/makeres.c

@@ -172,7 +172,7 @@ typedef const char * res_t;\n\n");
           if (total_responses == 1)
             fprintf(outf, " = 1");
           fprintf(outsf, "static res_t res_%s[] = {\n", cmd);
-          sprintf(lower_resps, "%s,\n\tres_%s", lower_resps, cmd);
+          sprintf(&lower_resps[strlen(lower_resps)], ",\n\tres_%s", cmd);
         } else {			/* END */
           fprintf(outf, "\tRES_END\n};\n\n#define RES_TYPES %d\n", total_responses);
           fprintf(outf, "const char *response(response_t);\nvoid init_responses();\nconst char *r_banned(struct chanset_t* chan);\n\n#endif /* !_RESPONSE_H */\n");

+ 4 - 5
src/shell.c

@@ -984,9 +984,8 @@ void crontab_create(int interval) {
 
       while (i < 60) {
         if (buf[0])
-          simple_snprintf(buf, sizeof(buf), "%s,%i", buf[0] ? buf : "", (i + si) % 60);
-        else
-          simple_snprintf(buf, sizeof(buf), "%i", (i + si) % 60);
+          strlcat(buf, ",", sizeof(buf));
+        simple_snprintf(&buf[strlen(buf)], sizeof(buf) - strlen(buf), "%i", (i + si) % 60);
         i += interval;
       }
     }
@@ -1050,9 +1049,9 @@ char *shell_escape(const char *path)
 
   for (c = (char *) path; c && *c; ++c) {
     if (strchr(ESCAPESHELL, *c))
-      simple_snprintf(ret, sizeof(ret1), "%s\\%c", ret[0] ? ret : "", *c);
+      simple_snprintf(&ret[strlen(ret)], sizeof(ret1) - strlen(ret), "\\%c", *c);
     else
-      simple_snprintf(ret, sizeof(ret1), "%s%c", ret[0] ? ret : "", *c);
+      simple_snprintf(&ret[strlen(ret)], sizeof(ret1) - strlen(ret), "%c", *c);
   }
 
   return ret;