diff --git a/crypto/x509/x509_test.cc b/crypto/x509/x509_test.cc index 71ffda9e23..d92d1a1ac7 100644 --- a/crypto/x509/x509_test.cc +++ b/crypto/x509/x509_test.cc @@ -7618,6 +7618,7 @@ TEST(X509Test, SPKIPrint) { const uint8_t *data; size_t data_len; ASSERT_TRUE(BIO_mem_contents(bio.get(), &data, &data_len)); + ASSERT_GT(data_len, strlen(expected_certificate_string)); std::string print(reinterpret_cast(data), strlen(expected_certificate_string)); EXPECT_EQ(print, expected_certificate_string); diff --git a/crypto/x509/x509spki.c b/crypto/x509/x509spki.c index ce8fbfb0ec..77fa8b857e 100644 --- a/crypto/x509/x509spki.c +++ b/crypto/x509/x509spki.c @@ -134,7 +134,8 @@ char *NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *spki) { } int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki) { - if (out == NULL || spki == NULL) { + if (out == NULL || spki == NULL || spki->spkac->pubkey == NULL || + spki->sig_algor == NULL || spki->signature == NULL) { OPENSSL_PUT_ERROR(X509, ERR_R_PASSED_NULL_PARAMETER); return 0; } @@ -143,10 +144,9 @@ int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki) { // Print out public key algorithm and contents. ASN1_OBJECT *spkioid; X509_PUBKEY_get0_param(&spkioid, NULL, NULL, NULL, spki->spkac->pubkey); + int spkioid_nid = OBJ_obj2nid(spkioid); BIO_printf(out, " Public Key Algorithm: %s\n", - (OBJ_obj2nid(spkioid) == NID_undef) - ? "UNKNOWN" - : OBJ_nid2ln(OBJ_obj2nid(spkioid))); + (spkioid_nid == NID_undef) ? "UNKNOWN" : OBJ_nid2ln(spkioid_nid)); EVP_PKEY *pkey = X509_PUBKEY_get0(spki->spkac->pubkey); if (pkey == NULL) { BIO_printf(out, " Unable to load public key\n"); @@ -166,7 +166,7 @@ int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki) { : OBJ_nid2ln(OBJ_obj2nid(spki->sig_algor->algorithm))); for (int i = 0; i < spki->signature->length; i++) { if ((i % 18) == 0) { - BIO_write(out, "\n ", 7); + BIO_printf(out, "\n "); } BIO_printf(out, "%02x%s", (unsigned char)spki->signature->data[i], ((i + 1) == spki->signature->length) ? "" : ":");