Ver código fonte

* Fixed another fatal bug with cmd_conf, this should fix it for good.
* Cleaned up limits on binary data parsing


svn: 2261

Bryan Drewery 21 anos atrás
pai
commit
41e719727d
5 arquivos alterados com 23 adições e 15 exclusões
  1. 1 0
      doc/UPDATES
  2. 18 13
      src/binary.c
  3. 1 1
      src/binary.h
  4. 1 1
      src/cmds.c
  5. 2 0
      src/conf.c

+ 1 - 0
doc/UPDATES

@@ -23,6 +23,7 @@ Lines prefixed with '-' were disabled before release and are not finished, or ar
 * Added a 5 second delay on requesting/checking ops when no bots are available to ask.
 * Fixed 16 bytes after packdata being cleared in memory, causing random memory corruption.
 * Fixed localhub attempting to spawn itself during binary rehash and cmd_conf
+* Fixed another fatal bug with cmd_conf, this should fix it for good.
 
 1.2.4
 * Fixed cmd_botset not displaying botnick.

+ 18 - 13
src/binary.c

@@ -348,7 +348,7 @@ static void edpack(settings_t *incfg, const char *hash, int what)
 #undef dofield
 }
 
-/* 
+#ifdef DEBUG 
 static void
 tellconfig(settings_t *incfg)
 {
@@ -381,7 +381,7 @@ tellconfig(settings_t *incfg)
   dofield(incfg->portmax);
 #undef dofield
 }
-*/
+#endif
 
 void
 check_sum(const char *fname, const char *cfgfile)
@@ -402,7 +402,9 @@ check_sum(const char *fname, const char *cfgfile)
 
 // tellconfig(&settings); 
     edpack(&settings, hash, PACK_DEC);
-// tellconfig(&settings); 
+#ifdef DEBUG
+ tellconfig(&settings); 
+#endif
 
     if (strcmp(settings.hash, hash)) {
       unlink(fname);
@@ -462,15 +464,17 @@ void write_settings(const char *fname, int die, bool conf)
 static void 
 clear_settings(void)
 {
-  egg_memset(&settings.bots, 0, sizeof(settings_t) - SIZE_PACK - PREFIXLEN);
+//  egg_memset(&settings.bots, 0, sizeof(settings_t) - SIZE_PACK - PREFIXLEN);
+  egg_memset(&settings.bots, 0, SIZE_CONF);
 }
 
-void conf_to_bin(conf_t *in, bool move, int die)
+void conf_to_bin(conf_t *in, bool move, int die, bool clear)
 {
   conf_bot *bot = NULL;
   char *newbin = NULL;
 
-  clear_settings();
+  if (clear)
+    clear_settings();
   sdprintf("converting conf to bin\n");
   simple_sprintf(settings.uid, "%d", in->uid);
   simple_sprintf(settings.watcher, "%d", in->watcher);
@@ -480,15 +484,16 @@ void conf_to_bin(conf_t *in, bool move, int die)
   simple_sprintf(settings.portmax, "%d", in->portmax);
   simple_sprintf(settings.pscloak, "%d", in->pscloak);
 
-  strlcpy(settings.binname, in->binname, 51);
-  strlcpy(settings.username, in->username, 16);
+  strlcpy(settings.binname, in->binname, sizeof(settings.binname));
+  strlcpy(settings.username, in->username, sizeof(settings.username));
 
-  strlcpy(settings.uname, in->uname, 350);
-  strlcpy(settings.tempdir, in->tempdir, 1024);
-  strlcpy(settings.homedir, in->homedir, 1024);
-  strlcpy(settings.binpath, in->binpath, 1024);
+  strlcpy(settings.uname, in->uname, sizeof(settings.uname));
+  strlcpy(settings.tempdir, in->tempdir, sizeof(settings.tempdir));
+  strlcpy(settings.homedir, in->homedir, sizeof(settings.homedir));
+  strlcpy(settings.binpath, in->binpath, sizeof(settings.binpath));
   for (bot = in->bots; bot && bot->nick; bot = bot->next) {
-    simple_sprintf(settings.bots, "%s%s%s %s %s%s %s,", settings.bots && settings.bots[0] ? settings.bots : "",
+    simple_snprintf(settings.bots, sizeof(settings.bots), "%s%s%s %s %s%s %s,", 
+                           settings.bots && settings.bots[0] ? settings.bots : "",
                            bot->disabled ? "/" : "",
                            bot->nick,
                            bot->net.ip ? bot->net.ip : ".", 

+ 1 - 1
src/binary.h

@@ -13,6 +13,6 @@ extern int checked_bin_buf;
 
 void check_sum(const char *, const char *);
 void write_settings(const char *, int, bool);
-void conf_to_bin(conf_t *, bool, int);
+void conf_to_bin(conf_t *, bool, int, bool clear = 1);
 void reload_bin_data();
 #endif /* !_BINARY_H */

+ 1 - 1
src/cmds.c

@@ -1726,7 +1726,7 @@ static void cmd_conf(int idx, char *par)
 
   if (save) {
     /* rewrite our binary */
-    conf_to_bin(&conf, 0, -1);
+    conf_to_bin(&conf, 0, -1, 0);
 
     kill_removed_bots(oldlist, conf.bots);
     conf_add_userlist_bots();

+ 2 - 0
src/conf.c

@@ -979,6 +979,8 @@ fill_conf_bot()
   } else
     mynick = strdup(origbotname);
 
+  sdprintf("mynick: %s", mynick);
+
   for (me = conf.bots; me && me->nick; me = me->next)
     if (!egg_strcasecmp(me->nick, mynick))
       break;