Skip to content

Commit d721f7b

Browse files
committed
Fix finding 355
1 parent e8c4fec commit d721f7b

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

examples/wrap/wrap_test.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ int TPM2_Wrapper_TestArgs(void* userCtx, int argc, char *argv[])
989989
/* PCR TESTS */
990990
/*------------------------------------------------------------------------*/
991991
/* Read PCR Index 0 */
992-
hashSz = 0;
992+
hashSz = sizeof(hashBuf);
993993
rc = wolfTPM2_ReadPCR(&dev, 0, TEST_WRAP_DIGEST, hashBuf, &hashSz);
994994
if (rc != 0) goto exit;
995995

@@ -1001,6 +1001,7 @@ int TPM2_Wrapper_TestArgs(void* userCtx, int argc, char *argv[])
10011001
if (rc != 0 && !WOLFTPM_IS_COMMAND_UNAVAILABLE(rc)) goto exit;
10021002

10031003
/* Read PCR Index 0 */
1004+
hashSz = sizeof(hashBuf);
10041005
rc = wolfTPM2_ReadPCR(&dev, 0, TEST_WRAP_DIGEST, hashBuf, &hashSz);
10051006
if (rc != 0) goto exit;
10061007
printf("PCR Test pass\n");

src/tpm2_wrap.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4804,8 +4804,22 @@ int wolfTPM2_ReadPCR(WOLFTPM2_DEV* dev, int pcrIndex, int hashAlg, byte* digest,
48044804
}
48054805

48064806
digestLen = (int)pcrReadOut.pcrValues.digests[0].size;
4807-
if (digest)
4807+
if (digest) {
4808+
if (pDigestLen == NULL) {
4809+
#ifdef DEBUG_WOLFTPM
4810+
printf("TPM2_PCR_Read: NULL pDigestLen with non-NULL digest\n");
4811+
#endif
4812+
return BAD_FUNC_ARG;
4813+
}
4814+
if (*pDigestLen < (int)pcrReadOut.pcrValues.digests[0].size) {
4815+
#ifdef DEBUG_WOLFTPM
4816+
printf("TPM2_PCR_Read: Digest buffer too small %d -> %d\n",
4817+
*pDigestLen, (int)pcrReadOut.pcrValues.digests[0].size);
4818+
#endif
4819+
return BUFFER_E;
4820+
}
48084821
XMEMCPY(digest, pcrReadOut.pcrValues.digests[0].buffer, digestLen);
4822+
}
48094823

48104824
#ifdef DEBUG_WOLFTPM
48114825
printf("TPM2_PCR_Read: Index %d, Digest Sz %d, Update Counter %d\n",

0 commit comments

Comments
 (0)