Skip to content

Commit 04d4feb

Browse files
committed
tests: free the AES context on a GCM key failure
test_DoReceive_AeadTagFailure() marks decryptCipher initialized and sets its cipher type as soon as wc_AesInit() succeeds, so a later wc_AesGcmSetKey() failure still leaves wolfSSH_free() a context that CipherClear() will free. Matches what CipherSetKey() does in the library. - give the key-set failure its own result code, so the split reports which of the two calls failed
1 parent 49975da commit 04d4feb

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

‎tests/unit.c‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,13 +1827,19 @@ static int test_DoReceive_AeadTagFailure(void)
18271827
/* Tamper with a ciphertext byte so the tag check must fail. */
18281828
record[UINT32_SZ] ^= 0x01;
18291829

1830-
if (wc_AesInit(&ssh->decryptCipher.aes, ssh->ctx->heap, INVALID_DEVID) != 0
1831-
|| wc_AesGcmSetKey(&ssh->decryptCipher.aes, key, sizeof(key)) != 0) {
1830+
if (wc_AesInit(&ssh->decryptCipher.aes, ssh->ctx->heap,
1831+
INVALID_DEVID) != 0) {
18321832
result = -226;
18331833
goto done;
18341834
}
1835+
/* claim the context before setting the key so wolfSSH_free frees it
1836+
* even if the key set fails */
18351837
ssh->decryptCipher.isInit = 1;
18361838
ssh->decryptCipher.cipherType = ID_AES256_GCM;
1839+
if (wc_AesGcmSetKey(&ssh->decryptCipher.aes, key, sizeof(key)) != 0) {
1840+
result = -230;
1841+
goto done;
1842+
}
18371843
ssh->peerEncryptId = ID_AES256_GCM;
18381844
ssh->peerAeadMode = 1;
18391845
ssh->peerBlockSz = AES_BLOCK_SIZE;

0 commit comments

Comments
 (0)