Browse Source

m_clearlist: Apparently we can/should free newparv[] after do_cmd() na0, also attempt to fix weird, non-reproducible wind0ngs-only crash

Wazakindjes 3 years ago
parent
commit
522709b546
1 changed files with 22 additions and 22 deletions
  1. 22 22
      u4/m_clearlist.c

+ 22 - 22
u4/m_clearlist.c

@@ -59,7 +59,7 @@ static char *clearListhelp[] = {
 // Dat dere module header
 ModuleHeader MOD_HEADER(m_clearlist) = {
 	"m_clearlist",
-	"$Id: v1.05 2017/11/28 Gottem$",
+	"$Id: v1.06 2018/11/29 Gottem$",
 	"Adds /CLEARLIST <channel> <types> <mask> command to clear out banlists etc",
 	"3.2-b8-1", // Modversion, not sure wat do
 	NULL
@@ -119,14 +119,14 @@ CMD_FUNC(m_clearlist) {
 	** So "CLEARLIST test" would result in parc = 2 and parv[1] = "test"
 	** Also, parv[0] seems to always be NULL, so better not rely on it fam
 	*/
-	Ban **muhList, *ban, *bnext; // Pointer to pointer of banlist, also pointers to ban entries
+	Ban *muhList, *ban, *bnext; // Pointer to em banlist, also pointers to ban entries
 	listType *ltype; // Pointer to our listType struct
 	char flag; // Store current flag/type for dat dere iteration fam
 	char *channel, *types, *rawmask; // Pointers to store arguments
-	char remflags[MAXMODEPARAMS], *remstr[MAXPARA]; // Some buffers to store flags and masks to remove
+	char remflags[MAXMODEPARAMS + 2], *remstr[MAXMODEPARAMS + 1]; // Some buffers to store flags and masks to remove
 	size_t remlen; // Keep track of all masks' lengths =]
 	aChannel *chptr; // Pointer to channel m8
-	int strcount, i; // Keep track of mask counts to do shit like -bbb, also "boolean" to actually delete the list entry
+	int strcount, i, j; // Keep track of mask counts to do shit like -bbb, also "boolean" to actually delete the list entry
 	int tainted, dountaint; // Keep track of whether the current entry is tainted (like ham@*)
 
 	if(BadPtr(parv[1])) // If first argument is a bad pointer, don't proceed
@@ -166,7 +166,7 @@ CMD_FUNC(m_clearlist) {
 		strcount = 0; // Set count to 0
 		dountaint = 0; // Reset untaint flag for every bantype obv fam
 		memset(remflags, 0, sizeof(remflags)); // Reset flags to remove entirely
-		for(i = 0; i < MAXPARA; i++) remstr[i] = NULL; // Ditto for the masks
+		for(i = 0; i <= MAXMODEPARAMS; i++) remstr[i] = NULL; // Ditto for the masks
 		remflags[0] = '-'; // Lil hack =]
 		remlen = 0;
 
@@ -175,18 +175,16 @@ CMD_FUNC(m_clearlist) {
 
 		// Check what flag this is m9
 		switch(flag) {
-			// We have **banList so we can actually modify the "live" list, instead of just a shitty copy
-
 			case 'b': // Banned lol
-				muhList = &chptr->banlist; // Quality reference
+				muhList = chptr->banlist; // Quality reference
 				break;
 
 			case 'e': // Ban exception
-				muhList = &chptr->exlist; // Ayyyy
+				muhList = chptr->exlist; // Ayyyy
 				break;
 
 			case 'I': // Yay invex
-				muhList = &chptr->invexlist; // Lmao
+				muhList = chptr->invexlist; // Lmao
 				break;
 
 			default: // Just a safeguard imo tbh
@@ -194,7 +192,7 @@ CMD_FUNC(m_clearlist) {
 		}
 
 		// Loop over all entries in the current list
-		for(ban = *muhList; ban; ban = bnext) {
+		for(ban = muhList; ban; ban = bnext) {
 			tainted = 0; // Not tainted yet
 			bnext = ban->next; // Already get the next entry here, since we may delete the current one
 			// Does the entry's mask match the given arg? (match() does bighek with wildcards)
@@ -204,29 +202,31 @@ CMD_FUNC(m_clearlist) {
 					dountaint = 1; // Only need one tainted hit cuz it's majikk =]
 
 				remflags[strcount + 1] = flag; // Add this flag to our remflags array
-				remstr[strcount] = ban->banstr; // Gotta dup 'em for do_cmd cuz inb4rip =]
+				remstr[strcount] = ban->banstr;
 				strcount++; // Increment strcount later cuz muh first char = index 0
 				remlen += strlen(ban->banstr); // Increment em lol
 			}
 
 			// We'll use at least 5 masks together, until the banstring lengths exceed 200 chars or if we run out of entries
-			if((strcount >= 5 && remlen >= 200) || !ban->next || strcount >= MAXMODEPARAMS) {
+			if((strcount >= 5 && remlen >= 200) || !ban->next || strcount >= MAXMODEPARAMS || (strcount + 2) >= MAXPARA) {
 				// Apparently using "* " for mask with active entries results in a weird MODE message
 				if(!strchr(remflags, flag)) // So let's skip that shit
 					continue;
 
 				char *newparv[MAXPARA + 1]; // Gonna need new parv lol
-				newparv[0] = strdup(sptr->name); // Gotta
-				newparv[1] = strdup(channel); // dup
-				newparv[2] = strdup(remflags); // 'em
-				for(i = 3; remstr[i - 3]; i++)
-					newparv[i] = strdup(remstr[i - 3]); // all
+				newparv[0] = strdup(sptr->name); // Make sure none of these variables get directly modified somehow
+				newparv[1] = strdup(channel);
+				newparv[2] = strdup(remflags);
+				for(i = 3, j = 0; i < MAXPARA && remstr[j]; i++, j++)
+					newparv[i] = strdup(remstr[j]);
 				newparv[i] = NULL; // Some functions may depend on this ;]
-
 				int suppresshack = do_cmd(sptr, sptr, "MODE", i, newparv); // This shit takes care of removing it locally as well as br0adcasting it ;]
-				strcount = 0; // Reset counter
-				memset(remflags, 0, sizeof(remflags)); // Reset flags
-				for(i = 0; i < MAXPARA; i++) remstr[i] = NULL; // Ditto for the masks
+
+				// Reset that shit lol
+				strcount = 0;
+				memset(remflags, 0, sizeof(remflags));
+				for(i = 0; newparv[i]; i++) free(newparv[i]);
+				for(i = 0; i <= MAXMODEPARAMS; i++) remstr[i] = NULL; // Ditto for the masks
 				remflags[0] = '-'; // Lil hack =]
 				remlen = 0;
 			}