From cbe7bfd9a81273c04a40f1ff19f516f8db31ac53 Mon Sep 17 00:00:00 2001 From: Kazuki Yamaguchi Date: Wed, 30 Oct 2024 03:59:03 +0900 Subject: [ruby/openssl] ts: fix exception class raised when getting an OID name get_asn1obj() is used by several methods in OpenSSL::Timestamp to get the string representation of an OID. On an error, such as memory allocation failure, it can raise OpenSSL::X509::AttributeError. It should be OpenSSL::Timestamp::TimestampError instead. https://github.com/ruby/openssl/commit/a424aad1df --- ext/openssl/ossl_ts.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'ext/openssl') diff --git a/ext/openssl/ossl_ts.c b/ext/openssl/ossl_ts.c index dadbc38f98..bcd1777a78 100644 --- a/ext/openssl/ossl_ts.c +++ b/ext/openssl/ossl_ts.c @@ -161,8 +161,11 @@ get_asn1obj(ASN1_OBJECT *obj) ret = rb_str_new2(OBJ_nid2sn(nid)); else{ if (!(out = BIO_new(BIO_s_mem()))) - ossl_raise(eX509AttrError, NULL); - i2a_ASN1_OBJECT(out, obj); + ossl_raise(eTimestampError, "BIO_new(BIO_s_mem())"); + if (i2a_ASN1_OBJECT(out, obj) <= 0) { + BIO_free(out); + ossl_raise(eTimestampError, "i2a_ASN1_OBJECT"); + } ret = ossl_membio2str(out); } -- cgit v1.2.3