Skip to content

Commit 2c34210

Browse files
committed
Coverity scan fixes
DecodeRsaPssParams() assumed params is never NULL. Should never be called with NULL but check saves a NULL dereference. PrintObjectIdText() didn't check return of call to GetObjectId. 'oid' will retain -1 value on error and work as normal on error return. Cleaner to check for ASN_PARSE_E and handle - other error, ASN_UNKNOWN_OID_E, is OK for printing.
1 parent a595f10 commit 2c34210

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

wolfcrypt/src/asn.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6146,6 +6146,7 @@ enum {
61466146
* @param [out] hash Hash algorithm to use on message.
61476147
* @param [out] mgf MGF algorithm to use with PSS padding.
61486148
* @param [out] saltLen Length of salt in PSS padding.
6149+
* @return BAD_FUNC_ARG when the params is NULL.
61496150
* @return ASN_PARSE_E when the decoding fails.
61506151
* @return 0 on success.
61516152
*/
@@ -6160,7 +6161,10 @@ static int DecodeRsaPssParams(const byte* params, word32 sz,
61606161
byte tag;
61616162
int length;
61626163

6163-
if (GetSequence_ex(params, &idx, &len, sz, 1) < 0) {
6164+
if (params == NULL) {
6165+
ret = BAD_FUNC_ARG;
6166+
}
6167+
if ((ret == 0) && (GetSequence_ex(params, &idx, &len, sz, 1) < 0)) {
61646168
ret = ASN_PARSE_E;
61656169
}
61666170
if (ret == 0) {
@@ -6252,6 +6256,10 @@ static int DecodeRsaPssParams(const byte* params, word32 sz,
62526256
int ret = 0;
62536257
word16 sLen = 20;
62546258

6259+
if (params == NULL) {
6260+
ret = BAD_FUNC_ARG;
6261+
}
6262+
62556263
CALLOC_ASNGETDATA(dataASN, rsaPssParamsASN_Length, ret, NULL);
62566264
if (ret == 0) {
62576265
word32 inOutIdx = 0;
@@ -37228,8 +37236,11 @@ static void PrintObjectIdText(Asn1* asn1, Asn1PrintOptions* opts)
3722837236
int known = 1;
3722937237

3723037238
/* Get the OID value for the OBJECT_ID. */
37231-
GetObjectId(asn1->data + asn1->offset, &i, &oid, oidIgnoreType,
37232-
asn1->item.len + 2);
37239+
if (GetObjectId(asn1->data + asn1->offset, &i, &oid, oidIgnoreType,
37240+
asn1->item.len + 2) == ASN_PARSE_E) {
37241+
known = 0;
37242+
}
37243+
else
3723337244
#if !defined(WOLFCRYPT_ONLY) && defined(OPENSSL_EXTRA)
3723437245
/* Lookup NID for OID value. */
3723537246
if ((nid = oid2nid(oid, oidIgnoreType)) != -1) {

0 commit comments

Comments
 (0)