From 4329f361ce75973ceca9d440e8430580ee515070 Mon Sep 17 00:00:00 2001 From: "Dr. David von Oheimb" Date: Fri, 7 May 2021 17:16:48 +0200 Subject: Add ASN1_item_i2d_mem_bio(); document and improve also ASN1_item_d2i_bio() ASN1_item_d2i_bio(): Do not report errors in queue on BIO input being NULL Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/15147) --- crypto/asn1/a_d2i_fp.c | 2 ++ crypto/asn1/a_i2d_fp.c | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) (limited to 'crypto') diff --git a/crypto/asn1/a_d2i_fp.c b/crypto/asn1/a_d2i_fp.c index b6faa0f2ae..2c7acb34e0 100644 --- a/crypto/asn1/a_d2i_fp.c +++ b/crypto/asn1/a_d2i_fp.c @@ -62,6 +62,8 @@ void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x) void *ret = NULL; int len; + if (in == NULL) + return NULL; len = asn1_d2i_read_bio(in, &b); if (len < 0) goto err; diff --git a/crypto/asn1/a_i2d_fp.c b/crypto/asn1/a_i2d_fp.c index efc839e615..482ee627b1 100644 --- a/crypto/asn1/a_i2d_fp.c +++ b/crypto/asn1/a_i2d_fp.c @@ -109,3 +109,21 @@ int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, const void *x) OPENSSL_free(b); return ret; } + +BIO *ASN1_item_i2d_mem_bio(const ASN1_ITEM *it, const ASN1_VALUE *val) +{ + BIO *res; + + if (it == NULL || val == NULL) { + ERR_raise(ERR_LIB_ASN1, ERR_R_PASSED_NULL_PARAMETER); + return NULL; + } + + if ((res = BIO_new(BIO_s_mem())) == NULL) + return NULL; + if (ASN1_item_i2d_bio(it, res, val) <= 0) { + BIO_free(res); + res = NULL; + } + return res; +} -- cgit v1.2.3