summaryrefslogtreecommitdiff
path: root/blabouncer.c
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2020-10-21 23:56:50 +0100
committerLuke Bratch <luke@bratch.co.uk>2020-10-21 23:56:50 +0100
commit80881f04e70b1708a303ae71774b87301f8deb38 (patch)
tree417b48760bc30491f7a975350feeb4e8414d90f7 /blabouncer.c
parentb09cbe8b3575ec018f7d73a0bcd751dba011fc72 (diff)
Don't have arrindex() return 0 on failure as 0 is a valid index. Instead return -1 and change callers to check this.
Diffstat (limited to 'blabouncer.c')
-rw-r--r--blabouncer.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/blabouncer.c b/blabouncer.c
index 9604ba3..982d504 100644
--- a/blabouncer.c
+++ b/blabouncer.c
@@ -764,6 +764,14 @@ void dochat(int *serversockfd, int *clientsockfd, struct settings *settings) {
debugprint(DEBUG_FULL, "checking client socket %d out of %d.\n", i, fdmax);
if (FD_ISSET(i, &rfds)) {
debugprint(DEBUG_FULL, "fd %d is FD_ISSET and it is a...\n", i);
+
+ // Index of client fd in clients array for use later
+ int clientindex = arrindex(clients, i);
+ if (clientindex < 0 && i != *clientsockfd) {
+ debugprint(DEBUG_CRIT, "dochat(): error: arrindex() returned '%d', exiting!\n", clientindex);
+ exit(1);
+ }
+
// if value of clientsockfd then must be a new connection, if greater must be an existing connection
if (i == *clientsockfd) {
debugprint(DEBUG_SOME, "...new connection!\n");
@@ -845,15 +853,15 @@ void dochat(int *serversockfd, int *clientsockfd, struct settings *settings) {
debugprint(DEBUG_FULL, "bouncer-client: total client connections: %d\n", numclients(clients));
}
// If using client TLS and still pending SSL_accept() then re-try SSL_accept() (it can't be real client data yet)
- } else if (clients[arrindex(clients, i)].pendingsslaccept) {
+ } else if (clients[clientindex].pendingsslaccept) {
debugprint(DEBUG_FULL, "...previous connection pending SSL_accept!\n");
// Try to SSL_accept(), not interested in return code here since openssl_accept() does the right thing.
- openssl_accept(clients[arrindex(clients, i)].fd, clients, &ircdstate, settings, clientcodes);
+ openssl_accept(clients[clientindex].fd, clients, &ircdstate, settings, clientcodes);
} else {
debugprint(DEBUG_FULL, "...previous connection!\n");
// handle data from a client
- if ((clientnumbytes = sockread(clients[arrindex(clients, i)].ssl, clientbuf, MAXRCVSIZE - 1, settings->clienttls)) <= 0) {
+ if ((clientnumbytes = sockread(clients[clientindex].ssl, clientbuf, MAXRCVSIZE - 1, settings->clienttls)) <= 0) {
// got error or connection closed by client
if (clientnumbytes == 0) {
// connection closed