Skip to content

Commit ec01cd9

Browse files
committed
Revert "[ruby/openssl] x509: disallow ossl_x509{,attr,crl,ext,revoked,name}*_new(NULL)"
This reverts commit 4e8bbb0. It broke RubyGems tests: https://rubyci.s3.amazonaws.com/debian/ruby-master/log/20250727T123003Z.fail.html.gz OpenSSL::X509::StoreContext#current_cert incorrectly calls ossl_x509_new() with NULL to create a bogus Certificate object, and a test case in RubyGems relies on it. This will be reapplied when both are fixed.
1 parent 9eda3cf commit ec01cd9

File tree

6 files changed

+42
-18
lines changed

6 files changed

+42
-18
lines changed

ext/openssl/ossl_x509attr.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,14 @@ ossl_x509attr_new(X509_ATTRIBUTE *attr)
5454
VALUE obj;
5555

5656
obj = NewX509Attr(cX509Attr);
57-
new = X509_ATTRIBUTE_dup(attr);
58-
if (!new)
59-
ossl_raise(eX509AttrError, "X509_ATTRIBUTE_dup");
57+
if (!attr) {
58+
new = X509_ATTRIBUTE_new();
59+
} else {
60+
new = X509_ATTRIBUTE_dup(attr);
61+
}
62+
if (!new) {
63+
ossl_raise(eX509AttrError, NULL);
64+
}
6065
SetX509Attr(obj, new);
6166

6267
return obj;

ext/openssl/ossl_x509cert.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,14 @@ ossl_x509_new(X509 *x509)
5454
VALUE obj;
5555

5656
obj = NewX509(cX509Cert);
57-
new = X509_dup(x509);
58-
if (!new)
59-
ossl_raise(eX509CertError, "X509_dup");
57+
if (!x509) {
58+
new = X509_new();
59+
} else {
60+
new = X509_dup(x509);
61+
}
62+
if (!new) {
63+
ossl_raise(eX509CertError, NULL);
64+
}
6065
SetX509(obj, new);
6166

6267
return obj;

ext/openssl/ossl_x509crl.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,8 @@ ossl_x509crl_new(X509_CRL *crl)
6464
VALUE obj;
6565

6666
obj = NewX509CRL(cX509CRL);
67-
tmp = X509_CRL_dup(crl);
68-
if (!tmp)
69-
ossl_raise(eX509CRLError, "X509_CRL_dup");
67+
tmp = crl ? X509_CRL_dup(crl) : X509_CRL_new();
68+
if(!tmp) ossl_raise(eX509CRLError, NULL);
7069
SetX509CRL(obj, tmp);
7170

7271
return obj;

ext/openssl/ossl_x509ext.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,14 @@ ossl_x509ext_new(X509_EXTENSION *ext)
6868
VALUE obj;
6969

7070
obj = NewX509Ext(cX509Ext);
71-
new = X509_EXTENSION_dup(ext);
72-
if (!new)
73-
ossl_raise(eX509ExtError, "X509_EXTENSION_dup");
71+
if (!ext) {
72+
new = X509_EXTENSION_new();
73+
} else {
74+
new = X509_EXTENSION_dup(ext);
75+
}
76+
if (!new) {
77+
ossl_raise(eX509ExtError, NULL);
78+
}
7479
SetX509Ext(obj, new);
7580

7681
return obj;

ext/openssl/ossl_x509name.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,14 @@ ossl_x509name_new(X509_NAME *name)
5959
VALUE obj;
6060

6161
obj = NewX509Name(cX509Name);
62-
new = X509_NAME_dup(name);
63-
if (!new)
64-
ossl_raise(eX509NameError, "X509_NAME_dup");
62+
if (!name) {
63+
new = X509_NAME_new();
64+
} else {
65+
new = X509_NAME_dup(name);
66+
}
67+
if (!new) {
68+
ossl_raise(eX509NameError, NULL);
69+
}
6570
SetX509Name(obj, new);
6671

6772
return obj;

ext/openssl/ossl_x509revoked.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,14 @@ ossl_x509revoked_new(X509_REVOKED *rev)
5454
VALUE obj;
5555

5656
obj = NewX509Rev(cX509Rev);
57-
new = X509_REVOKED_dup(rev);
58-
if (!new)
59-
ossl_raise(eX509RevError, "X509_REVOKED_dup");
57+
if (!rev) {
58+
new = X509_REVOKED_new();
59+
} else {
60+
new = X509_REVOKED_dup(rev);
61+
}
62+
if (!new) {
63+
ossl_raise(eX509RevError, NULL);
64+
}
6065
SetX509Rev(obj, new);
6166

6267
return obj;

0 commit comments

Comments
 (0)