Bladeren bron

Merge branch 'fix-overlapping-sprintf'

* fix-overlapping-sprintf:
  * Fix some overlapping strcpy() calls and replace with memmove()
  * Fix overlapping sprintf calls
Bryan Drewery 17 jaren geleden
bovenliggende
commit
b67894bd91
5 gewijzigde bestanden met toevoegingen van 14 en 17 verwijderingen
  1. 2 4
      src/botcmd.c
  2. 6 6
      src/cmds.c
  3. 1 1
      src/makeres.c
  4. 1 1
      src/net.c
  5. 4 5
      src/shell.c

+ 2 - 4
src/botcmd.c

@@ -75,8 +75,7 @@ static void bot_chan2(int idx, char *msg)
   /* Strip annoying control chars */
   for (p = from; *p;) {
     if ((*p < 32) || (*p == 127))
-/* FIXME: overlap      strcpy(p, p + 1); */
-      simple_sprintf(p, "%s", p + 1);
+      memmove(p, p + 1, strlen(p));
     else
       p++;
   }
@@ -250,8 +249,7 @@ static void bot_actchan(int idx, char *par)
   chan = base64_to_int(p);
   for (p = from; *p;) {
     if ((*p < 32) || (*p == 127))
-      simple_sprintf(p, "%s", p + 1);
-/* FIXME: overlap      strcpy(p, p + 1); */
+      memmove(p, p + 1, strlen(p));
     else
       p++;
   }

+ 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)
       simple_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");

+ 1 - 1
src/net.c

@@ -1284,7 +1284,7 @@ int sockgets(char *s, int *len)
 	  /* Split up into chunks of SGRAB bytes. */
 	  *len = SGRAB;
 	  egg_memcpy(s, socklist[i].inbuf, *len);
-	  egg_memcpy(socklist[i].inbuf, socklist[i].inbuf + *len, *len);
+	  memmove(socklist[i].inbuf, socklist[i].inbuf + *len, *len);
 	  socklist[i].inbuflen -= *len;
 	  socklist[i].inbuf = (char *) my_realloc(socklist[i].inbuf, socklist[i].inbuflen);
 	}

+ 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;