Skip to content

Commit b2913d2

Browse files
authored
Merge pull request #9842 from rlm2002/coverity
20260227 Coverity changes
2 parents 36328e3 + 682901e commit b2913d2

2 files changed

Lines changed: 17 additions & 11 deletions

File tree

wolfcrypt/src/asn.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
4221542218
static 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)
4225542260
static 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);

wolfcrypt/src/hpke.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,12 @@ static int I2OSP(int n, int w, byte* out)
101101
{
102102
int i;
103103

104-
if (w <= 0 || w > 32) {
104+
if (w <= 0 || w > 32 || n < 0) {
105105
return MP_VAL;
106106
}
107107

108108
/* if width is less than int max check that n is less than w bytes max */
109-
/* if width is greater than int max check that n is less than int max */
110-
if ((w < 4 && n > ((1 << (w * 8)) - 1)) || (w >= 4 && n > 0x7fffffff)) {
109+
if (w < 4 && n > ((1 << (w * 8)) - 1)) {
111110
return MP_VAL;
112111
}
113112

0 commit comments

Comments
 (0)