Skip to content

Commit d5c7252

Browse files
authored
Coverity Fix Null Check (aws#1965)
`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.
1 parent 8f1aae9 commit d5c7252

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

crypto/x509/x509_att.c

+3
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype,
192192
}
193193

194194
int X509_ATTRIBUTE_count(const X509_ATTRIBUTE *attr) {
195+
if (attr == NULL) {
196+
return 0;
197+
}
195198
return (int)sk_ASN1_TYPE_num(attr->set);
196199
}
197200

include/openssl/x509.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -2272,7 +2272,8 @@ OPENSSL_EXPORT int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype,
22722272
OPENSSL_EXPORT void *X509_ATTRIBUTE_get0_data(X509_ATTRIBUTE *attr, int idx,
22732273
int attrtype, void *unused);
22742274

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

22782279
// X509_ATTRIBUTE_get0_object returns the type of |attr|.

0 commit comments

Comments
 (0)