[X2serv-cvs] CVS: x2/source chan.c,1.64,1.65
Brought to you by:
sirvulcan
From: Alex S. <ru...@us...> - 2001-01-19 23:37:05
|
Update of /cvsroot/x2serv/x2/source In directory usw-pr-cvs1:/tmp/cvs-serv21928 Modified Files: chan.c Log Message: Cleaned up the banned handling functions a bit. Discovered a bugin DelChan where the banned list was being free'd but the inital pointer not set to NULL.. THEN the function would call channel_massunban (which it should NOT have been calling at all) which would crash, due to cptr->banned being free'd random value. Index: chan.c =================================================================== RCS file: /cvsroot/x2serv/x2/source/chan.c,v retrieving revision 1.64 retrieving revision 1.65 diff -C2 -r1.64 -r1.65 *** chan.c 2001/01/14 19:04:55 1.64 --- chan.c 2001/01/19 23:37:10 1.65 *************** *** 1129,1133 **** ChannelUsersListType jptr, jptr_next; LamerListType lptr, lptr_next; ! BanListType bptr, bptr_next; int Pos; --- 1129,1133 ---- ChannelUsersListType jptr, jptr_next; LamerListType lptr, lptr_next; ! BanListType bptr, Nextbptr; int Pos; *************** *** 1161,1170 **** DelHandle(CurrPtr, hptr); } - /* Delete bans */ - for(bptr = CurrPtr->banned;bptr; bptr = bptr_next) - { - bptr_next = bptr->Next; - free(bptr); - } /* Delete channeluser's entries */ for(jptr = CurrPtr->Joined;jptr;jptr = jptr_next) --- 1161,1164 ---- *************** *** 1173,1177 **** free(jptr); } ! channel_massunban(CurrPtr); /* Delete lamer list */ for(lptr = CurrPtr->Lamers;lptr;lptr = lptr_next) --- 1167,1176 ---- free(jptr); } ! for(bptr = CurrPtr->banned;bptr;bptr = Nextbptr) ! { ! Nextcptr = bptr->Next; ! free(bptr); ! } ! CurrPtr->banned = NULL; /* Delete lamer list */ for(lptr = CurrPtr->Lamers;lptr;lptr = lptr_next) *************** *** 1594,1617 **** int delete_ban(ChannelListType cptr, char *banstring) { ! BanListType *b_list; ! BanListType *old; ! BanListType Dummy; ! b_list = &cptr->banned; ! if ((Dummy = search_ban(cptr, banstring)) == NULL) return (FALSE); ! for (old = b_list; *old; old = &(*old)->Next) { ! Debug(DBGINFO, "*** In delete_ban loop: %s\n", &(*old)->banstring); ! if (*old == Dummy) { ! Debug(DBGINFO, "*** Found the match."); ! *old = Dummy->Next; ! free(Dummy); return (TRUE); } } - Debug(DBGINFO, "*** NULL encountered. Ban not found. Returning.\n"); return (FALSE); } --- 1593,1616 ---- int delete_ban(ChannelListType cptr, char *banstring) { ! BanListType bptr; ! BanListType theban; ! BanListType PrevBan; ! if ((theban = search_ban(cptr, banstring)) == NULL) return (FALSE); ! for (bptr = PrevBan = cptr->banned; bptr; bptr = bptr->Next) { ! if (bptr == theban) { ! if(bptr == cptr->banned) ! cptr->banned = bptr->Next; ! else ! PrevBan->Next = bptr->Next; ! free(bptr); return (TRUE); } + PrevBan = bptr; } return (FALSE); } *************** *** 1808,1812 **** int channel_massunban(ChannelListType Channel) { ! BanListType Dummy; char unbanmode[10]; char unbanstring[1024]; --- 1807,1811 ---- int channel_massunban(ChannelListType Channel) { ! BanListType bptr, oldbptr; char unbanmode[10]; char unbanstring[1024]; *************** *** 1820,1825 **** if(Channel->settings[INCHAN] == FALSE) return(0); /* Not in channel */ ! Dummy = Channel->banned; ! while (Dummy) { /* We can't just -bbb ban1 ban2, --- 1819,1824 ---- if(Channel->settings[INCHAN] == FALSE) return(0); /* Not in channel */ ! bptr = Channel->banned; ! while (bptr) { /* We can't just -bbb ban1 ban2, *************** *** 1829,1839 **** strcpy(unbanstring, ""); i = 0; ! while (Dummy && (i < 6)) { strcat(unbanmode, "b"); strcat(unbanstring, " "); ! strcat(unbanstring, Dummy->banstring); i++; ! Dummy = Dummy->Next; found++; } --- 1828,1840 ---- strcpy(unbanstring, ""); i = 0; ! while (bptr && (i < 6)) { strcat(unbanmode, "b"); strcat(unbanstring, " "); ! strcat(unbanstring, bptr->banstring); i++; ! oldbptr = bptr; ! bptr = bptr->Next; ! free(oldbptr); found++; } *************** *** 1849,1853 **** int channel_unban(ChannelListType Channel, char* banstring) { ! BanListType Dummy, tmp; char unbanmode[5]; char unbanstring[MAXLEN]; --- 1850,1854 ---- int channel_unban(ChannelListType Channel, char* banstring) { ! BanListType bptr, tmp; char unbanmode[5]; char unbanstring[MAXLEN]; *************** *** 1861,1884 **** return(0); /* Not in channel */ } ! Dummy = Channel->banned; ! while (Dummy) { strcpy(unbanmode, "-"); strcpy(unbanstring, ""); i = 0; ! while (Dummy && (i < 3)) { ! tmp = Dummy->Next; ! if (!matches(Dummy->banstring, banstring) || !strcmp(banstring, Dummy->banstring)) { strcat(unbanmode, "b"); strcat(unbanstring, " "); ! strcat(unbanstring, Dummy->banstring); ! Debug(DBGINFO, "*** channel_unban calling delete_ban for %s", Dummy->banstring); ! delete_ban(Channel, Dummy->banstring); i++; found++; } ! Dummy = tmp; } send_chanmode(Channel, "%s %s", unbanmode, unbanstring); --- 1862,1885 ---- return(0); /* Not in channel */ } ! bptr = Channel->banned; ! while (bptr) { strcpy(unbanmode, "-"); strcpy(unbanstring, ""); i = 0; ! while (bptr && (i < 3)) { ! tmp = bptr->Next; ! if (!matches(bptr->banstring, banstring) || !strcmp(banstring, bptr->banstring)) { strcat(unbanmode, "b"); strcat(unbanstring, " "); ! strcat(unbanstring, bptr->banstring); ! Debug(DBGINFO, "*** channel_unban calling delete_ban for %s", bptr->banstring); ! delete_ban(Channel, bptr->banstring); i++; found++; } ! bptr = tmp; } send_chanmode(Channel, "%s %s", unbanmode, unbanstring); *************** *** 1892,1900 **** BanListType search_ban(ChannelListType cptr, char *banstring) { ! BanListType Banned; ! for (Banned = cptr->banned; Banned; Banned = Banned->Next) ! if (!strcasecmp(Banned->banstring, banstring)) ! return (Banned); return (NULL); } --- 1893,1901 ---- BanListType search_ban(ChannelListType cptr, char *banstring) { ! BanListType bptr; ! for (bptr = cptr->banned; bptr; bptr = bptr->Next) ! if (!strcasecmp(bptr->banstring, banstring)) ! return (bptr); return (NULL); } |