Skip to content

Commit 40627b5

Browse files
committed
asn1: check error return from i2d_ASN1_TYPE()
i2d_ASN1_TYPE() is not expected to fail, but the return value should be checked.
1 parent 5a52368 commit 40627b5

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

ext/openssl/ossl_asn1.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,9 +1163,12 @@ ossl_asn1prim_to_der(VALUE self)
11631163
rb_jump_tag(state);
11641164
}
11651165
p0 = p1 = (unsigned char *)RSTRING_PTR(str);
1166-
i2d_ASN1_TYPE(asn1, &p0);
1166+
if (i2d_ASN1_TYPE(asn1, &p0) < 0) {
1167+
ASN1_TYPE_free(asn1);
1168+
ossl_raise(eASN1Error, "i2d_ASN1_TYPE");
1169+
}
11671170
ASN1_TYPE_free(asn1);
1168-
assert(p0 - p1 == alllen);
1171+
rb_str_adjust(str, p0);
11691172

11701173
/* Strip header since to_der_internal() wants only the payload */
11711174
j = ASN1_get_object((const unsigned char **)&p1, &bodylen, &tag, &tc, alllen);

0 commit comments

Comments
 (0)