summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Gustafsson2021-10-01 20:47:05 +0000
committerDaniel Gustafsson2021-10-01 20:47:05 +0000
commit0ded7039fab314afb7cbaf36b52209f253c05539 (patch)
tree900efb736b147f5335bb6f72661ac7801fb5a1b3
parent8c1144ba73478b818d9cebe8ecd64a14b7d45bde (diff)
Fix memory leak in pg_hmac
The intermittent h buffer was not freed, causing it to leak. Backpatch through 14 where HMAC was refactored to the current API. Author: Sergey Shinderuk <[email protected]> Discussion: https://postgr.es/m/[email protected] Backpatch-through: 14
-rw-r--r--src/common/hmac.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/common/hmac.c b/src/common/hmac.c
index 1089db6744..bfe2e7cb5e 100644
--- a/src/common/hmac.c
+++ b/src/common/hmac.c
@@ -232,7 +232,10 @@ pg_hmac_final(pg_hmac_ctx *ctx, uint8 *dest, size_t len)
memset(h, 0, ctx->digest_size);
if (pg_cryptohash_final(ctx->hash, h, ctx->digest_size) < 0)
+ {
+ FREE(h);
return -1;
+ }
/* H(K XOR opad, tmp) */
if (pg_cryptohash_init(ctx->hash) < 0 ||
@@ -240,9 +243,11 @@ pg_hmac_final(pg_hmac_ctx *ctx, uint8 *dest, size_t len)
pg_cryptohash_update(ctx->hash, h, ctx->digest_size) < 0 ||
pg_cryptohash_final(ctx->hash, dest, len) < 0)
{
+ FREE(h);
return -1;
}
+ FREE(h);
return 0;
}