Explorar o código

Merge branch 'botlink-stack-overflow' into maint

* botlink-stack-overflow:
  * Fix stack overflow in bot linking due to bot continually looping forever between autolink_cycle() via failed_link()
Bryan Drewery %!s(int64=16) %!d(string=hai) anos
pai
achega
d5b2fda3fc
Modificáronse 4 ficheiros con 19 adicións e 11 borrados
  1. 1 1
      src/dcc.c
  2. 2 2
      src/main.c
  3. 14 6
      src/users.c
  4. 2 2
      src/users.h

+ 1 - 1
src/dcc.c

@@ -363,7 +363,7 @@ failed_link(int idx)
   strlcpy(nick, dcc[idx].nick, sizeof(nick));
   lostdcc(idx);
   if (conf.bot->hub || conf.bot->localhub)
-    autolink_cycle(nick);            /* Check for more auto-connections */
+    strlcpy(autolink_failed, nick, HANDLEN + 1);
 }
 
 static void

+ 2 - 2
src/main.c

@@ -524,7 +524,7 @@ static void core_secondly()
   ++cnt;
 
   if (((conf.bot->localhub || conf.bot->hub) && (cnt % 30) == 0) || (cnt % 5) == 0) {
-    autolink_cycle(NULL);         /* attempt autolinks */
+    autolink_cycle();         /* attempt autolinks */
     cnt = 0;
   }
 
@@ -878,7 +878,7 @@ int main(int argc, char **argv)
   }
 
   online_since = now;
-  autolink_cycle(NULL);		/* Hurry and connect to tandem bots */
+  autolink_cycle();		/* Hurry and connect to tandem bots */
   timer_create_secs(1, STR("core_secondly"), (Function) core_secondly);
   timer_create_secs(10, STR("check_expired_dcc"), (Function) check_expired_dcc);
   timer_create_secs(10, STR("core_10secondly"), (Function) core_10secondly);

+ 14 - 6
src/users.c

@@ -57,6 +57,7 @@
 #include "EncryptedStream.h"
 
 char userfile[121] = "";	/* where the user records are stored */
+char autolink_failed[HANDLEN + 1] = "";
 interval_t ignore_time = 10;		/* how many minutes will ignores last? */
 bool	dont_restructure = 0;		/* set when we botlink() to a hub with +U, only stops bot from restructuring */
 
@@ -1003,7 +1004,7 @@ struct userrec *next_hub(struct userrec *current, char *lowval, char *highval)
   return NULL;
 }
 
-void autolink_cycle_hub(char *start)
+static void autolink_cycle_hub(char *start)
 {
   char bestval[HANDLEN + 4] = "", curval[HANDLEN + 4] = "", myval[HANDLEN + 4] = "";
   tand_t *bot = NULL;
@@ -1083,7 +1084,7 @@ typedef struct hublist_entry {
 
 int botlinkcount = 0;
 
-void autolink_random_hub(char *avoidbot) {
+static void autolink_random_hub(char *avoidbot) {
   /* Pick a random hub, but avoid 'avoidbot' */
   int hlc = 0;
   struct hublist_entry *hl = NULL, *hl2 = NULL;
@@ -1125,7 +1126,7 @@ void autolink_random_hub(char *avoidbot) {
   }
 }
 
-void autolink_cycle_leaf(char *start)
+static void autolink_cycle_leaf(char *start)
 {
   struct bot_addr *my_ba = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, conf.bot->u);
   char uplink[HANDLEN + 1] = "", avoidbot[HANDLEN + 1] = "", curhub[HANDLEN + 1] = "";
@@ -1195,12 +1196,19 @@ void autolink_cycle_leaf(char *start)
 }
 
 
-void autolink_cycle(char *start)
+void autolink_cycle()
 {
+  char start[HANDLEN + 1] = "";
+
+  if (autolink_failed[0]) {
+    strlcpy(start, autolink_failed, HANDLEN + 1);
+    autolink_failed[0] = 0;
+  }
+
   if (conf.bot->hub)
-    autolink_cycle_hub(start);
+    autolink_cycle_hub(start[0] ? start : NULL);
   else if (conf.bot->localhub)
-    autolink_cycle_leaf(start);
+    autolink_cycle_leaf(start[0] ? start : NULL);
   else { //Connect to the localhub
     if (tands == 0) {
       // Make sure not already trying for the localhub

+ 2 - 2
src/users.h

@@ -169,7 +169,7 @@ char *delignore(char *);
 void tell_ignores(int, char *);
 bool match_ignore(char *);
 void check_expired_ignores();
-void autolink_cycle(char *);
+void autolink_cycle();
 void tell_file_stats(int, char *);
 void tell_user_ident(int, char *);
 void tell_users_match(int, char *, int, int, char *, int);
@@ -179,7 +179,7 @@ void check_pmode();
 void link_pref_val(struct userrec *u, char *lval);
 void check_stale_dcc_users();
 
-extern char			userfile[];
+extern char			userfile[], autolink_failed[];
 extern interval_t			ignore_time;
 extern bool			dont_restructure;