Fix for use of unititlized PKCS7.isDynamic case in unit test. Added return code checks for wc_PKCS7_Init.

This commit is contained in:
David Garske 2018-07-02 09:38:14 -07:00
parent 3adbb07abe
commit fb3d3dce0e
2 changed files with 11 additions and 3 deletions

View File

@ -14278,6 +14278,7 @@ static void test_wc_PKCS7_InitWithCert (void)
#endif
printf(testingFmt, "wc_PKCS7_InitWithCert()");
/* If initialization is not successful, it's free'd in init func. */
pkcs7.isDynamic = 0;
AssertIntEQ(wc_PKCS7_InitWithCert(&pkcs7, (byte*)cert, (word32)certSz), 0);
wc_PKCS7_Free(&pkcs7);

View File

@ -233,8 +233,13 @@ PKCS7* wc_PKCS7_New(void* heap, int devId)
PKCS7* pkcs7 = (PKCS7*)XMALLOC(sizeof(PKCS7), heap, DYNAMIC_TYPE_PKCS7);
if (pkcs7) {
XMEMSET(pkcs7, 0, sizeof(PKCS7));
wc_PKCS7_Init(pkcs7, heap, devId);
pkcs7->isDynamic = 1;
if (wc_PKCS7_Init(pkcs7, heap, devId) == 0) {
pkcs7->isDynamic = 1;
}
else {
XFREE(pkcs7, heap, DYNAMIC_TYPE_PKCS7);
pkcs7 = NULL;
}
}
return pkcs7;
}
@ -284,7 +289,9 @@ int wc_PKCS7_InitWithCert(PKCS7* pkcs7, byte* cert, word32 certSz)
heap = pkcs7->heap;
devId = pkcs7->devId;
isDynamic = pkcs7->isDynamic;
wc_PKCS7_Init(pkcs7, heap, devId);
ret = wc_PKCS7_Init(pkcs7, heap, devId);
if (ret != 0)
return ret;
pkcs7->isDynamic = isDynamic;
if (cert != NULL && certSz > 0) {