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(). --- sockets.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'sockets.c') 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 { -- cgit v1.2.3