ccm: Fix memory leak on failed ICV verification if not using in-place decryption

Fixes: 80a93a1335 ("Implemented a ccm plugin providing CCM mode based on CBC crypters")
This commit is contained in:
Tobias Brunner
2026-07-22 18:20:12 +02:00
parent 40aa0a12c4
commit 85c02dc16c
+11 -6
View File
@@ -283,17 +283,22 @@ METHOD(aead_t, decrypt, bool,
return FALSE; return FALSE;
} }
encrypted.len -= this->icv_size; encrypted.len -= this->icv_size;
if (plain) if (!plain)
{ {
*plain = chunk_alloc(encrypted.len);
return crypt_data(this, iv, encrypted, *plain) &&
verify_icv(this, *plain, assoc, iv,
encrypted.ptr + encrypted.len);
}
return crypt_data(this, iv, encrypted, encrypted) && return crypt_data(this, iv, encrypted, encrypted) &&
verify_icv(this, encrypted, assoc, iv, verify_icv(this, encrypted, assoc, iv,
encrypted.ptr + encrypted.len); encrypted.ptr + encrypted.len);
} }
*plain = chunk_alloc(encrypted.len);
if (crypt_data(this, iv, encrypted, *plain) &&
verify_icv(this, *plain, assoc, iv,
encrypted.ptr + encrypted.len))
{
return TRUE;
}
chunk_free(plain);
return FALSE;
}
METHOD(aead_t, get_block_size, size_t, METHOD(aead_t, get_block_size, size_t,
private_ccm_aead_t *this) private_ccm_aead_t *this)