summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2019-05-20 18:46:49 +0100
committerLuke Bratch <luke@bratch.co.uk>2019-05-20 18:46:49 +0100
commitd4adf9c516b6a0098571fe579519b88281c1d98a (patch)
tree9d78e0365108c5f9218a2445df941398ed4b9212
parent954aafdf50559dc9f868f79aacbdfdb0bf8bbb3b (diff)
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.
-rw-r--r--blabouncer.c7
1 files changed, 3 insertions, 4 deletions
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;
}
}