Avoid NULL pointer dereference. Fixes #9043.
[openssl.git] / crypto / x509 / t_req.c
index 28157de7e322b9cce287897b4dafb4bf2565768f..8af6510bf56b912556ab658a8d5a030a9a9e9f20 100644 (file)
@@ -127,6 +127,10 @@ int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags,
                 if ((j = i2a_ASN1_OBJECT(bp, aobj)) > 0) {
                     ii = 0;
                     count = X509_ATTRIBUTE_count(a);
+                    if (count == 0) {
+                      X509err(X509_F_X509_REQ_PRINT_EX, X509_R_INVALID_ATTRIBUTES);
+                      return 0;
+                    }
  get_next:
                     at = X509_ATTRIBUTE_get0_type(a, ii);
                     type = at->type;