diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/tasn_fre.c')
-rw-r--r-- | src/lib/libcrypto/asn1/tasn_fre.c | 71 |
1 files changed, 27 insertions, 44 deletions
diff --git a/src/lib/libcrypto/asn1/tasn_fre.c b/src/lib/libcrypto/asn1/tasn_fre.c index b321de6615..5211276efe 100644 --- a/src/lib/libcrypto/asn1/tasn_fre.c +++ b/src/lib/libcrypto/asn1/tasn_fre.c | |||
@@ -93,30 +93,27 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c | |||
93 | else | 93 | else |
94 | asn1_cb = 0; | 94 | asn1_cb = 0; |
95 | 95 | ||
96 | switch(it->itype) | 96 | switch(it->itype) { |
97 | { | ||
98 | 97 | ||
99 | case ASN1_ITYPE_PRIMITIVE: | 98 | case ASN1_ITYPE_PRIMITIVE: |
100 | if (it->templates) | 99 | if (it->templates) |
101 | ASN1_template_free(pval, it->templates); | 100 | ASN1_template_free(pval, it->templates); |
102 | else | 101 | else |
103 | ASN1_primitive_free(pval, it); | 102 | ASN1_primitive_free(pval, it); |
104 | break; | 103 | break; |
105 | 104 | ||
106 | case ASN1_ITYPE_MSTRING: | 105 | case ASN1_ITYPE_MSTRING: |
107 | ASN1_primitive_free(pval, it); | 106 | ASN1_primitive_free(pval, it); |
108 | break; | 107 | break; |
109 | 108 | ||
110 | case ASN1_ITYPE_CHOICE: | 109 | case ASN1_ITYPE_CHOICE: |
111 | if (asn1_cb) | 110 | if (asn1_cb) { |
112 | { | ||
113 | i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL); | 111 | i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL); |
114 | if (i == 2) | 112 | if (i == 2) |
115 | return; | 113 | return; |
116 | } | 114 | } |
117 | i = asn1_get_choice_selector(pval, it); | 115 | i = asn1_get_choice_selector(pval, it); |
118 | if ((i >= 0) && (i < it->tcount)) | 116 | if ((i >= 0) && (i < it->tcount)) { |
119 | { | ||
120 | ASN1_VALUE **pchval; | 117 | ASN1_VALUE **pchval; |
121 | tt = it->templates + i; | 118 | tt = it->templates + i; |
122 | pchval = asn1_get_field_ptr(pval, tt); | 119 | pchval = asn1_get_field_ptr(pval, tt); |
@@ -124,31 +121,29 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c | |||
124 | } | 121 | } |
125 | if (asn1_cb) | 122 | if (asn1_cb) |
126 | asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL); | 123 | asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL); |
127 | if (!combine) | 124 | if (!combine) { |
128 | { | ||
129 | free(*pval); | 125 | free(*pval); |
130 | *pval = NULL; | 126 | *pval = NULL; |
131 | } | 127 | } |
132 | break; | 128 | break; |
133 | 129 | ||
134 | case ASN1_ITYPE_COMPAT: | 130 | case ASN1_ITYPE_COMPAT: |
135 | cf = it->funcs; | 131 | cf = it->funcs; |
136 | if (cf && cf->asn1_free) | 132 | if (cf && cf->asn1_free) |
137 | cf->asn1_free(*pval); | 133 | cf->asn1_free(*pval); |
138 | break; | 134 | break; |
139 | 135 | ||
140 | case ASN1_ITYPE_EXTERN: | 136 | case ASN1_ITYPE_EXTERN: |
141 | ef = it->funcs; | 137 | ef = it->funcs; |
142 | if (ef && ef->asn1_ex_free) | 138 | if (ef && ef->asn1_ex_free) |
143 | ef->asn1_ex_free(pval, it); | 139 | ef->asn1_ex_free(pval, it); |
144 | break; | 140 | break; |
145 | 141 | ||
146 | case ASN1_ITYPE_NDEF_SEQUENCE: | 142 | case ASN1_ITYPE_NDEF_SEQUENCE: |
147 | case ASN1_ITYPE_SEQUENCE: | 143 | case ASN1_ITYPE_SEQUENCE: |
148 | if (asn1_do_lock(pval, -1, it) > 0) | 144 | if (asn1_do_lock(pval, -1, it) > 0) |
149 | return; | 145 | return; |
150 | if (asn1_cb) | 146 | if (asn1_cb) { |
151 | { | ||
152 | i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL); | 147 | i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL); |
153 | if (i == 2) | 148 | if (i == 2) |
154 | return; | 149 | return; |
@@ -160,8 +155,7 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c | |||
160 | * free up in reverse order. | 155 | * free up in reverse order. |
161 | */ | 156 | */ |
162 | tt = it->templates + it->tcount - 1; | 157 | tt = it->templates + it->tcount - 1; |
163 | for (i = 0; i < it->tcount; tt--, i++) | 158 | for (i = 0; i < it->tcount; tt--, i++) { |
164 | { | ||
165 | ASN1_VALUE **pseqval; | 159 | ASN1_VALUE **pseqval; |
166 | seqtt = asn1_do_adb(pval, tt, 0); | 160 | seqtt = asn1_do_adb(pval, tt, 0); |
167 | if (!seqtt) | 161 | if (!seqtt) |
@@ -171,8 +165,7 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c | |||
171 | } | 165 | } |
172 | if (asn1_cb) | 166 | if (asn1_cb) |
173 | asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL); | 167 | asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL); |
174 | if (!combine) | 168 | if (!combine) { |
175 | { | ||
176 | free(*pval); | 169 | free(*pval); |
177 | *pval = NULL; | 170 | *pval = NULL; |
178 | } | 171 | } |
@@ -183,11 +176,9 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c | |||
183 | void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) | 176 | void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) |
184 | { | 177 | { |
185 | int i; | 178 | int i; |
186 | if (tt->flags & ASN1_TFLG_SK_MASK) | 179 | if (tt->flags & ASN1_TFLG_SK_MASK) { |
187 | { | ||
188 | STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval; | 180 | STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval; |
189 | for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) | 181 | for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) { |
190 | { | ||
191 | ASN1_VALUE *vtmp; | 182 | ASN1_VALUE *vtmp; |
192 | vtmp = sk_ASN1_VALUE_value(sk, i); | 183 | vtmp = sk_ASN1_VALUE_value(sk, i); |
193 | asn1_item_combine_free(&vtmp, ASN1_ITEM_ptr(tt->item), | 184 | asn1_item_combine_free(&vtmp, ASN1_ITEM_ptr(tt->item), |
@@ -204,60 +195,52 @@ void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) | |||
204 | void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it) | 195 | void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it) |
205 | { | 196 | { |
206 | int utype; | 197 | int utype; |
207 | if (it) | 198 | if (it) { |
208 | { | ||
209 | const ASN1_PRIMITIVE_FUNCS *pf; | 199 | const ASN1_PRIMITIVE_FUNCS *pf; |
210 | pf = it->funcs; | 200 | pf = it->funcs; |
211 | if (pf && pf->prim_free) | 201 | if (pf && pf->prim_free) { |
212 | { | ||
213 | pf->prim_free(pval, it); | 202 | pf->prim_free(pval, it); |
214 | return; | 203 | return; |
215 | } | 204 | } |
216 | } | 205 | } |
217 | /* Special case: if 'it' is NULL free contents of ASN1_TYPE */ | 206 | /* Special case: if 'it' is NULL free contents of ASN1_TYPE */ |
218 | if (!it) | 207 | if (!it) { |
219 | { | ||
220 | ASN1_TYPE *typ = (ASN1_TYPE *)*pval; | 208 | ASN1_TYPE *typ = (ASN1_TYPE *)*pval; |
221 | utype = typ->type; | 209 | utype = typ->type; |
222 | pval = &typ->value.asn1_value; | 210 | pval = &typ->value.asn1_value; |
223 | if (!*pval) | 211 | if (!*pval) |
224 | return; | 212 | return; |
225 | } | 213 | } else if (it->itype == ASN1_ITYPE_MSTRING) { |
226 | else if (it->itype == ASN1_ITYPE_MSTRING) | ||
227 | { | ||
228 | utype = -1; | 214 | utype = -1; |
229 | if (!*pval) | 215 | if (!*pval) |
230 | return; | 216 | return; |
231 | } | 217 | } else { |
232 | else | ||
233 | { | ||
234 | utype = it->utype; | 218 | utype = it->utype; |
235 | if ((utype != V_ASN1_BOOLEAN) && !*pval) | 219 | if ((utype != V_ASN1_BOOLEAN) && !*pval) |
236 | return; | 220 | return; |
237 | } | 221 | } |
238 | 222 | ||
239 | switch(utype) | 223 | switch(utype) { |
240 | { | 224 | case V_ASN1_OBJECT: |
241 | case V_ASN1_OBJECT: | ||
242 | ASN1_OBJECT_free((ASN1_OBJECT *)*pval); | 225 | ASN1_OBJECT_free((ASN1_OBJECT *)*pval); |
243 | break; | 226 | break; |
244 | 227 | ||
245 | case V_ASN1_BOOLEAN: | 228 | case V_ASN1_BOOLEAN: |
246 | if (it) | 229 | if (it) |
247 | *(ASN1_BOOLEAN *)pval = it->size; | 230 | *(ASN1_BOOLEAN *)pval = it->size; |
248 | else | 231 | else |
249 | *(ASN1_BOOLEAN *)pval = -1; | 232 | *(ASN1_BOOLEAN *)pval = -1; |
250 | return; | 233 | return; |
251 | 234 | ||
252 | case V_ASN1_NULL: | 235 | case V_ASN1_NULL: |
253 | break; | 236 | break; |
254 | 237 | ||
255 | case V_ASN1_ANY: | 238 | case V_ASN1_ANY: |
256 | ASN1_primitive_free(pval, NULL); | 239 | ASN1_primitive_free(pval, NULL); |
257 | free(*pval); | 240 | free(*pval); |
258 | break; | 241 | break; |
259 | 242 | ||
260 | default: | 243 | default: |
261 | ASN1_STRING_free((ASN1_STRING *)*pval); | 244 | ASN1_STRING_free((ASN1_STRING *)*pval); |
262 | *pval = NULL; | 245 | *pval = NULL; |
263 | break; | 246 | break; |