Skip to content

Commit 00fff0f

Browse files
committed
Zeroize PKCS#8 DER staging area in PEM write helper
F-2148 pem_write_mem_pkcs8privatekey stages the PKCS#8 DER encoded private key at the tail of the PEM buffer, then writes the shorter PEM output at the head of the same buffer. The DER tail is not overwritten, leaking the plaintext private key to heap memory after the callers free. Zero the DER staging area before returning.
1 parent 87e5c62 commit 00fff0f

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/pk.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7208,6 +7208,12 @@ static int pem_write_mem_pkcs8privatekey(byte** pem, int* pemSz,
72087208
}
72097209
}
72107210

7211+
/* Zero the DER staging area at the tail of the buffer so the plaintext
7212+
* private key material is not left in freed heap memory. */
7213+
if (key != NULL && keySz > 0) {
7214+
ForceZero(key, keySz);
7215+
}
7216+
72117217
/* Return appropriate return code. */
72127218
return (res == 0) ? 0 : ret;
72137219

0 commit comments

Comments
 (0)