Skip to content

Commit 1c72f70

Browse files
FdaSilvaYYRich Salz
authored andcommitted
Use more X509_REQ_get0_pubkey & X509_get0_pubkey
Reviewed-by: Matt Caswell <[email protected]> Reviewed-by: Rich Salz <[email protected]> (Merged from openssl#1284)
1 parent 415e7c4 commit 1c72f70

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

apps/req.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -727,15 +727,14 @@ int req_main(int argc, char **argv)
727727
goto end;
728728

729729
if (pubkey) {
730-
EVP_PKEY *tpubkey;
731-
tpubkey = X509_REQ_get_pubkey(req);
730+
EVP_PKEY *tpubkey = X509_REQ_get0_pubkey(req);
731+
732732
if (tpubkey == NULL) {
733733
BIO_printf(bio_err, "Error getting public key\n");
734734
ERR_print_errors(bio_err);
735735
goto end;
736736
}
737737
PEM_write_bio_PUBKEY(out, tpubkey);
738-
EVP_PKEY_free(tpubkey);
739738
}
740739

741740
if (text) {
@@ -758,9 +757,9 @@ int req_main(int argc, char **argv)
758757
EVP_PKEY *tpubkey;
759758

760759
if (x509)
761-
tpubkey = X509_get_pubkey(x509ss);
760+
tpubkey = X509_get0_pubkey(x509ss);
762761
else
763-
tpubkey = X509_REQ_get_pubkey(req);
762+
tpubkey = X509_REQ_get0_pubkey(req);
764763
if (tpubkey == NULL) {
765764
fprintf(stdout, "Modulus=unavailable\n");
766765
goto end;
@@ -774,7 +773,6 @@ int req_main(int argc, char **argv)
774773
} else
775774
#endif
776775
fprintf(stdout, "Wrong Algorithm type");
777-
EVP_PKEY_free(tpubkey);
778776
fprintf(stdout, "\n");
779777
}
780778

crypto/x509/t_req.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,12 @@ int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags,
8686
if (BIO_puts(bp, "\n") <= 0)
8787
goto err;
8888

89-
pkey = X509_REQ_get_pubkey(x);
89+
pkey = X509_REQ_get0_pubkey(x);
9090
if (pkey == NULL) {
9191
BIO_printf(bp, "%12sUnable to load Public Key\n", "");
9292
ERR_print_errors(bp);
9393
} else {
9494
EVP_PKEY_print_public(bp, pkey, 16, NULL);
95-
EVP_PKEY_free(pkey);
9695
}
9796
}
9897

test/ssltest_old.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -852,11 +852,11 @@ static void print_details(SSL *c_ssl, const char *prefix)
852852
SSL_CIPHER_get_version(ciph), SSL_CIPHER_get_name(ciph));
853853
cert = SSL_get_peer_certificate(c_ssl);
854854
if (cert != NULL) {
855-
pkey = X509_get_pubkey(cert);
856-
if (pkey != NULL) {
855+
EVP_PKEY* pubkey = X509_get0_pubkey(cert);
856+
857+
if (pubkey != NULL) {
857858
BIO_puts(bio_stdout, ", ");
858-
print_key_details(bio_stdout, pkey);
859-
EVP_PKEY_free(pkey);
859+
print_key_details(bio_stdout, pubkey);
860860
}
861861
X509_free(cert);
862862
}

0 commit comments

Comments
 (0)