summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2023-03-23 00:26:16 +0000
committerLuke Bratch <luke@bratch.co.uk>2023-03-23 00:26:16 +0000
commit85255291678e5cd6d42cdcd19ee413dc96191112 (patch)
tree8eb38ac1d9b36da165cf323f2c883b9de3c6799f
parent7d12838e4c4d97cdd2757a8a7e00df41098e9a73 (diff)
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().
-rw-r--r--functions.c12
-rw-r--r--sockets.c10
2 files changed, 16 insertions, 6 deletions
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
diff --git a/sockets.c b/sockets.c
index c075232..0921e55 100644
--- a/sockets.c
+++ b/sockets.c
@@ -210,6 +210,11 @@ void configure_openssl_context(SSL_CTX *ctx, char *certfile, char *keyfile) {
// Read from a socket, whether or not using TLS
int sockread(SSL *fd, char *buf, int bufsize, int tls) {
+ if (fd == NULL) {
+ debugprint(DEBUG_CRIT, "sockread(): error: fd is NULL, returning.\n");
+ return -1;
+ }
+
if (tls) {
return SSL_read(fd, buf, bufsize);
} else {
@@ -220,6 +225,11 @@ int sockread(SSL *fd, char *buf, int bufsize, int tls) {
// Write to a socket, whether or not using TLS
int socksend(SSL *fd, char *buf, int bufsize, int tls) {
+ if (fd == NULL) {
+ debugprint(DEBUG_CRIT, "socksend(): error: fd is NULL, returning.\n");
+ return -1;
+ }
+
if (tls) {
return SSL_write(fd, buf, bufsize);
} else {