From 82ab48d41bfef30ab51b407b48dfcda9ebc5f7e7 Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Sun, 5 Jan 2020 22:25:22 +0000 Subject: Fix some situations where the remote IP of a connecting/disconnecting client is wrong in the debug log and NOTICEs. --- message.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'message.c') diff --git a/message.c b/message.c index 7d50f0a..2c6eb16 100644 --- a/message.c +++ b/message.c @@ -846,12 +846,15 @@ int processclientmessage(SSL *server_ssl, char *str, struct client *clients, int } } } else { - debugprint(DEBUG_SOME, "Password rejected, disconnecting client %s with fd %d.\n", clients[arrindex(clients, sourcefd)].remoteip, sourcefd); + // Store the client's IP address for now, since we need to refer to it after disconnecting + // them (thus clearing the array entry that the IP is read from) + char remoteip[INET6_ADDRSTRLEN]; + strncpy(remoteip, clients[arrindex(clients, sourcefd)].remoteip, INET6_ADDRSTRLEN); + debugprint(DEBUG_SOME, "Password rejected, disconnecting client %s with fd %d.\n", remoteip, sourcefd); disconnectclient(sourcefd, clients, ircdstate, settings, clientcodes); // Alert other clients about the failed authentication char alertmsg[MAXDATASIZE]; - if (!snprintf(alertmsg, MAXDATASIZE, "NOTICE %s :blabouncer: new client %s has failed to authenticate.", ircdstate->ircnick, - clients[arrindex(clients, sourcefd)].remoteip)) { + if (!snprintf(alertmsg, MAXDATASIZE, "NOTICE %s :blabouncer: new client %s failed to authenticate.", ircdstate->ircnick, remoteip)) { fprintf(stderr, "Error while preparing authentication failure NOTICE!\n"); debugprint(DEBUG_CRIT, "Error while preparing authentication failure NOTICE!\n"); alertmsg[0] = '\0'; -- cgit v1.2.3