aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/bio/b_sock.c
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2016-05-04 10:38:02 +0100
committerMatt Caswell <matt@openssl.org>2016-05-04 13:42:14 +0100
commitad9a05621ac75b6b9db1e8856d7f434276b1a7af (patch)
tree748441437219540fb92f83bcb24acf6dbae02300 /crypto/bio/b_sock.c
parentd5975c8d5a171551dd42ffa18ca12e84f29ad106 (diff)
downloadopenssl-ad9a05621ac75b6b9db1e8856d7f434276b1a7af.tar.gz
Handle malloc failures in BIO_accept
The old BIO_accept() function can encounter errors during malloc. We need to ensure we properly clean up if that occurs. GH Issue #817 Reviewed-by: Richard Levitte <levitte@openssl.org>
Diffstat (limited to 'crypto/bio/b_sock.c')
-rw-r--r--crypto/bio/b_sock.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/crypto/bio/b_sock.c b/crypto/bio/b_sock.c
index 071acda48e..dc14a1b587 100644
--- a/crypto/bio/b_sock.c
+++ b/crypto/bio/b_sock.c
@@ -311,10 +311,20 @@ int BIO_accept(int sock, char **ip_port)
if (ip_port != NULL) {
char *host = BIO_ADDR_hostname_string(&res, 1);
char *port = BIO_ADDR_service_string(&res, 1);
- *ip_port = OPENSSL_zalloc(strlen(host) + strlen(port) + 2);
- strcpy(*ip_port, host);
- strcat(*ip_port, ":");
- strcat(*ip_port, port);
+ if (host != NULL && port != NULL)
+ *ip_port = OPENSSL_zalloc(strlen(host) + strlen(port) + 2);
+ else
+ *ip_port = NULL;
+
+ if (*ip_port == NULL) {
+ BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE);
+ BIO_closesocket(ret);
+ ret = (int)INVALID_SOCKET;
+ } else {
+ strcpy(*ip_port, host);
+ strcat(*ip_port, ":");
+ strcat(*ip_port, port);
+ }
OPENSSL_free(host);
OPENSSL_free(port);
}