Skip to content

Commit 8da7220

Browse files
committed
pkey: avoid calling i2d_PUBKEY family on an incomplete key
Call ossl_pkey_check_public_key() to ensure that EVP_PKEY_missing_parameters() passes. This check should be cheap. DSA#{to_der,to_pem,export,to_s} and PKey#{public_to_der,public_to_pem} cause a segfault if the receiver is an empty DSA instance with no parameters set. Fixes <ruby#845>.
1 parent 82548a4 commit 8da7220

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

ext/openssl/ossl_pkey.c

+1
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,7 @@ ossl_pkey_export_spki(VALUE self, int to_der)
807807
BIO *bio;
808808

809809
GetPKey(self, pkey);
810+
ossl_pkey_check_public_key(pkey);
810811
bio = BIO_new(BIO_s_mem());
811812
if (!bio)
812813
ossl_raise(ePKeyError, "BIO_new");

test/openssl/test_pkey_dsa.rb

+6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ def test_new_break
2828
end
2929
end
3030

31+
def test_new_empty
32+
key = OpenSSL::PKey::DSA.new
33+
assert_nil(key.p)
34+
assert_raise(OpenSSL::PKey::PKeyError) { key.to_der }
35+
end
36+
3137
def test_generate
3238
# DSA.generate used to call DSA_generate_parameters_ex(), which adjusts the
3339
# size of q according to the size of p

0 commit comments

Comments
 (0)