From 85255291678e5cd6d42cdcd19ee413dc96191112 Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Thu, 23 Mar 2023 00:26:16 +0000 Subject: Don't try to sockread() or socksend() if the file descriptor is NULL, assume all socksend() return values of <0 are errors, correct (currently unused) return values in sendtoserver(). --- functions.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'functions.c') diff --git a/functions.c b/functions.c index fcb1799..cd56904 100644 --- a/functions.c +++ b/functions.c @@ -476,7 +476,7 @@ int sendtoclient(int fd, char *strsrc, struct client *clients, struct settings * } debugprint(DEBUG_SOME, "sendtoclient(): sending \"%s\" (length %zd) to client with fd %d.\n", str, strlen(str), fd); - if (socksend(clients[i].ssl, str, strlen(str), settings->clienttls) == -1) { + if (socksend(clients[i].ssl, str, strlen(str), settings->clienttls) < 0) { debugprint(DEBUG_CRIT, "error: sendtoclient() socksend() error sending to client with fd '%d', errno '%d'.\n", fd, errno); return 0; } @@ -545,7 +545,7 @@ int sendtoallclients(struct client *clients, char *strsrc, int except, struct se continue; } debugprint(DEBUG_SOME, "sendtoallclients(): %s: sending '%s' to client with fd %d.\n", sendertype, str, clients[i].fd); - if (socksend(clients[i].ssl, str, strlen(str), settings->clienttls) == -1) { + if (socksend(clients[i].ssl, str, strlen(str), settings->clienttls) < 0) { debugprint(DEBUG_CRIT, "error: sendtoallclients() socksend() error sending to client with fd '%d', errno '%d'.\n", clients[i].fd, errno); } } @@ -588,18 +588,18 @@ int sendtoserver(SSL *server_ssl, char *strsrc, int str_len, int clientfd, struc // Found client in array, check authentication status if (!clients[i].authed) { debugprint(DEBUG_SOME, "sendtoserver(): skipping unauthenticated client with fd %d.\n", clients[i].fd); - return 1; + return 0; } } } debugprint(DEBUG_SOME, "sendtoserver(): sending '%s' to IRC server (length %d).\n", str, str_len); - if (socksend(server_ssl, str, str_len, settings->servertls) == -1) { + if (socksend(server_ssl, str, str_len, settings->servertls) < 0) { debugprint(DEBUG_CRIT, "error: sendtoserver() socksend() error sending to server, errno '%d'.\n", clientfd, errno); - return 1; + return 0; } - return 0; + return 1; } // Disconnect the client fd "fd" by close()ing it and remove -- cgit v1.2.3