summaryrefslogtreecommitdiffstats
path: root/crypto/modes/ocb128.c
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 /crypto/modes/ocb128.c
parent3dfcb6a0ecbc210899e4b674331d0294189281b9 (diff)
Don't leak memory if realloc fails.
RT#4403 Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
Diffstat (limited to 'crypto/modes/ocb128.c')
-rw-r--r--crypto/modes/ocb128.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/crypto/modes/ocb128.c b/crypto/modes/ocb128.c
index 3c17aa5287..cb99d094ab 100644
--- a/crypto/modes/ocb128.c
+++ b/crypto/modes/ocb128.c
@@ -147,6 +147,7 @@ static OCB_BLOCK *ocb_lookup_l(OCB128_CONTEXT *ctx, size_t idx)
/* We don't have it - so calculate it */
if (idx >= ctx->max_l_index) {
+ void *tmp_ptr;
/*
* Each additional entry allows to process almost double as
* much data, so that in linear world the table will need to
@@ -157,10 +158,11 @@ static OCB_BLOCK *ocb_lookup_l(OCB128_CONTEXT *ctx, size_t idx)
* the index.
*/
ctx->max_l_index += (idx - ctx->max_l_index + 4) & ~3;
- ctx->l =
+ tmp_ptr =
OPENSSL_realloc(ctx->l, ctx->max_l_index * sizeof(OCB_BLOCK));
- if (ctx->l == NULL)
+ if (tmp_ptr == NULL) /* prevent ctx->l from being clobbered */
return NULL;
+ ctx->l = tmp_ptr;
}
while (l_index < idx) {
ocb_double(ctx->l + l_index, ctx->l + l_index + 1);