summaryrefslogtreecommitdiff
path: root/lib/libcrypto/asn1
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2022-05-21 13:16:20 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2022-05-21 13:16:20 +0000
commit597b88ebe643a38c2deea369f10bbc6b0962f1a1 (patch)
treef1a8cfcf28e03e3dab6d9d7b6a888e0d060f9640 /lib/libcrypto/asn1
parentdc60a0012805b3e839303d1bace09eaead5994f1 (diff)
Factor out ASN1_ITYPE_EXTERN handling.
Factor out the ef->asn1_ex_d2i() callback handling - this allows us to pull out all of the related variables into a self-contained function. ok tb@
Diffstat (limited to 'lib/libcrypto/asn1')
-rw-r--r--lib/libcrypto/asn1/tasn_dec.c47
1 files changed, 32 insertions, 15 deletions
diff --git a/lib/libcrypto/asn1/tasn_dec.c b/lib/libcrypto/asn1/tasn_dec.c
index a769ace9758..03a4d6313b9 100644
--- a/lib/libcrypto/asn1/tasn_dec.c
+++ b/lib/libcrypto/asn1/tasn_dec.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tasn_dec.c,v 1.74 2022/05/21 11:21:31 jsing Exp $ */
+/* $OpenBSD: tasn_dec.c,v 1.75 2022/05/21 13:16:19 jsing Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2000.
*/
@@ -903,6 +903,35 @@ asn1_item_d2i_sequence(ASN1_VALUE **pval, CBS *cbs, const ASN1_ITEM *it,
return 0;
}
+static int
+asn1_item_d2i_extern(ASN1_VALUE **pval, CBS *cbs, const ASN1_ITEM *it,
+ int tag_number, int tag_class, char optional)
+{
+ const ASN1_EXTERN_FUNCS *ef = it->funcs;
+ const unsigned char *p = NULL;
+ ASN1_TLC ctx = { 0 };
+ int ret = 0;
+
+ if (CBS_len(cbs) > LONG_MAX)
+ return 0;
+
+ p = CBS_data(cbs);
+
+ if ((ret = ef->asn1_ex_d2i(pval, &p, (long)CBS_len(cbs), it,
+ tag_number, tag_class, optional, &ctx)) == 1) {
+ if (!CBS_skip(cbs, p - CBS_data(cbs)))
+ goto err;
+ }
+ return ret;
+
+ err:
+ ASN1_item_ex_free(pval, it);
+
+ ERR_asprintf_error_data("Type=%s", it->sname);
+
+ return 0;
+}
+
/*
* Decode an item, taking care of IMPLICIT tagging, if any.
* If 'opt' set and tag mismatch return -1 to handle OPTIONAL
@@ -911,11 +940,6 @@ static int
asn1_item_d2i(ASN1_VALUE **pval, CBS *cbs, const ASN1_ITEM *it,
int tag_number, int tag_class, char optional, int depth)
{
- const ASN1_EXTERN_FUNCS *ef = it->funcs;
- const unsigned char *p = NULL;
- ASN1_TLC ctx = { 0 };
- int ret = 0;
-
if (pval == NULL)
return 0;
@@ -949,15 +973,8 @@ asn1_item_d2i(ASN1_VALUE **pval, CBS *cbs, const ASN1_ITEM *it,
optional);
case ASN1_ITYPE_EXTERN:
- if (CBS_len(cbs) > LONG_MAX)
- return 0;
- p = CBS_data(cbs);
- if ((ret = ef->asn1_ex_d2i(pval, &p, (long)CBS_len(cbs), it,
- tag_number, tag_class, optional, &ctx)) == 1) {
- if (!CBS_skip(cbs, p - CBS_data(cbs)))
- goto err;
- }
- return ret;
+ return asn1_item_d2i_extern(pval, cbs, it, tag_number,
+ tag_class, optional);
case ASN1_ITYPE_CHOICE:
return asn1_item_d2i_choice(pval, cbs, it, tag_number,