Skip to content

Commit 0ded703

Browse files
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
1 parent 8c1144b commit 0ded703

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/common/hmac.c

+5
Original file line numberDiff line numberDiff line change
@@ -232,17 +232,22 @@ pg_hmac_final(pg_hmac_ctx *ctx, uint8 *dest, size_t len)
232232
memset(h, 0, ctx->digest_size);
233233

234234
if (pg_cryptohash_final(ctx->hash, h, ctx->digest_size) < 0)
235+
{
236+
FREE(h);
235237
return -1;
238+
}
236239

237240
/* H(K XOR opad, tmp) */
238241
if (pg_cryptohash_init(ctx->hash) < 0 ||
239242
pg_cryptohash_update(ctx->hash, ctx->k_opad, ctx->block_size) < 0 ||
240243
pg_cryptohash_update(ctx->hash, h, ctx->digest_size) < 0 ||
241244
pg_cryptohash_final(ctx->hash, dest, len) < 0)
242245
{
246+
FREE(h);
243247
return -1;
244248
}
245249

250+
FREE(h);
246251
return 0;
247252
}
248253

0 commit comments

Comments
 (0)