Skip to content

Commit

Permalink
Coverity Fix Null Check (#1965)
Browse files Browse the repository at this point in the history
`X509_ATTRIBUTE_count` dereferences `a` without a NULL check, added it
in.

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license and the ISC license.
  • Loading branch information
smittals2 authored Nov 5, 2024
1 parent 8f1aae9 commit d5c7252
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions crypto/x509/x509_att.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype,
}

int X509_ATTRIBUTE_count(const X509_ATTRIBUTE *attr) {
if (attr == NULL) {
return 0;
}
return (int)sk_ASN1_TYPE_num(attr->set);
}

Expand Down
3 changes: 2 additions & 1 deletion include/openssl/x509.h
Original file line number Diff line number Diff line change
Expand Up @@ -2272,7 +2272,8 @@ OPENSSL_EXPORT int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype,
OPENSSL_EXPORT void *X509_ATTRIBUTE_get0_data(X509_ATTRIBUTE *attr, int idx,
int attrtype, void *unused);

// X509_ATTRIBUTE_count returns the number of values in |attr|.
// X509_ATTRIBUTE_count returns the number of values in |attr| or 0 if |attr|
// is NULL.
OPENSSL_EXPORT int X509_ATTRIBUTE_count(const X509_ATTRIBUTE *attr);

// X509_ATTRIBUTE_get0_object returns the type of |attr|.
Expand Down

0 comments on commit d5c7252

Please sign in to comment.