@@ -810,7 +810,7 @@ static int tpm2_ifx_cap_vendor_get(WOLFTPM2_CAPS* cap, uint32_t property,
810810 if (rc == TPM_RC_SUCCESS ) {
811811 TPM2B_MAX_BUFFER * buf = & out .capabilityData .data .vendor ;
812812 /* 4 bytes=count + 2 bytes=len + vendor value */
813- if (buf -> buffer [3 ] == 1 && buf -> buffer [5 ] == valSz ) {
813+ if (buf -> size >= ( int )( 6 + valSz ) && buf -> buffer [3 ] == 1 && buf -> buffer [5 ] == valSz ) {
814814 XMEMCPY (val , & buf -> buffer [6 ], valSz );
815815 if (valSz == 2 ) {
816816 * ((uint16_t * )val ) = be16_to_cpu (* ((uint16_t * )val ));
@@ -1615,6 +1615,8 @@ static int wolfTPM2_EncryptSecret_RSA(WOLFTPM2_DEV* dev, const WOLFTPM2_KEY* tpm
16151615
16161616 wc_FreeRsaKey (& rsaKey );
16171617 wc_FreeRng (& rng );
1618+ TPM2_ForceZero (& rsaKey , sizeof (rsaKey ));
1619+ TPM2_ForceZero (& rng , sizeof (rng ));
16181620
16191621 if (rc > 0 ) {
16201622 rc = (rc == secret -> size ) ? 0 /* success */ : BUFFER_E /* fail */ ;
@@ -1630,15 +1632,15 @@ int wolfTPM2_EncryptSecret(WOLFTPM2_DEV* dev, const WOLFTPM2_KEY* tpmKey,
16301632{
16311633 int rc = NOT_COMPILED_IN ;
16321634
1635+ if (dev == NULL || data == NULL || secret == NULL ) {
1636+ return BAD_FUNC_ARG ;
1637+ }
1638+
16331639 /* if a tpmKey is not present then we are using an unsalted session */
16341640 if (tpmKey == NULL ) {
16351641 return TPM_RC_SUCCESS ;
16361642 }
16371643
1638- if (dev == NULL || data == NULL || secret == NULL ) {
1639- return BAD_FUNC_ARG ;
1640- }
1641-
16421644#ifdef DEBUG_WOLFTPM
16431645 printf ("Encrypt secret: Alg %s, Label %s\n" ,
16441646 TPM2_GetAlgName (tpmKey -> pub .publicArea .type ), label );
@@ -3275,7 +3277,7 @@ int wolfTPM2_ExportPublicKeyBuffer(WOLFTPM2_DEV* dev, WOLFTPM2_KEY* tpmKey,
32753277 #endif
32763278 } key ;
32773279
3278- if (dev == NULL || tpmKey == NULL ) {
3280+ if (dev == NULL || tpmKey == NULL || outSz == NULL ) {
32793281 return BAD_FUNC_ARG ;
32803282 }
32813283
@@ -4995,17 +4997,14 @@ int wolfTPM2_NVCreateAuthPolicy(WOLFTPM2_DEV* dev, WOLFTPM2_HANDLE* parent,
49954997 #endif
49964998 return rc ;
49974999 }
4998- if (rc == TPM_RC_SUCCESS && alreadyExists )
4999- rc = TPM_RC_NV_DEFINED ;
5000-
50015000 /* compute NV object with name */
50025001 XMEMSET (nv , 0 , sizeof (* nv ));
50035002 rctmp = wolfTPM2_NVOpen (dev , nv , nvIndex , auth , authSz );
50045003 if (rctmp != TPM_RC_SUCCESS )
50055004 rc = rctmp ;
50065005
50075006#ifdef DEBUG_WOLFTPM
5008- printf ("TPM2_NV_DefineSpace: Auth 0x%x, Idx 0x%x, Attribs 0x%d , Size %d\n" ,
5007+ printf ("TPM2_NV_DefineSpace: Auth 0x%x, Idx 0x%x, Attribs 0x%x , Size %d\n" ,
50095008 (word32 )in .authHandle ,
50105009 (word32 )in .publicInfo .nvPublic .nvIndex ,
50115010 (word32 )in .publicInfo .nvPublic .attributes ,
@@ -6291,16 +6290,19 @@ int wolfTPM2_UnloadHandles(WOLFTPM2_DEV* dev, word32 handleStart,
62916290 word32 handleCount )
62926291{
62936292 int rc = TPM_RC_SUCCESS ;
6294- word32 hndl ;
6293+ word32 i ;
62956294 WOLFTPM2_HANDLE handle ;
62966295 if (dev == NULL ) {
62976296 return BAD_FUNC_ARG ;
62986297 }
6298+ if (handleCount != 0 && handleStart > (word32 )0xFFFFFFFF - (handleCount - 1 )) {
6299+ return BAD_FUNC_ARG ;
6300+ }
62996301 XMEMSET (& handle , 0 , sizeof (handle ));
63006302 wolfTPM2_CopyAuth (& handle .auth , & dev -> session [0 ].auth );
63016303
6302- for (hndl = handleStart ; hndl < handleStart + handleCount ; hndl ++ ) {
6303- handle .hndl = hndl ;
6304+ for (i = 0 ; i < handleCount ; i ++ ) {
6305+ handle .hndl = handleStart + i ;
63046306 /* ignore return code failures */
63056307 (void )wolfTPM2_UnloadHandle (dev , & handle );
63066308 }
0 commit comments