summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2021-12-03 17:27:34 +0000
committerjsing <>2021-12-03 17:27:34 +0000
commit70e457ecdac2e754c7695e07db8ede5dbd075676 (patch)
treeed18c8d27a378c803bc65f35849a95a3651aca48
parent4f7d2d50bd695e29a0268642de614b97bc3538ce (diff)
downloadopenbsd-70e457ecdac2e754c7695e07db8ede5dbd075676.tar.gz
openbsd-70e457ecdac2e754c7695e07db8ede5dbd075676.tar.bz2
openbsd-70e457ecdac2e754c7695e07db8ede5dbd075676.zip
Replace asn1_tlc_clear and asn1_tlc_clear_nc macros with a function.
Call the replacement asn1_tlc_invalidate() since it does not actually clear the ASN1_TLC. While here, name the ASN1_TLC variables consistently as ctx, remove a pointless comment and simplify ASN1_item_d2i() slightly. ok inoguchi@ tb@
-rw-r--r--src/lib/libcrypto/asn1/tasn_dec.c58
1 files changed, 26 insertions, 32 deletions
diff --git a/src/lib/libcrypto/asn1/tasn_dec.c b/src/lib/libcrypto/asn1/tasn_dec.c
index ab3ff8c3bc..331b147936 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.40 2021/12/03 17:23:16 jsing Exp $ */ 1/* $OpenBSD: tasn_dec.c,v 1.41 2021/12/03 17:27:34 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 */
@@ -115,45 +115,40 @@ ASN1_tag2bit(int tag)
115 return tag2bit[tag]; 115 return tag2bit[tag];
116} 116}
117 117
118/* Macro to initialize and invalidate the cache */ 118static void
119 119asn1_tlc_invalidate(ASN1_TLC *ctx)
120#define asn1_tlc_clear(c) if (c) (c)->valid = 0 120{
121/* Version to avoid compiler warning about 'c' always non-NULL */ 121 if (ctx != NULL)
122#define asn1_tlc_clear_nc(c) (c)->valid = 0 122 ctx->valid = 0;
123 123}
124/* Decode an ASN1 item, this currently behaves just
125 * like a standard 'd2i' function. 'in' points to
126 * a buffer to read the data from, in future we will
127 * have more advanced versions that can input data
128 * a piece at a time and this will simply be a special
129 * case.
130 */
131 124
132ASN1_VALUE * 125ASN1_VALUE *
133ASN1_item_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, 126ASN1_item_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
134 const ASN1_ITEM *it) 127 const ASN1_ITEM *it)
135{ 128{
136 ASN1_TLC c;
137 ASN1_VALUE *ptmpval = NULL; 129 ASN1_VALUE *ptmpval = NULL;
130 ASN1_TLC ctx;
138 131
139 if (!pval) 132 asn1_tlc_invalidate(&ctx);
133
134 if (pval == NULL)
140 pval = &ptmpval; 135 pval = &ptmpval;
141 asn1_tlc_clear_nc(&c); 136 if (asn1_item_ex_d2i(pval, in, len, it, -1, 0, 0, &ctx, 0) <= 0)
142 if (asn1_item_ex_d2i(pval, in, len, it, -1, 0, 0, &c, 0) > 0) 137 return NULL;
143 return *pval; 138
144 return NULL; 139 return *pval;
145} 140}
146 141
147int 142int
148ASN1_template_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, 143ASN1_template_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
149 const ASN1_TEMPLATE *tt) 144 const ASN1_TEMPLATE *tt)
150{ 145{
151 ASN1_TLC c; 146 ASN1_TLC ctx;
152 147
153 asn1_tlc_clear_nc(&c); 148 asn1_tlc_invalidate(&ctx);
154 return asn1_template_ex_d2i(pval, in, len, tt, 0, &c, 0);
155}
156 149
150 return asn1_template_ex_d2i(pval, in, len, tt, 0, &ctx, 0);
151}
157 152
158/* Decode an item, taking care of IMPLICIT tagging, if any. 153/* Decode an item, taking care of IMPLICIT tagging, if any.
159 * If 'opt' set and tag mismatch return -1 to handle OPTIONAL 154 * If 'opt' set and tag mismatch return -1 to handle OPTIONAL
@@ -749,10 +744,9 @@ asn1_d2i_ex_primitive(ASN1_VALUE **pval, const unsigned char **in, long inlen,
749 * when we have a exact match wont work 744 * when we have a exact match wont work
750 */ 745 */
751 if (utype == V_ASN1_OTHER) { 746 if (utype == V_ASN1_OTHER) {
752 asn1_tlc_clear(ctx); 747 asn1_tlc_invalidate(ctx);
753 } 748 } else if (!cst) {
754 /* SEQUENCE and SET must be constructed */ 749 /* SEQUENCE and SET must be constructed */
755 else if (!cst) {
756 ASN1error(ASN1_R_TYPE_NOT_CONSTRUCTED); 750 ASN1error(ASN1_R_TYPE_NOT_CONSTRUCTED);
757 return 0; 751 return 0;
758 } 752 }
@@ -1148,7 +1142,7 @@ asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, char *inf,
1148 */ 1142 */
1149 if (!(i & 0x81) && ((plen + ctx->hdrlen) > len)) { 1143 if (!(i & 0x81) && ((plen + ctx->hdrlen) > len)) {
1150 ASN1error(ASN1_R_TOO_LONG); 1144 ASN1error(ASN1_R_TOO_LONG);
1151 asn1_tlc_clear(ctx); 1145 asn1_tlc_invalidate(ctx);
1152 return 0; 1146 return 0;
1153 } 1147 }
1154 } 1148 }
@@ -1156,7 +1150,7 @@ asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, char *inf,
1156 1150
1157 if (i & 0x80) { 1151 if (i & 0x80) {
1158 ASN1error(ASN1_R_BAD_OBJECT_HEADER); 1152 ASN1error(ASN1_R_BAD_OBJECT_HEADER);
1159 asn1_tlc_clear(ctx); 1153 asn1_tlc_invalidate(ctx);
1160 return 0; 1154 return 0;
1161 } 1155 }
1162 if (exptag >= 0) { 1156 if (exptag >= 0) {
@@ -1166,13 +1160,13 @@ asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, char *inf,
1166 */ 1160 */
1167 if (opt) 1161 if (opt)
1168 return -1; 1162 return -1;
1169 asn1_tlc_clear(ctx); 1163 asn1_tlc_invalidate(ctx);
1170 ASN1error(ASN1_R_WRONG_TAG); 1164 ASN1error(ASN1_R_WRONG_TAG);
1171 return 0; 1165 return 0;
1172 } 1166 }
1173 /* We have a tag and class match: 1167 /* We have a tag and class match:
1174 * assume we are going to do something with it */ 1168 * assume we are going to do something with it */
1175 asn1_tlc_clear(ctx); 1169 asn1_tlc_invalidate(ctx);
1176 } 1170 }
1177 1171
1178 if (i & 1) 1172 if (i & 1)