Skip to content

Commit ef27708

Browse files
committed
x509: disallow ossl_x509{,attr,crl,ext,revoked,name}*_new(NULL)
These functions are not actually called with NULL. It also doesn't make sense to do so, so let's simplify the definitions.
1 parent 6fa793d commit ef27708

File tree

6 files changed

+18
-42
lines changed

6 files changed

+18
-42
lines changed

ext/openssl/ossl_x509attr.c

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

5656
obj = NewX509Attr(cX509Attr);
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-
}
57+
new = X509_ATTRIBUTE_dup(attr);
58+
if (!new)
59+
ossl_raise(eX509AttrError, "X509_ATTRIBUTE_dup");
6560
SetX509Attr(obj, new);
6661

6762
return obj;

ext/openssl/ossl_x509cert.c

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

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

6762
return obj;

ext/openssl/ossl_x509crl.c

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

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

7172
return obj;

ext/openssl/ossl_x509ext.c

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

7070
obj = NewX509Ext(cX509Ext);
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-
}
71+
new = X509_EXTENSION_dup(ext);
72+
if (!new)
73+
ossl_raise(eX509ExtError, "X509_EXTENSION_dup");
7974
SetX509Ext(obj, new);
8075

8176
return obj;

ext/openssl/ossl_x509name.c

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

6161
obj = NewX509Name(cX509Name);
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-
}
62+
new = X509_NAME_dup(name);
63+
if (!new)
64+
ossl_raise(eX509NameError, "X509_NAME_dup");
7065
SetX509Name(obj, new);
7166

7267
return obj;

ext/openssl/ossl_x509revoked.c

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

5656
obj = NewX509Rev(cX509Rev);
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-
}
57+
new = X509_REVOKED_dup(rev);
58+
if (!new)
59+
ossl_raise(eX509RevError, "X509_REVOKED_dup");
6560
SetX509Rev(obj, new);
6661

6762
return obj;

0 commit comments

Comments
 (0)