Skip to content

Commit

Permalink
Resolve hash new leak due to improper heap hint check. Make sure isAl…
Browse files Browse the repository at this point in the history
…located is initialized to 0.
  • Loading branch information
dgarske committed Sep 25, 2024
1 parent 85296c6 commit 32ed473
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion wolfcrypt/src/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,7 @@ int wc_HashInit_ex(wc_HashAlg* hash, enum wc_HashType type, void* heap,
if (hash == NULL)
return BAD_FUNC_ARG;

hash->isAllocated = 0;
switch (type) {
case WC_HASH_TYPE_MD5:
#ifndef NO_MD5
Expand Down Expand Up @@ -1146,8 +1147,9 @@ int wc_HashFree(wc_HashAlg* hash, enum wc_HashType type)
ret = BAD_FUNC_ARG;
};

if (isAllocated && heap)
if (isAllocated) {
XFREE(hash, heap, DYNAMIC_TYPE_HASHES);
}

return ret;
}
Expand Down

0 comments on commit 32ed473

Please sign in to comment.