Skip to content

Commit 5adad7d

Browse files
fix for sanity check of null input
1 parent ca3b1a1 commit 5adad7d

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

wolfcrypt/src/pkcs7.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3451,14 +3451,25 @@ int wc_PKCS7_SetCustomSKID(PKCS7* pkcs7, byte* in, word16 inSz)
34513451
return BAD_FUNC_ARG;
34523452
}
34533453

3454-
pkcs7->customSKID = (byte*)XMALLOC(inSz, pkcs7->heap, DYNAMIC_TYPE_PKCS7);
3455-
if (pkcs7->customSKID == NULL) {
3456-
ret = MEMORY_E;
3454+
if (in == NULL) {
3455+
if (pkcs7->customSKID != NULL) {
3456+
XFREE(pkcs7->customSKID, pkcs7->heap, DYNAMIC_TYPE_PKCS7);
3457+
}
3458+
pkcs7->customSKIDSz = 0;
3459+
pkcs7->customSKID = NULL;
34573460
}
34583461
else {
3459-
XMEMCPY(pkcs7->customSKID, in, inSz);
3460-
pkcs7->customSKIDSz = inSz;
3462+
pkcs7->customSKID = (byte*)XMALLOC(inSz, pkcs7->heap,
3463+
DYNAMIC_TYPE_PKCS7);
3464+
if (pkcs7->customSKID == NULL) {
3465+
ret = MEMORY_E;
3466+
}
3467+
else {
3468+
XMEMCPY(pkcs7->customSKID, in, inSz);
3469+
pkcs7->customSKIDSz = inSz;
3470+
}
34613471
}
3472+
34623473
return ret;
34633474
}
34643475

0 commit comments

Comments
 (0)