From 4b1a4e5bfa4ad797050cbb323671b50d4a2367d5 Mon Sep 17 00:00:00 2001 From: Stefan Berger Date: Thu, 22 Jul 2021 21:23:58 -0400 Subject: [PATCH 1/2] tpm2: Initialize a whole OBJECT before using it Initialize a whole OBJECT before using it. This is necessary since an OBJECT may also be used as a HASH_OBJECT via the ANY_OBJECT union and that HASH_OBJECT can leave bad size inidicators in TPM2B buffer in the OBJECT. To get rid of this problem we reset the whole OBJECT to 0 before using it. This is as if the memory for the OBJECT was just initialized. Signed-off-by: Stefan Berger --- src/tpm2/Object.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tpm2/Object.c b/src/tpm2/Object.c index a70254c..bd98fd9 100644 --- a/src/tpm2/Object.c +++ b/src/tpm2/Object.c @@ -284,7 +284,8 @@ FindEmptyObjectSlot( if(handle) *handle = i + TRANSIENT_FIRST; // Initialize the object attributes - MemorySet(&object->attributes, 0, sizeof(OBJECT_ATTRIBUTES)); + // MemorySet(&object->attributes, 0, sizeof(OBJECT_ATTRIBUTES)); + MemorySet(object, 0, sizeof(*object)); // libtpms added: Initialize the whole object return object; } } -- 2.33.0.rc2