Skip to content

Commit 27bada5

Browse files
committed
F-2976 - https://fenrir.wolfssl.com/finding/2976 - Guard handle auth assignment on success in wolfTPM2_SetIdentityAuth
1 parent 547fcda commit 27bada5

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

src/tpm2_wrap.c

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

9394-
/* Hash Final truncate to 16 bytes */
9395-
/* Use 16-byte for auth when accessing key */
9396-
handle->auth.size = 16;
9397-
XMEMCPY(handle->auth.buffer, &digest[16], 16);
9398-
#ifdef DEBUG_WOLFTPM
9399-
printf("Handle 0x%x, Auth %d\n", handle->hndl, handle->auth.size);
9400-
TPM2_PrintBin(handle->auth.buffer, handle->auth.size);
9401-
#endif
9394+
if (rc == 0) {
9395+
/* Hash Final truncate to 16 bytes */
9396+
/* Use 16-byte for auth when accessing key */
9397+
handle->auth.size = 16;
9398+
XMEMCPY(handle->auth.buffer, &digest[16], 16);
9399+
#ifdef DEBUG_WOLFTPM
9400+
printf("Handle 0x%x, Auth %d\n", handle->hndl, handle->auth.size);
9401+
TPM2_PrintBin(handle->auth.buffer, handle->auth.size);
9402+
#endif
9403+
}
9404+
wc_ForceZero(digest, sizeof(digest));
94029405

94039406
(void)dev;
94049407

0 commit comments

Comments
 (0)