summaryrefslogtreecommitdiff
path: root/ext/openssl
diff options
context:
space:
mode:
authorKazuki Yamaguchi <[email protected]>2024-05-02 15:49:05 +0900
committergit <[email protected]>2024-05-02 07:17:35 +0000
commitf5af620c611bf62d2b29111a0347f306c1f38644 (patch)
tree2e1f3446ac7740c03d86b47bb8515acfbb66dd16 /ext/openssl
parenteb82ea62186fb9c9b2941b04ee12d0dcba112607 (diff)
[ruby/openssl] asn1: check error return from i2d_ASN1_TYPE()
i2d_ASN1_TYPE() is not expected to fail, but the return value should be checked. https://github.com/ruby/openssl/commit/21ed3c310e
Diffstat (limited to 'ext/openssl')
-rw-r--r--ext/openssl/ossl_asn1.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/ext/openssl/ossl_asn1.c b/ext/openssl/ossl_asn1.c
index 71c452c88a..0533342077 100644
--- a/ext/openssl/ossl_asn1.c
+++ b/ext/openssl/ossl_asn1.c
@@ -1163,9 +1163,12 @@ ossl_asn1prim_to_der(VALUE self)
rb_jump_tag(state);
}
p0 = p1 = (unsigned char *)RSTRING_PTR(str);
- i2d_ASN1_TYPE(asn1, &p0);
+ if (i2d_ASN1_TYPE(asn1, &p0) < 0) {
+ ASN1_TYPE_free(asn1);
+ ossl_raise(eASN1Error, "i2d_ASN1_TYPE");
+ }
ASN1_TYPE_free(asn1);
- assert(p0 - p1 == alllen);
+ ossl_str_adjust(str, p0);
/* Strip header since to_der_internal() wants only the payload */
j = ASN1_get_object((const unsigned char **)&p1, &bodylen, &tag, &tc, alllen);