From 27b2967b63aab5cfb6029a9ec018a59f665707bc Mon Sep 17 00:00:00 2001 From: pk910 Date: Thu, 22 Dec 2011 00:24:24 +0100 Subject: [PATCH] fixed crash in modcmd.c (bots could be destroyed inside a function) --- src/modcmd.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/modcmd.c b/src/modcmd.c index 058612a..aca47f6 100644 --- a/src/modcmd.c +++ b/src/modcmd.c @@ -531,6 +531,7 @@ static void got_chanmsg(struct UserNode *user, struct ChanNode *chan, char *mess struct ClientSocket *client; FD_ZERO(&fds); FD_ZERO(&fds2); + got_chanmsg_loop1: for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) { if(isUserOnChan(client->user, chan) && (client->flags & SOCKET_FLAG_PREFERRED) && ((client->botid == 0 && !FD_ISSET(client->clientid, &fds)) || (client->botid && !FD_ISSET(client->botid, &fds2)))) { FD_SET(client->clientid, &fds); @@ -538,16 +539,19 @@ static void got_chanmsg(struct UserNode *user, struct ChanNode *chan, char *mess trigger = get_channel_trigger(client->botid, client->clientid, chan); if(trigger && stricmplen(message, trigger, strlen(trigger)) == 0) { handle_command(client, user, chan, message + strlen(trigger)); + goto got_chanmsg_loop1; //Thats really really bad, i know... But we can't count on the "getBots" list anymore after executing a command } } } + got_chanmsg_loop2: for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) { if(isUserOnChan(client->user, chan) && ((client->botid == 0 && !FD_ISSET(client->clientid, &fds)) || (client->botid && !FD_ISSET(client->botid, &fds2)))) { - FD_SET(client->botid, &fds); + FD_SET(client->clientid, &fds); FD_SET(client->botid, &fds2); trigger = get_channel_trigger(client->botid, client->clientid, chan); if(trigger && stricmplen(message, trigger, strlen(trigger)) == 0) { handle_command(client, user, chan, message + strlen(trigger)); + goto got_chanmsg_loop2; //Thats really really bad, i know... But we can't count on the "getBots" list anymore after executing a command } } } -- 2.20.1