From: Jonas Maebe Date: Mon, 9 Dec 2013 15:57:04 +0000 (+0100) Subject: serverinfo_process_buffer: check result of realloc(ctx->cert->key->serverinfo) and... X-Git-Tag: master-pre-reformat~119 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e9e688effbd5f94e9a8614ca0181a9c8a596a6e1;p=openssl serverinfo_process_buffer: check result of realloc(ctx->cert->key->serverinfo) and don't leak memory if it fails Signed-off-by: Kurt Roeckx Reviewed-by: Matt Caswell --- diff --git a/ssl/ssl_rsa.c b/ssl/ssl_rsa.c index 6f9337e150..006c02eb03 100644 --- a/ssl/ssl_rsa.c +++ b/ssl/ssl_rsa.c @@ -948,6 +948,8 @@ static int serverinfo_process_buffer(const unsigned char *serverinfo, int SSL_CTX_use_serverinfo(SSL_CTX *ctx, const unsigned char *serverinfo, size_t serverinfo_length) { + unsigned char *new_serverinfo; + if (ctx == NULL || serverinfo == NULL || serverinfo_length == 0) { SSLerr(SSL_F_SSL_CTX_USE_SERVERINFO,ERR_R_PASSED_NULL_PARAMETER); @@ -968,13 +970,14 @@ int SSL_CTX_use_serverinfo(SSL_CTX *ctx, const unsigned char *serverinfo, SSLerr(SSL_F_SSL_CTX_USE_SERVERINFO,ERR_R_INTERNAL_ERROR); return 0; } - ctx->cert->key->serverinfo = OPENSSL_realloc(ctx->cert->key->serverinfo, + new_serverinfo = OPENSSL_realloc(ctx->cert->key->serverinfo, serverinfo_length); - if (ctx->cert->key->serverinfo == NULL) + if (new_serverinfo == NULL) { SSLerr(SSL_F_SSL_CTX_USE_SERVERINFO,ERR_R_MALLOC_FAILURE); return 0; } + ctx->cert->key->serverinfo = new_serverinfo; memcpy(ctx->cert->key->serverinfo, serverinfo, serverinfo_length); ctx->cert->key->serverinfo_length = serverinfo_length;