Skip to content

Commit f2b8b48

Browse files
Zeroize the pKey struct at the beginning of AllocKey to avoid issues on failure and free.
1 parent d917d32 commit f2b8b48

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/internal.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8651,6 +8651,12 @@ int AllocKey(WOLFSSL* ssl, int type, void** pKey)
86518651
return MEMORY_E;
86528652
}
86538653

8654+
/* Zero the allocation before initializing. XMALLOC does not clear memory,
8655+
* and the key-specific init below may fail before it has zeroed/initialized
8656+
* the structure's members. Starting from all-zero makes any partial-init
8657+
* failure safe to free. */
8658+
XMEMSET(*pKey, 0, sz);
8659+
86548660
/* Initialize key */
86558661
switch (type) {
86568662
#ifndef NO_RSA

0 commit comments

Comments
 (0)