Skip to content

Commit 8a0c7a9

Browse files
ejohnstownphilljj
authored andcommitted
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 34a9939 commit 8a0c7a9

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
@@ -1866,13 +1866,19 @@ static int test_DoReceive_AeadTagFailure(void)
18661866
/* Tamper with a ciphertext byte so the tag check must fail. */
18671867
record[UINT32_SZ] ^= 0x01;
18681868

1869-
if (wc_AesInit(&ssh->decryptCipher.aes, ssh->ctx->heap, INVALID_DEVID) != 0
1870-
|| wc_AesGcmSetKey(&ssh->decryptCipher.aes, key, sizeof(key)) != 0) {
1869+
if (wc_AesInit(&ssh->decryptCipher.aes, ssh->ctx->heap,
1870+
INVALID_DEVID) != 0) {
18711871
result = -226;
18721872
goto done;
18731873
}
1874+
/* claim the context before setting the key so wolfSSH_free frees it
1875+
* even if the key set fails */
18741876
ssh->decryptCipher.isInit = 1;
18751877
ssh->decryptCipher.cipherType = ID_AES256_GCM;
1878+
if (wc_AesGcmSetKey(&ssh->decryptCipher.aes, key, sizeof(key)) != 0) {
1879+
result = -230;
1880+
goto done;
1881+
}
18761882
ssh->peerEncryptId = ID_AES256_GCM;
18771883
ssh->peerAeadMode = 1;
18781884
ssh->peerBlockSz = AES_BLOCK_SIZE;

0 commit comments

Comments
 (0)