From ac48b6c8af106ad48e87e45eab8ca61121cc084e Mon Sep 17 00:00:00 2001 From: ndossche <7771979+ndossche@users.noreply.github.com> Date: Mon, 20 Apr 2026 21:41:45 +0200 Subject: [PATCH] asn1: add error checks for ASN1_STRING_set() calls Other calls in the project have such checks, add it consistently everywhere to raise an exception in case of an error. --- ext/openssl/ossl_asn1.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ext/openssl/ossl_asn1.c b/ext/openssl/ossl_asn1.c index 67c03b7f9..a3e4afe7c 100644 --- a/ext/openssl/ossl_asn1.c +++ b/ext/openssl/ossl_asn1.c @@ -253,7 +253,10 @@ obj_to_asn1str(VALUE obj) StringValue(obj); if(!(str = ASN1_STRING_new())) ossl_raise(eASN1Error, NULL); - ASN1_STRING_set(str, RSTRING_PTR(obj), RSTRING_LENINT(obj)); + if(!ASN1_STRING_set(str, RSTRING_PTR(obj), RSTRING_LENINT(obj))) { + ASN1_STRING_free(str); + ossl_raise(eASN1Error, NULL); + } return str; } @@ -323,7 +326,10 @@ obj_to_asn1derstr(VALUE obj) str = ossl_to_der(obj); if(!(a1str = ASN1_STRING_new())) ossl_raise(eASN1Error, NULL); - ASN1_STRING_set(a1str, RSTRING_PTR(str), RSTRING_LENINT(str)); + if(!ASN1_STRING_set(a1str, RSTRING_PTR(str), RSTRING_LENINT(str))) { + ASN1_STRING_free(a1str); + ossl_raise(eASN1Error, NULL); + } return a1str; }