aboutsummaryrefslogtreecommitdiffstats
path: root/ssl
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>2016-05-11 21:14:57 +0100
committerDr. Stephen Henson <steve@openssl.org>2016-05-12 12:02:38 +0100
commit7c0ef8431845ea741012a5a6ff7063dca801fadd (patch)
tree29a5fe81356f6baf98b7d6162367879cd1e38ecb /ssl
parent3dfcb6a0ecbc210899e4b674331d0294189281b9 (diff)
downloadopenssl-7c0ef8431845ea741012a5a6ff7063dca801fadd.tar.gz
Don't leak memory if realloc fails.
RT#4403 Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
Diffstat (limited to 'ssl')
-rw-r--r--ssl/ssl_rsa.c6
-rw-r--r--ssl/t1_ext.c12
2 files changed, 11 insertions, 7 deletions
diff --git a/ssl/ssl_rsa.c b/ssl/ssl_rsa.c
index f1280ad01f..88dce79ace 100644
--- a/ssl/ssl_rsa.c
+++ b/ssl/ssl_rsa.c
@@ -940,6 +940,7 @@ int SSL_CTX_use_serverinfo(SSL_CTX *ctx, const unsigned char *serverinfo,
int SSL_CTX_use_serverinfo_file(SSL_CTX *ctx, const char *file)
{
unsigned char *serverinfo = NULL;
+ unsigned char *tmp;
size_t serverinfo_length = 0;
unsigned char *extension = 0;
long extension_length = 0;
@@ -999,12 +1000,13 @@ int SSL_CTX_use_serverinfo_file(SSL_CTX *ctx, const char *file)
goto end;
}
/* Append the decoded extension to the serverinfo buffer */
- serverinfo =
+ tmp =
OPENSSL_realloc(serverinfo, serverinfo_length + extension_length);
- if (serverinfo == NULL) {
+ if (tmp == NULL) {
SSLerr(SSL_F_SSL_CTX_USE_SERVERINFO_FILE, ERR_R_MALLOC_FAILURE);
goto end;
}
+ serverinfo = tmp;
memcpy(serverinfo + serverinfo_length, extension, extension_length);
serverinfo_length += extension_length;
diff --git a/ssl/t1_ext.c b/ssl/t1_ext.c
index 3bbe1fd826..281613185e 100644
--- a/ssl/t1_ext.c
+++ b/ssl/t1_ext.c
@@ -205,7 +205,7 @@ static int custom_ext_meth_add(custom_ext_methods *exts,
void *add_arg,
custom_ext_parse_cb parse_cb, void *parse_arg)
{
- custom_ext_method *meth;
+ custom_ext_method *meth, *tmp;
/*
* Check application error: if add_cb is not set free_cb will never be
* called.
@@ -225,15 +225,17 @@ static int custom_ext_meth_add(custom_ext_methods *exts,
/* Search for duplicate */
if (custom_ext_find(exts, ext_type))
return 0;
- exts->meths = OPENSSL_realloc(exts->meths,
- (exts->meths_count +
- 1) * sizeof(custom_ext_method));
+ tmp = OPENSSL_realloc(exts->meths,
+ (exts->meths_count + 1) * sizeof(custom_ext_method));
- if (!exts->meths) {
+ if (tmp == NULL) {
+ OPENSSL_free(exts->meths);
+ exts->meths = NULL;
exts->meths_count = 0;
return 0;
}
+ exts->meths = tmp;
meth = exts->meths + exts->meths_count;
memset(meth, 0, sizeof(*meth));
meth->parse_cb = parse_cb;