Selaa lähdekoodia

Fix crash when clearing last botset entry for a bot.

This avoids redundantly deleting/freeing the last list entry due to
set_gotshare() ignoring e and not passing it along to set_set() and
because set_user() is used later which matches the share code
Bryan Drewery 8 vuotta sitten
vanhempi
commit
4843c4cb50
3 muutettua tiedostoa jossa 12 lisäystä ja 1 poistoa
  1. 1 0
      doc/UPDATES.md
  2. 9 1
      src/mod/share.mod/share.cc
  3. 2 0
      src/userent.cc

+ 1 - 0
doc/UPDATES.md

@@ -1,5 +1,6 @@
 # maint
   * Clear FiSH keys when a client quits.
+  * Fix crash when clearing last botset entry for a bot.
 
 # 1.4.9
   * Fix various compile warnings and spam

+ 9 - 1
src/mod/share.mod/share.cc

@@ -655,7 +655,7 @@ share_change(int idx, char *par)
         return;
       }
 
-      if (uet->got_share) {
+      if (uet->got_share && uet != &USERENTRY_SET) {
         if (!(e = find_user_entry(uet, u))) {
           e = (struct user_entry *) calloc(1, sizeof(struct user_entry));
 
@@ -669,6 +669,14 @@ share_change(int idx, char *par)
           list_delete((struct list_type **) &(u->entries), (struct list_type *) e);
           free(e);
         }
+      } else if (uet == &USERENTRY_SET) {
+        /*
+         * set_set() chains down to set_user() which mimics
+         * the above and leads to deleting/freeing 'e' when
+         * already done in set_user(). set_gotshare() ignores
+         * e.
+         */
+        uet->got_share(u, NULL, par, idx);
       }
       noshare = 0;
     }

+ 2 - 0
src/userent.cc

@@ -335,6 +335,8 @@ static bool set_gotshare(struct userrec *u, struct user_entry *e, char *buf, int
 {
   char *name = newsplit(&buf);
 
+  ASSERT(e == NULL, "set_gotshare should not be passed a user_entry");
+
   if (!name || !name[0])
     return 1;