From d4adf9c516b6a0098571fe579519b88281c1d98a Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Mon, 20 May 2019 18:46:49 +0100 Subject: Don't inform clients about other client disconnections until after clearing the clients array, or we risk trying to send to a socket that's no longer there. --- blabouncer.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'blabouncer.c') diff --git a/blabouncer.c b/blabouncer.c index 23d5217..15b1eb4 100644 --- a/blabouncer.c +++ b/blabouncer.c @@ -262,15 +262,12 @@ int sendtoserver(SSL *server_ssl, char *strsrc, int str_len, int clientfd, struc int disconnectclient(int fd, struct client *clients, struct ircdstrings *ircdstrings, struct settings *settings) { printf("disconnectclient(): disconnecting client fd '%d'\n", fd); - // Alert other clients about the disconnection + // Alert other clients about the disconnection (don't send yet, we haven't removed from the clients array yet) char alertmsg[MAXDATASIZE]; if (!snprintf(alertmsg, MAXDATASIZE, "NOTICE %s :blabouncer: client with fd %d has disconnected.", ircdstrings->ircnick, fd)) { fprintf(stderr, "Error while preparing authentication failure NOTICE!\n"); exit(1); } - // "except" 0 since we trust this message - sendtoallclients(clients, alertmsg, 0, settings); - // Remove the client from the clients array for (int i = 0; i < MAXCLIENTS; i++) { if (clients[i].fd == fd) { @@ -289,6 +286,8 @@ int disconnectclient(int fd, struct client *clients, struct ircdstrings *ircdstr SSL_free(clients[i].ssl); // Close the socket close(fd); + // Now clients array is cleared, inform all other clients (source "0" since we trust this message) + sendtoallclients(clients, alertmsg, 0, settings); return 1; } } -- cgit v1.2.3