diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2024-05-02 15:49:05 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2024-05-02 15:52:02 +0900 |
commit | 21ed3c310ee67f1d445f399718758b24e1c396ae (patch) | |
tree | 9e63a1c01285ad8288ad13c1ee9c67ff54c989ad | |
parent | 5a5236838b712553dbdca0c68e253107e768d5ed (diff) | |
download | ruby-openssl-21ed3c310ee67f1d445f399718758b24e1c396ae.tar.gz |
asn1: check error return from i2d_ASN1_TYPE()ky/asn1-check-i2d-error
i2d_ASN1_TYPE() is not expected to fail, but the return value should be
checked.
-rw-r--r-- | ext/openssl/ossl_asn1.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/ext/openssl/ossl_asn1.c b/ext/openssl/ossl_asn1.c index 71c452c8..05333420 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); |