Skip to content

Commit 00e1fa6

Browse files
committed
Adds tmpSz so int is not cast to word32 in wc_d2i_PKCS12
1 parent 001939d commit 00e1fa6

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

wolfcrypt/src/pkcs12.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,9 @@ int wc_d2i_PKCS12(const byte* der, word32 derSz, WC_PKCS12* pkcs12)
696696
int ret;
697697
int size = 0;
698698
int version = 0;
699+
#ifdef ASN_BER_TO_DER
700+
word32 tmpSz = 0;
701+
#endif
699702

700703
WOLFSSL_ENTER("wolfSSL_d2i_PKCS12");
701704

@@ -717,22 +720,22 @@ int wc_d2i_PKCS12(const byte* der, word32 derSz, WC_PKCS12* pkcs12)
717720
#ifdef ASN_BER_TO_DER
718721
if (size == 0) {
719722
if (wc_BerToDer(der, totalSz, NULL,
720-
(word32*)&size) != WC_NO_ERR_TRACE(LENGTH_ONLY_E)) {
723+
&tmpSz) != WC_NO_ERR_TRACE(LENGTH_ONLY_E)) {
721724
WOLFSSL_MSG("Not BER sequence");
722725
return ASN_PARSE_E;
723726
}
724727

725-
pkcs12->der = (byte*)XMALLOC((size_t)size, pkcs12->heap, DYNAMIC_TYPE_PKCS);
728+
pkcs12->der = (byte*)XMALLOC((size_t)tmpSz, pkcs12->heap, DYNAMIC_TYPE_PKCS);
726729
if (pkcs12->der == NULL)
727730
return MEMORY_E;
728-
ret = wc_BerToDer(der, derSz, pkcs12->der, (word32*)&size);
731+
ret = wc_BerToDer(der, derSz, pkcs12->der, &tmpSz);
729732
if (ret < 0) {
730733
return ret;
731734
}
732735

733736
der = pkcs12->der;
734-
pkcs12->derSz = (word32)size;
735-
totalSz = (word32)size;
737+
pkcs12->derSz = tmpSz;
738+
totalSz = tmpSz;
736739
idx = 0;
737740

738741
if (GetSequence(der, &idx, &size, totalSz) < 0) {

0 commit comments

Comments
 (0)