Skip to content

Commit 317bd5c

Browse files
authored
Merge pull request #537 from rhenium/ky/x509-delete-attr-cleanup
x509*: fix error queue leak in #extensions= and #attributes= methods
2 parents ab4d58e + a0c8784 commit 317bd5c

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

ext/openssl/ossl_x509cert.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -642,12 +642,12 @@ ossl_x509_set_extensions(VALUE self, VALUE ary)
642642
OSSL_Check_Kind(RARRAY_AREF(ary, i), cX509Ext);
643643
}
644644
GetX509(self, x509);
645-
while ((ext = X509_delete_ext(x509, 0)))
646-
X509_EXTENSION_free(ext);
645+
for (i = X509_get_ext_count(x509); i > 0; i--)
646+
X509_EXTENSION_free(X509_delete_ext(x509, 0));
647647
for (i=0; i<RARRAY_LEN(ary); i++) {
648648
ext = GetX509ExtPtr(RARRAY_AREF(ary, i));
649649
if (!X509_add_ext(x509, ext, -1)) { /* DUPs ext */
650-
ossl_raise(eX509CertError, NULL);
650+
ossl_raise(eX509CertError, "X509_add_ext");
651651
}
652652
}
653653

ext/openssl/ossl_x509crl.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,12 +474,12 @@ ossl_x509crl_set_extensions(VALUE self, VALUE ary)
474474
OSSL_Check_Kind(RARRAY_AREF(ary, i), cX509Ext);
475475
}
476476
GetX509CRL(self, crl);
477-
while ((ext = X509_CRL_delete_ext(crl, 0)))
478-
X509_EXTENSION_free(ext);
477+
for (i = X509_CRL_get_ext_count(crl); i > 0; i--)
478+
X509_EXTENSION_free(X509_CRL_delete_ext(crl, 0));
479479
for (i=0; i<RARRAY_LEN(ary); i++) {
480480
ext = GetX509ExtPtr(RARRAY_AREF(ary, i)); /* NO NEED TO DUP */
481481
if (!X509_CRL_add_ext(crl, ext, -1)) {
482-
ossl_raise(eX509CRLError, NULL);
482+
ossl_raise(eX509CRLError, "X509_CRL_add_ext");
483483
}
484484
}
485485

ext/openssl/ossl_x509req.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,13 +380,13 @@ ossl_x509req_set_attributes(VALUE self, VALUE ary)
380380
OSSL_Check_Kind(RARRAY_AREF(ary, i), cX509Attr);
381381
}
382382
GetX509Req(self, req);
383-
while ((attr = X509_REQ_delete_attr(req, 0)))
384-
X509_ATTRIBUTE_free(attr);
383+
for (i = X509_REQ_get_attr_count(req); i > 0; i--)
384+
X509_ATTRIBUTE_free(X509_REQ_delete_attr(req, 0));
385385
for (i=0;i<RARRAY_LEN(ary); i++) {
386386
item = RARRAY_AREF(ary, i);
387387
attr = GetX509AttrPtr(item);
388388
if (!X509_REQ_add1_attr(req, attr)) {
389-
ossl_raise(eX509ReqError, NULL);
389+
ossl_raise(eX509ReqError, "X509_REQ_add1_attr");
390390
}
391391
}
392392
return ary;

ext/openssl/ossl_x509revoked.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,13 @@ ossl_x509revoked_set_extensions(VALUE self, VALUE ary)
223223
OSSL_Check_Kind(RARRAY_AREF(ary, i), cX509Ext);
224224
}
225225
GetX509Rev(self, rev);
226-
while ((ext = X509_REVOKED_delete_ext(rev, 0)))
227-
X509_EXTENSION_free(ext);
226+
for (i = X509_REVOKED_get_ext_count(rev); i > 0; i--)
227+
X509_EXTENSION_free(X509_REVOKED_delete_ext(rev, 0));
228228
for (i=0; i<RARRAY_LEN(ary); i++) {
229229
item = RARRAY_AREF(ary, i);
230230
ext = GetX509ExtPtr(item);
231231
if(!X509_REVOKED_add_ext(rev, ext, -1)) {
232-
ossl_raise(eX509RevError, NULL);
232+
ossl_raise(eX509RevError, "X509_REVOKED_add_ext");
233233
}
234234
}
235235

0 commit comments

Comments
 (0)