Skip to content

Commit 0fe4603

Browse files
committed
F-2976 - https://fenrir.wolfssl.com/finding/2976 - Guard handle auth assignment on success in wolfTPM2_SetIdentityAuth
1 parent a054175 commit 0fe4603

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/tpm2_wrap.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9463,14 +9463,17 @@ int wolfTPM2_SetIdentityAuth(WOLFTPM2_DEV* dev, WOLFTPM2_HANDLE* handle,
94639463
wc_HashFree(&hash_ctx, hashType);
94649464
}
94659465

9466-
/* Hash Final truncate to 16 bytes */
9467-
/* Use 16-byte for auth when accessing key */
9468-
handle->auth.size = 16;
9469-
XMEMCPY(handle->auth.buffer, &digest[16], 16);
9470-
#ifdef DEBUG_WOLFTPM
9471-
printf("Handle 0x%x, Auth %d\n", handle->hndl, handle->auth.size);
9472-
TPM2_PrintBin(handle->auth.buffer, handle->auth.size);
9473-
#endif
9466+
if (rc == 0) {
9467+
/* Hash Final truncate to 16 bytes */
9468+
/* Use 16-byte for auth when accessing key */
9469+
handle->auth.size = 16;
9470+
XMEMCPY(handle->auth.buffer, &digest[16], 16);
9471+
#ifdef DEBUG_WOLFTPM
9472+
printf("Handle 0x%x, Auth %d\n", handle->hndl, handle->auth.size);
9473+
TPM2_PrintBin(handle->auth.buffer, handle->auth.size);
9474+
#endif
9475+
}
9476+
wc_ForceZero(digest, sizeof(digest));
94749477

94759478
(void)dev;
94769479

0 commit comments

Comments
 (0)