[ruby/openssl] 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.

https://github.com/ruby/openssl/commit/5164725855
This commit is contained in:
Kazuki Yamaguchi 2025-01-07 02:14:50 +09:00 committed by git
parent 8888ad6902
commit 47cdf98fa4
3 changed files with 3 additions and 14 deletions

View File

@ -619,10 +619,7 @@ ossl_x509_get_extensions(VALUE self)
GetX509(self, x509); GetX509(self, x509);
count = X509_get_ext_count(x509); count = X509_get_ext_count(x509);
if (count < 0) { ary = rb_ary_new_capa(count);
return rb_ary_new();
}
ary = rb_ary_new2(count);
for (i=0; i<count; i++) { for (i=0; i<count; i++) {
ext = X509_get_ext(x509, i); /* NO DUP - don't free! */ ext = X509_get_ext(x509, i); /* NO DUP - don't free! */
rb_ary_push(ary, ossl_x509ext_new(ext)); rb_ary_push(ary, ossl_x509ext_new(ext));

View File

@ -449,11 +449,7 @@ ossl_x509crl_get_extensions(VALUE self)
GetX509CRL(self, crl); GetX509CRL(self, crl);
count = X509_CRL_get_ext_count(crl); count = X509_CRL_get_ext_count(crl);
if (count < 0) { ary = rb_ary_new_capa(count);
OSSL_Debug("count < 0???");
return rb_ary_new();
}
ary = rb_ary_new2(count);
for (i=0; i<count; i++) { for (i=0; i<count; i++) {
ext = X509_CRL_get_ext(crl, i); /* NO DUP - don't free! */ ext = X509_CRL_get_ext(crl, i); /* NO DUP - don't free! */
rb_ary_push(ary, ossl_x509ext_new(ext)); rb_ary_push(ary, ossl_x509ext_new(ext));

View File

@ -194,11 +194,7 @@ ossl_x509revoked_get_extensions(VALUE self)
GetX509Rev(self, rev); GetX509Rev(self, rev);
count = X509_REVOKED_get_ext_count(rev); count = X509_REVOKED_get_ext_count(rev);
if (count < 0) { ary = rb_ary_new_capa(count);
OSSL_Debug("count < 0???");
return rb_ary_new();
}
ary = rb_ary_new2(count);
for (i=0; i<count; i++) { for (i=0; i<count; i++) {
ext = X509_REVOKED_get_ext(rev, i); ext = X509_REVOKED_get_ext(rev, i);
rb_ary_push(ary, ossl_x509ext_new(ext)); rb_ary_push(ary, ossl_x509ext_new(ext));