diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/asn1/asn1t.h | 18 | ||||
-rw-r--r-- | src/lib/libcrypto/asn1/tasn_dec.c | 33 | ||||
-rw-r--r-- | src/lib/libcrypto/asn1/tasn_fre.c | 29 | ||||
-rw-r--r-- | src/lib/libcrypto/asn1/tasn_new.c | 35 | ||||
-rw-r--r-- | src/lib/libcrypto/asn1/tasn_utl.c | 4 |
5 files changed, 37 insertions, 82 deletions
diff --git a/src/lib/libcrypto/asn1/asn1t.h b/src/lib/libcrypto/asn1/asn1t.h index 892c8b70c3..2d38b0d006 100644 --- a/src/lib/libcrypto/asn1/asn1t.h +++ b/src/lib/libcrypto/asn1/asn1t.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: asn1t.h,v 1.19 2022/01/14 08:43:06 tb Exp $ */ | 1 | /* $OpenBSD: asn1t.h,v 1.20 2022/05/10 05:19:22 jsing Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 2000. | 3 | * project 2000. |
4 | */ | 4 | */ |
@@ -352,11 +352,6 @@ extern "C" { | |||
352 | (flags), (tag), offsetof(stname, field),\ | 352 | (flags), (tag), offsetof(stname, field),\ |
353 | #field, ASN1_ITEM_ref(type) } | 353 | #field, ASN1_ITEM_ref(type) } |
354 | 354 | ||
355 | /* used when the structure is combined with the parent */ | ||
356 | |||
357 | #define ASN1_EX_COMBINE(flags, tag, type) { \ | ||
358 | (flags)|ASN1_TFLG_COMBINE, (tag), 0, NULL, ASN1_ITEM_ref(type) } | ||
359 | |||
360 | /* implicit and explicit helper macros */ | 355 | /* implicit and explicit helper macros */ |
361 | 356 | ||
362 | #define ASN1_IMP_EX(stname, field, type, tag, ex) \ | 357 | #define ASN1_IMP_EX(stname, field, type, tag, ex) \ |
@@ -570,17 +565,6 @@ struct ASN1_ADB_TABLE_st { | |||
570 | #define ASN1_TFLG_ADB_INT (0x1<<9) | 565 | #define ASN1_TFLG_ADB_INT (0x1<<9) |
571 | 566 | ||
572 | /* | 567 | /* |
573 | * This flag means a parent structure is passed | ||
574 | * instead of the field: this is useful is a | ||
575 | * SEQUENCE is being combined with a CHOICE for | ||
576 | * example. Since this means the structure and | ||
577 | * item name will differ we need to use the | ||
578 | * ASN1_CHOICE_END_name() macro for example. | ||
579 | */ | ||
580 | |||
581 | #define ASN1_TFLG_COMBINE (0x1<<10) | ||
582 | |||
583 | /* | ||
584 | * This flag when present in a SEQUENCE OF, SET OF | 568 | * This flag when present in a SEQUENCE OF, SET OF |
585 | * or EXPLICIT causes indefinite length constructed | 569 | * or EXPLICIT causes indefinite length constructed |
586 | * encoding to be used if required. | 570 | * encoding to be used if required. |
diff --git a/src/lib/libcrypto/asn1/tasn_dec.c b/src/lib/libcrypto/asn1/tasn_dec.c index f9c5fa81b8..de0b819064 100644 --- a/src/lib/libcrypto/asn1/tasn_dec.c +++ b/src/lib/libcrypto/asn1/tasn_dec.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tasn_dec.c,v 1.61 2022/05/07 15:50:25 jsing Exp $ */ | 1 | /* $OpenBSD: tasn_dec.c,v 1.62 2022/05/10 05:19:22 jsing Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 2000. | 3 | * project 2000. |
4 | */ | 4 | */ |
@@ -132,10 +132,6 @@ asn1_item_ex_d2i_choice(ASN1_VALUE **pval, const unsigned char **in, long len, | |||
132 | const unsigned char *p = NULL; | 132 | const unsigned char *p = NULL; |
133 | int i; | 133 | int i; |
134 | int ret = 0; | 134 | int ret = 0; |
135 | int combine; | ||
136 | |||
137 | combine = aclass & ASN1_TFLG_COMBINE; | ||
138 | aclass &= ~ASN1_TFLG_COMBINE; | ||
139 | 135 | ||
140 | if (it->itype != ASN1_ITYPE_CHOICE) | 136 | if (it->itype != ASN1_ITYPE_CHOICE) |
141 | goto err; | 137 | goto err; |
@@ -211,8 +207,8 @@ asn1_item_ex_d2i_choice(ASN1_VALUE **pval, const unsigned char **in, long len, | |||
211 | auxerr: | 207 | auxerr: |
212 | ASN1error(ASN1_R_AUX_ERROR); | 208 | ASN1error(ASN1_R_AUX_ERROR); |
213 | err: | 209 | err: |
214 | if (combine == 0) | 210 | ASN1_item_ex_free(pval, it); |
215 | ASN1_item_ex_free(pval, it); | 211 | |
216 | if (errtt) | 212 | if (errtt) |
217 | ERR_asprintf_error_data("Field=%s, Type=%s", errtt->field_name, | 213 | ERR_asprintf_error_data("Field=%s, Type=%s", errtt->field_name, |
218 | it->sname); | 214 | it->sname); |
@@ -233,10 +229,6 @@ asn1_item_ex_d2i_sequence(ASN1_VALUE **pval, const unsigned char **in, long len, | |||
233 | long tmplen; | 229 | long tmplen; |
234 | int i; | 230 | int i; |
235 | int ret = 0; | 231 | int ret = 0; |
236 | int combine; | ||
237 | |||
238 | combine = aclass & ASN1_TFLG_COMBINE; | ||
239 | aclass &= ~ASN1_TFLG_COMBINE; | ||
240 | 232 | ||
241 | if (it->itype != ASN1_ITYPE_NDEF_SEQUENCE && | 233 | if (it->itype != ASN1_ITYPE_NDEF_SEQUENCE && |
242 | it->itype != ASN1_ITYPE_SEQUENCE) | 234 | it->itype != ASN1_ITYPE_SEQUENCE) |
@@ -388,8 +380,8 @@ asn1_item_ex_d2i_sequence(ASN1_VALUE **pval, const unsigned char **in, long len, | |||
388 | auxerr: | 380 | auxerr: |
389 | ASN1error(ASN1_R_AUX_ERROR); | 381 | ASN1error(ASN1_R_AUX_ERROR); |
390 | err: | 382 | err: |
391 | if (combine == 0) | 383 | ASN1_item_ex_free(pval, it); |
392 | ASN1_item_ex_free(pval, it); | 384 | |
393 | if (errtt) | 385 | if (errtt) |
394 | ERR_asprintf_error_data("Field=%s, Type=%s", errtt->field_name, | 386 | ERR_asprintf_error_data("Field=%s, Type=%s", errtt->field_name, |
395 | it->sname); | 387 | it->sname); |
@@ -412,10 +404,6 @@ asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, | |||
412 | unsigned char oclass; | 404 | unsigned char oclass; |
413 | int otag; | 405 | int otag; |
414 | int ret = 0; | 406 | int ret = 0; |
415 | int combine; | ||
416 | |||
417 | combine = aclass & ASN1_TFLG_COMBINE; | ||
418 | aclass &= ~ASN1_TFLG_COMBINE; | ||
419 | 407 | ||
420 | if (!pval) | 408 | if (!pval) |
421 | return 0; | 409 | return 0; |
@@ -491,20 +479,19 @@ asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, | |||
491 | 479 | ||
492 | case ASN1_ITYPE_CHOICE: | 480 | case ASN1_ITYPE_CHOICE: |
493 | return asn1_item_ex_d2i_choice(pval, in, len, it, tag, | 481 | return asn1_item_ex_d2i_choice(pval, in, len, it, tag, |
494 | aclass | combine, opt, depth); | 482 | aclass, opt, depth); |
495 | 483 | ||
496 | case ASN1_ITYPE_NDEF_SEQUENCE: | 484 | case ASN1_ITYPE_NDEF_SEQUENCE: |
497 | case ASN1_ITYPE_SEQUENCE: | 485 | case ASN1_ITYPE_SEQUENCE: |
498 | return asn1_item_ex_d2i_sequence(pval, in, len, it, tag, | 486 | return asn1_item_ex_d2i_sequence(pval, in, len, it, tag, |
499 | aclass | combine, opt, depth); | 487 | aclass, opt, depth); |
500 | 488 | ||
501 | default: | 489 | default: |
502 | return 0; | 490 | return 0; |
503 | } | 491 | } |
504 | 492 | ||
505 | err: | 493 | err: |
506 | if (combine == 0) | 494 | ASN1_item_ex_free(pval, it); |
507 | ASN1_item_ex_free(pval, it); | ||
508 | 495 | ||
509 | ERR_asprintf_error_data("Type=%s", it->sname); | 496 | ERR_asprintf_error_data("Type=%s", it->sname); |
510 | 497 | ||
@@ -691,8 +678,8 @@ asn1_template_noexp_d2i(ASN1_VALUE **val, const unsigned char **in, long len, | |||
691 | return -1; | 678 | return -1; |
692 | } else { | 679 | } else { |
693 | /* Nothing special */ | 680 | /* Nothing special */ |
694 | ret = asn1_item_ex_d2i(val, &p, len, tt->item, | 681 | ret = asn1_item_ex_d2i(val, &p, len, tt->item, -1, 0, |
695 | -1, tt->flags & ASN1_TFLG_COMBINE, opt, depth); | 682 | opt, depth); |
696 | if (!ret) { | 683 | if (!ret) { |
697 | ASN1error(ERR_R_NESTED_ASN1_ERROR); | 684 | ASN1error(ERR_R_NESTED_ASN1_ERROR); |
698 | goto err; | 685 | goto err; |
diff --git a/src/lib/libcrypto/asn1/tasn_fre.c b/src/lib/libcrypto/asn1/tasn_fre.c index 64d3856360..dbf6bf1e8e 100644 --- a/src/lib/libcrypto/asn1/tasn_fre.c +++ b/src/lib/libcrypto/asn1/tasn_fre.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tasn_fre.c,v 1.18 2022/01/07 12:24:17 tb Exp $ */ | 1 | /* $OpenBSD: tasn_fre.c,v 1.19 2022/05/10 05:19:22 jsing Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 2000. | 3 | * project 2000. |
4 | */ | 4 | */ |
@@ -64,25 +64,24 @@ | |||
64 | 64 | ||
65 | #include "asn1_locl.h" | 65 | #include "asn1_locl.h" |
66 | 66 | ||
67 | static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, | 67 | static void asn1_item_free(ASN1_VALUE **pval, const ASN1_ITEM *it); |
68 | int combine); | ||
69 | 68 | ||
70 | /* Free up an ASN1 structure */ | 69 | /* Free up an ASN1 structure */ |
71 | 70 | ||
72 | void | 71 | void |
73 | ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it) | 72 | ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it) |
74 | { | 73 | { |
75 | asn1_item_combine_free(&val, it, 0); | 74 | asn1_item_free(&val, it); |
76 | } | 75 | } |
77 | 76 | ||
78 | void | 77 | void |
79 | ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it) | 78 | ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it) |
80 | { | 79 | { |
81 | asn1_item_combine_free(pval, it, 0); | 80 | asn1_item_free(pval, it); |
82 | } | 81 | } |
83 | 82 | ||
84 | static void | 83 | static void |
85 | asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine) | 84 | asn1_item_free(ASN1_VALUE **pval, const ASN1_ITEM *it) |
86 | { | 85 | { |
87 | const ASN1_TEMPLATE *tt = NULL, *seqtt; | 86 | const ASN1_TEMPLATE *tt = NULL, *seqtt; |
88 | const ASN1_EXTERN_FUNCS *ef; | 87 | const ASN1_EXTERN_FUNCS *ef; |
@@ -126,10 +125,8 @@ asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine) | |||
126 | } | 125 | } |
127 | if (asn1_cb) | 126 | if (asn1_cb) |
128 | asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL); | 127 | asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL); |
129 | if (!combine) { | 128 | free(*pval); |
130 | free(*pval); | 129 | *pval = NULL; |
131 | *pval = NULL; | ||
132 | } | ||
133 | break; | 130 | break; |
134 | 131 | ||
135 | case ASN1_ITYPE_EXTERN: | 132 | case ASN1_ITYPE_EXTERN: |
@@ -164,10 +161,8 @@ asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine) | |||
164 | } | 161 | } |
165 | if (asn1_cb) | 162 | if (asn1_cb) |
166 | asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL); | 163 | asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL); |
167 | if (!combine) { | 164 | free(*pval); |
168 | free(*pval); | 165 | *pval = NULL; |
169 | *pval = NULL; | ||
170 | } | ||
171 | break; | 166 | break; |
172 | } | 167 | } |
173 | } | 168 | } |
@@ -181,14 +176,12 @@ ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) | |||
181 | for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) { | 176 | for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) { |
182 | ASN1_VALUE *vtmp; | 177 | ASN1_VALUE *vtmp; |
183 | vtmp = sk_ASN1_VALUE_value(sk, i); | 178 | vtmp = sk_ASN1_VALUE_value(sk, i); |
184 | asn1_item_combine_free(&vtmp, tt->item, | 179 | asn1_item_free(&vtmp, tt->item); |
185 | 0); | ||
186 | } | 180 | } |
187 | sk_ASN1_VALUE_free(sk); | 181 | sk_ASN1_VALUE_free(sk); |
188 | *pval = NULL; | 182 | *pval = NULL; |
189 | } else | 183 | } else |
190 | asn1_item_combine_free(pval, tt->item, | 184 | asn1_item_free(pval, tt->item); |
191 | tt->flags & ASN1_TFLG_COMBINE); | ||
192 | } | 185 | } |
193 | 186 | ||
194 | void | 187 | void |
diff --git a/src/lib/libcrypto/asn1/tasn_new.c b/src/lib/libcrypto/asn1/tasn_new.c index 1f17f177fe..83b0fce50b 100644 --- a/src/lib/libcrypto/asn1/tasn_new.c +++ b/src/lib/libcrypto/asn1/tasn_new.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tasn_new.c,v 1.21 2022/01/07 12:24:17 tb Exp $ */ | 1 | /* $OpenBSD: tasn_new.c,v 1.22 2022/05/10 05:19:22 jsing Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 2000. | 3 | * project 2000. |
4 | */ | 4 | */ |
@@ -66,8 +66,7 @@ | |||
66 | 66 | ||
67 | #include "asn1_locl.h" | 67 | #include "asn1_locl.h" |
68 | 68 | ||
69 | static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, | 69 | static int asn1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it); |
70 | int combine); | ||
71 | static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it); | 70 | static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it); |
72 | static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt); | 71 | static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt); |
73 | static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it); | 72 | static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it); |
@@ -86,11 +85,11 @@ ASN1_item_new(const ASN1_ITEM *it) | |||
86 | int | 85 | int |
87 | ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it) | 86 | ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it) |
88 | { | 87 | { |
89 | return asn1_item_ex_combine_new(pval, it, 0); | 88 | return asn1_item_ex_new(pval, it); |
90 | } | 89 | } |
91 | 90 | ||
92 | static int | 91 | static int |
93 | asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine) | 92 | asn1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it) |
94 | { | 93 | { |
95 | const ASN1_TEMPLATE *tt = NULL; | 94 | const ASN1_TEMPLATE *tt = NULL; |
96 | const ASN1_EXTERN_FUNCS *ef; | 95 | const ASN1_EXTERN_FUNCS *ef; |
@@ -102,9 +101,7 @@ asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine) | |||
102 | if (aux != NULL && aux->asn1_cb != NULL) | 101 | if (aux != NULL && aux->asn1_cb != NULL) |
103 | asn1_cb = aux->asn1_cb; | 102 | asn1_cb = aux->asn1_cb; |
104 | 103 | ||
105 | if (!combine) | 104 | *pval = NULL; |
106 | *pval = NULL; | ||
107 | |||
108 | 105 | ||
109 | switch (it->itype) { | 106 | switch (it->itype) { |
110 | case ASN1_ITYPE_EXTERN: | 107 | case ASN1_ITYPE_EXTERN: |
@@ -137,11 +134,9 @@ asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine) | |||
137 | return 1; | 134 | return 1; |
138 | } | 135 | } |
139 | } | 136 | } |
140 | if (!combine) { | 137 | *pval = calloc(1, it->size); |
141 | *pval = calloc(1, it->size); | 138 | if (!*pval) |
142 | if (!*pval) | 139 | goto memerr; |
143 | goto memerr; | ||
144 | } | ||
145 | asn1_set_choice_selector(pval, -1, it); | 140 | asn1_set_choice_selector(pval, -1, it); |
146 | if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL)) | 141 | if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL)) |
147 | goto auxerr; | 142 | goto auxerr; |
@@ -157,13 +152,11 @@ asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine) | |||
157 | return 1; | 152 | return 1; |
158 | } | 153 | } |
159 | } | 154 | } |
160 | if (!combine) { | 155 | *pval = calloc(1, it->size); |
161 | *pval = calloc(1, it->size); | 156 | if (!*pval) |
162 | if (!*pval) | 157 | goto memerr; |
163 | goto memerr; | 158 | asn1_do_lock(pval, 0, it); |
164 | asn1_do_lock(pval, 0, it); | 159 | asn1_enc_init(pval, it); |
165 | asn1_enc_init(pval, it); | ||
166 | } | ||
167 | for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) { | 160 | for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) { |
168 | pseqval = asn1_get_field_ptr(pval, tt); | 161 | pseqval = asn1_get_field_ptr(pval, tt); |
169 | if (!ASN1_template_new(pseqval, tt)) | 162 | if (!ASN1_template_new(pseqval, tt)) |
@@ -249,7 +242,7 @@ ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) | |||
249 | goto done; | 242 | goto done; |
250 | } | 243 | } |
251 | /* Otherwise pass it back to the item routine */ | 244 | /* Otherwise pass it back to the item routine */ |
252 | ret = asn1_item_ex_combine_new(pval, it, tt->flags & ASN1_TFLG_COMBINE); | 245 | ret = asn1_item_ex_new(pval, it); |
253 | done: | 246 | done: |
254 | return ret; | 247 | return ret; |
255 | } | 248 | } |
diff --git a/src/lib/libcrypto/asn1/tasn_utl.c b/src/lib/libcrypto/asn1/tasn_utl.c index e64bbe1f1a..4ef4232c7e 100644 --- a/src/lib/libcrypto/asn1/tasn_utl.c +++ b/src/lib/libcrypto/asn1/tasn_utl.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tasn_utl.c,v 1.13 2021/12/25 13:17:48 jsing Exp $ */ | 1 | /* $OpenBSD: tasn_utl.c,v 1.14 2022/05/10 05:19:23 jsing Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 2000. | 3 | * project 2000. |
4 | */ | 4 | */ |
@@ -205,8 +205,6 @@ asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) | |||
205 | { | 205 | { |
206 | ASN1_VALUE **pvaltmp; | 206 | ASN1_VALUE **pvaltmp; |
207 | 207 | ||
208 | if (tt->flags & ASN1_TFLG_COMBINE) | ||
209 | return pval; | ||
210 | pvaltmp = offset2ptr(*pval, tt->offset); | 208 | pvaltmp = offset2ptr(*pval, tt->offset); |
211 | /* NOTE for BOOLEAN types the field is just a plain | 209 | /* NOTE for BOOLEAN types the field is just a plain |
212 | * int so we can't return int **, so settle for | 210 | * int so we can't return int **, so settle for |