diff options
author | Luke Bratch <luke@bratch.co.uk> | 2023-03-23 00:26:16 +0000 |
---|---|---|
committer | Luke Bratch <luke@bratch.co.uk> | 2023-03-23 00:26:16 +0000 |
commit | 85255291678e5cd6d42cdcd19ee413dc96191112 (patch) | |
tree | 8eb38ac1d9b36da165cf323f2c883b9de3c6799f /sockets.c | |
parent | 7d12838e4c4d97cdd2757a8a7e00df41098e9a73 (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().
Diffstat (limited to 'sockets.c')
-rw-r--r-- | sockets.c | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -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 { |