Skip to content

Commit 5164725

Browse files
committed
x509: do not check for negative return from X509_*_get_ext_count()
These functions wrap X509v3_get_ext_count(). The implementation can never return a negative number, and this behavior is documented in the man page.
1 parent 84cffd4 commit 5164725

File tree

3 files changed

+3
-14
lines changed

3 files changed

+3
-14
lines changed

ext/openssl/ossl_x509cert.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -619,10 +619,7 @@ ossl_x509_get_extensions(VALUE self)
619619

620620
GetX509(self, x509);
621621
count = X509_get_ext_count(x509);
622-
if (count < 0) {
623-
return rb_ary_new();
624-
}
625-
ary = rb_ary_new2(count);
622+
ary = rb_ary_new_capa(count);
626623
for (i=0; i<count; i++) {
627624
ext = X509_get_ext(x509, i); /* NO DUP - don't free! */
628625
rb_ary_push(ary, ossl_x509ext_new(ext));

ext/openssl/ossl_x509crl.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -449,11 +449,7 @@ ossl_x509crl_get_extensions(VALUE self)
449449

450450
GetX509CRL(self, crl);
451451
count = X509_CRL_get_ext_count(crl);
452-
if (count < 0) {
453-
OSSL_Debug("count < 0???");
454-
return rb_ary_new();
455-
}
456-
ary = rb_ary_new2(count);
452+
ary = rb_ary_new_capa(count);
457453
for (i=0; i<count; i++) {
458454
ext = X509_CRL_get_ext(crl, i); /* NO DUP - don't free! */
459455
rb_ary_push(ary, ossl_x509ext_new(ext));

ext/openssl/ossl_x509revoked.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,7 @@ ossl_x509revoked_get_extensions(VALUE self)
194194

195195
GetX509Rev(self, rev);
196196
count = X509_REVOKED_get_ext_count(rev);
197-
if (count < 0) {
198-
OSSL_Debug("count < 0???");
199-
return rb_ary_new();
200-
}
201-
ary = rb_ary_new2(count);
197+
ary = rb_ary_new_capa(count);
202198
for (i=0; i<count; i++) {
203199
ext = X509_REVOKED_get_ext(rev, i);
204200
rb_ary_push(ary, ossl_x509ext_new(ext));

0 commit comments

Comments
 (0)