1
0
Эх сурвалжийг харах

* Ported [2730] and [2731] to 1.2.10 (tempdir crap)

svn: 2733
Bryan Drewery 20 жил өмнө
parent
commit
ff72bec90e

+ 1 - 0
doc/UPDATES

@@ -63,6 +63,7 @@ Lines prefixed with '-' were disabled before release and are not finished, or ar
 * Unsetting auth-prefix disables authing/cmds.
 * Unsetting auth-prefix disables authing/cmds.
 * Fixed segfault in cmd_slowpart (#191)
 * Fixed segfault in cmd_slowpart (#191)
 * Fixed a memory leak in the cookie checking functions.
 * Fixed a memory leak in the cookie checking functions.
+* Fixed some segfaults with tempfiles
 
 
 1.2.8
 1.2.8
 * Fixed [bot]* cmds depending on case of botnicks.
 * Fixed [bot]* cmds depending on case of botnicks.

+ 3 - 0
src/binary.c

@@ -96,6 +96,9 @@ bin_checksum(const char *fname, int todo)
     char *fname_bak = NULL;
     char *fname_bak = NULL;
     size_t size = 0, newpos = 0;
     size_t size = 0, newpos = 0;
 
 
+    if (!newbin || newbin->error)
+      werr(ERR_TMPSTAT);
+
     size = strlen(fname) + 2;
     size = strlen(fname) + 2;
     fname_bak = (char *) my_calloc(1, size);
     fname_bak = (char *) my_calloc(1, size);
     simple_snprintf(fname_bak, size, "%s~", fname);
     simple_snprintf(fname_bak, size, "%s~", fname);

+ 6 - 1
src/misc.c

@@ -636,8 +636,10 @@ restart(int idx)
   Tempfile *socks = new Tempfile("socks");
   Tempfile *socks = new Tempfile("socks");
   int fd = 0;
   int fd = 0;
 
 
-  sdprintf("%s", reason); 
+  if (!socks || socks->error)
+    werr(ERR_TMPSTAT);
 
 
+  sdprintf("%s", reason); 
 
 
   if (tands > 0) {
   if (tands > 0) {
     botnet_send_chat(-1, conf.bot->nick, (char *) reason);
     botnet_send_chat(-1, conf.bot->nick, (char *) reason);
@@ -788,6 +790,9 @@ int updatebin(int idx, char *par, int secs)
 
 
   Tempfile *conffile = new Tempfile("conf");
   Tempfile *conffile = new Tempfile("conf");
 
 
+  if (!conffile || conffile->error)
+    return 1;
+
   if (writeconf(NULL, conffile->f, CONF_ENC)) {
   if (writeconf(NULL, conffile->f, CONF_ENC)) {
     putlog(LOG_MISC, "*", "Failed to write temporary config file for update.");
     putlog(LOG_MISC, "*", "Failed to write temporary config file for update.");
     delete conffile;
     delete conffile;

+ 11 - 8
src/misc_file.c

@@ -223,6 +223,9 @@ static bool check_tempdir(bool do_mod)
   Tempfile *testdir = new Tempfile("test");
   Tempfile *testdir = new Tempfile("test");
   int result;
   int result;
 
 
+  if (!testdir || testdir->error)
+    return 0;
+
   fprintf(testdir->f, "\n");
   fprintf(testdir->f, "\n");
   result = fflush(testdir->f);
   result = fflush(testdir->f);
   delete testdir;
   delete testdir;
@@ -276,17 +279,17 @@ void Tempfile::FindDir()
   };
   };
   int i = 0;
   int i = 0;
   bool found = 0;
   bool found = 0;
-  char *pack_hash = NULL;
+//  char *pack_hash = NULL;
 
 
-  if (settings_crypt == PACK_DEC) {
-    pack_hash = MD5(settings.packname);
-    pack_hash[5] = 0;
-  }
+//  if (settings_crypt == PACK_DEC) {
+//    pack_hash = MD5(settings.packname);
+//    pack_hash[5] = 0;
+//  }
 
 
   for (i = 0; dirs[i]; i++) {
   for (i = 0; dirs[i]; i++) {
-    if (pack_hash)
-      simple_snprintf(tempdir, DIRMAX, "%s.%s/", dirs[i], pack_hash);
-    else
+//    if (pack_hash)
+//      simple_snprintf(tempdir, DIRMAX, "%s.%s/", dirs[i], pack_hash);
+//    else
       strlcpy(tempdir, dirs[i], DIRMAX);
       strlcpy(tempdir, dirs[i], DIRMAX);
     if (check_tempdir(0)) {
     if (check_tempdir(0)) {
       found = 1;
       found = 1;

+ 1 - 1
src/mod/update.mod/update.c

@@ -293,7 +293,7 @@ static void start_sending_binary(int idx)
 
 
 #ifdef old
 #ifdef old
   /* copy the binary to our tempdir and send that one. */
   /* copy the binary to our tempdir and send that one. */
-  sprintf(tmpFile, "%s.%s", tempdir, update_file);
+  //simple_snprintf(tmpFile, sizeof(tmpFile), "%s.%s", tempdir, update_file);
   unlink(tmpFile);
   unlink(tmpFile);
   copyfile(update_fpath, tmpFile);
   copyfile(update_fpath, tmpFile);
 #endif
 #endif