summaryrefslogtreecommitdiffstats
path: root/crypto/bio/b_addr.c
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2016-05-04 11:14:48 +0100
committerMatt Caswell <matt@openssl.org>2016-05-18 10:47:15 +0100
commit24854e0117000b81319665154c93e15743bf7de6 (patch)
tree5cbf18e691065b3b427f840f760d857b297a8777 /crypto/bio/b_addr.c
parent690b462126048d4d8ea3376cf13b4833d9f8801d (diff)
Fix some malloc failures in b_addr.c
There were some unchecked calls to OPENSSL_strdup(). Reviewed-by: Richard Levitte <levitte@openssl.org>
Diffstat (limited to 'crypto/bio/b_addr.c')
-rw-r--r--crypto/bio/b_addr.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/crypto/bio/b_addr.c b/crypto/bio/b_addr.c
index bb6719eb2a..3a9a00c121 100644
--- a/crypto/bio/b_addr.c
+++ b/crypto/bio/b_addr.c
@@ -228,21 +228,35 @@ static int addr_strings(const BIO_ADDR *ap, int numeric,
ntohs(BIO_ADDR_rawport(ap)));
}
- if (hostname)
+ if (hostname != NULL)
*hostname = OPENSSL_strdup(host);
- if (service)
+ if (service != NULL)
*service = OPENSSL_strdup(serv);
} else {
#endif
- if (hostname)
+ if (hostname != NULL)
*hostname = OPENSSL_strdup(inet_ntoa(ap->s_in.sin_addr));
- if (service) {
+ if (service != NULL) {
char serv[6]; /* port is 16 bits => max 5 decimal digits */
BIO_snprintf(serv, sizeof(serv), "%d", ntohs(ap->s_in.sin_port));
*service = OPENSSL_strdup(serv);
}
}
+ if ((hostname != NULL && *hostname == NULL)
+ || (service != NULL && *service == NULL)) {
+ if (hostname != NULL) {
+ OPENSSL_free(*hostname);
+ *hostname = NULL;
+ }
+ if (service != NULL) {
+ OPENSSL_free(*service);
+ *service = NULL;
+ }
+ BIOerr(BIO_F_ADDR_STRINGS, ERR_R_MALLOC_FAILURE);
+ return 0;
+ }
+
return 1;
}