@@ -7846,6 +7846,9 @@ word32 wc_EncodeRsaPssAlgoId(int hashOID, int saltLen, byte* out, word32 outSz)
78467846 if (outSz < outerSz) {
78477847 idx = 0; goto pss_algoid_done;
78487848 }
7849+ if (hashAlgSz > RSA_PSS_ALGOID_TMPBUF_SZ) {
7850+ idx = 0; goto pss_algoid_done;
7851+ }
78497852
78507853 {
78517854 word32 idPart = (word32)SetObjectId((int)rsapssOidSz, NULL) + rsapssOidSz;
@@ -11376,8 +11379,7 @@ int wc_RsaPublicKeyDecode_ex(const byte* input, word32* inOutIdx, word32 inSz,
1137611379 if (ret != 0) {
1137711380 /* Didn't work - try whole SubjectKeyInfo instead. Reset index
1137811381 * to caller's start since the previous attempt advanced it. */
11379- if (inOutIdx != NULL)
11380- *inOutIdx = startIdx;
11382+ *inOutIdx = startIdx;
1138111383 #ifdef WC_RSA_PSS
1138211384 /* Could be RSA or RSA PSS key. */
1138311385 GetASN_OID(&dataASN[RSAPUBLICKEYASN_IDX_ALGOID_OID], oidKeyType);
@@ -27618,6 +27620,7 @@ int PemToDer(const unsigned char* buff, long longSz, int type,
2761827620#ifdef OPENSSL_EXTRA
2761927621 char beginBuf[PEM_LINE_LEN + 1]; /* add 1 for null terminator */
2762027622 char endBuf[PEM_LINE_LEN + 1]; /* add 1 for null terminator */
27623+ int origType = type;
2762127624#endif
2762227625#ifdef WOLFSSL_ENCRYPTED_KEYS
2762327626 int hashType = WC_HASH_TYPE_NONE;
@@ -27740,9 +27743,9 @@ int PemToDer(const unsigned char* buff, long longSz, int type,
2774027743
2774127744 if (!headerEnd) {
2774227745#ifdef OPENSSL_EXTRA
27743- if (type == PRIVATEKEY_TYPE
27746+ if (origType == PRIVATEKEY_TYPE
2774427747#ifdef WOLFSSL_DUAL_ALG_CERTS
27745- || type == ALT_PRIVATEKEY_TYPE
27748+ || origType == ALT_PRIVATEKEY_TYPE
2774627749#endif
2774727750 ) {
2774827751 /* see if there is a -----BEGIN * PRIVATE KEY----- header */
@@ -42214,17 +42217,19 @@ static int EncodeCrlSerial(const byte* sn, word32 snSz, byte* output,
4221442217 */
4221542218static word32 EncodeRevokedCert(byte* output, const RevokedCert* rc)
4221642219{
42220+ int tmpSnSz;
4221742221 word32 idx = 0;
4221842222 word32 snSz, dateSz, seqSz;
4221942223 byte snBuf[MAX_SN_SZ];
4222042224 byte dateBuf[MAX_DATE_SIZE + 2]; /* tag + length + data */
4222142225 byte seqBuf[MAX_SEQ_SZ];
4222242226
4222342227 /* Encode serial number */
42224- snSz = (word32) EncodeCrlSerial(rc->serialNumber, (word32)rc->serialSz,
42228+ tmpSnSz = EncodeCrlSerial(rc->serialNumber, (word32)rc->serialSz,
4222542229 snBuf, sizeof(snBuf));
42226- if ((int)snSz < 0)
42230+ if (tmpSnSz < 0)
4222742231 return 0;
42232+ snSz = (word32)tmpSnSz;
4222842233
4222942234 /* Encode revocation date */
4223042235 dateSz = EncodeCrlDate(dateBuf, rc->revDate, rc->revDateFormat);
@@ -42255,6 +42260,7 @@ static word32 EncodeRevokedCert(byte* output, const RevokedCert* rc)
4225542260static word32 EncodeCrlNumberExt(byte* output, const byte* crlNum,
4225642261 word32 crlNumSz)
4225742262{
42263+ int tmpIntSz;
4225842264 word32 idx = 0;
4225942265 word32 oidSz, intSz, octetSz, seqSz;
4226042266 byte seqBuf[MAX_SEQ_SZ];
@@ -42266,9 +42272,10 @@ static word32 EncodeCrlNumberExt(byte* output, const byte* crlNum,
4226642272 oidSz = sizeof(crlNumOid);
4226742273
4226842274 /* Encode the INTEGER for CRL number */
42269- intSz = (word32) EncodeCrlSerial(crlNum, crlNumSz, intBuf, sizeof(intBuf));
42270- if ((int)intSz < 0)
42275+ tmpIntSz = EncodeCrlSerial(crlNum, crlNumSz, intBuf, sizeof(intBuf));
42276+ if (tmpIntSz < 0)
4227142277 return 0;
42278+ intSz = (word32)tmpIntSz;
4227242279
4227342280 /* Wrap INTEGER in OCTET STRING */
4227442281 octetSz = SetOctetString(intSz, octetBuf);
0 commit comments