diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/tasn_new.c')
| -rw-r--r-- | src/lib/libcrypto/asn1/tasn_new.c | 94 |
1 files changed, 38 insertions, 56 deletions
diff --git a/src/lib/libcrypto/asn1/tasn_new.c b/src/lib/libcrypto/asn1/tasn_new.c index f5d7c690b8..00aa31dd63 100644 --- a/src/lib/libcrypto/asn1/tasn_new.c +++ b/src/lib/libcrypto/asn1/tasn_new.c | |||
| @@ -107,30 +107,27 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, | |||
| 107 | CRYPTO_push_info(it->sname); | 107 | CRYPTO_push_info(it->sname); |
| 108 | #endif | 108 | #endif |
| 109 | 109 | ||
| 110 | switch(it->itype) | 110 | switch(it->itype) { |
| 111 | { | ||
| 112 | 111 | ||
| 113 | case ASN1_ITYPE_EXTERN: | 112 | case ASN1_ITYPE_EXTERN: |
| 114 | ef = it->funcs; | 113 | ef = it->funcs; |
| 115 | if (ef && ef->asn1_ex_new) | 114 | if (ef && ef->asn1_ex_new) { |
| 116 | { | ||
| 117 | if (!ef->asn1_ex_new(pval, it)) | 115 | if (!ef->asn1_ex_new(pval, it)) |
| 118 | goto memerr; | 116 | goto memerr; |
| 119 | } | 117 | } |
| 120 | break; | 118 | break; |
| 121 | 119 | ||
| 122 | case ASN1_ITYPE_COMPAT: | 120 | case ASN1_ITYPE_COMPAT: |
| 123 | cf = it->funcs; | 121 | cf = it->funcs; |
| 124 | if (cf && cf->asn1_new) { | 122 | if (cf && cf->asn1_new) { |
| 125 | *pval = cf->asn1_new(); | 123 | *pval = cf->asn1_new(); |
| 126 | if (!*pval) | 124 | if (!*pval) |
| 127 | goto memerr; | 125 | goto memerr; |
| 128 | } | 126 | } |
| 129 | break; | 127 | break; |
| 130 | 128 | ||
| 131 | case ASN1_ITYPE_PRIMITIVE: | 129 | case ASN1_ITYPE_PRIMITIVE: |
| 132 | if (it->templates) | 130 | if (it->templates) { |
| 133 | { | ||
| 134 | if (!ASN1_template_new(pval, it->templates)) | 131 | if (!ASN1_template_new(pval, it->templates)) |
| 135 | goto memerr; | 132 | goto memerr; |
| 136 | } | 133 | } |
| @@ -138,19 +135,17 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, | |||
| 138 | goto memerr; | 135 | goto memerr; |
| 139 | break; | 136 | break; |
| 140 | 137 | ||
| 141 | case ASN1_ITYPE_MSTRING: | 138 | case ASN1_ITYPE_MSTRING: |
| 142 | if (!ASN1_primitive_new(pval, it)) | 139 | if (!ASN1_primitive_new(pval, it)) |
| 143 | goto memerr; | 140 | goto memerr; |
| 144 | break; | 141 | break; |
| 145 | 142 | ||
| 146 | case ASN1_ITYPE_CHOICE: | 143 | case ASN1_ITYPE_CHOICE: |
| 147 | if (asn1_cb) | 144 | if (asn1_cb) { |
| 148 | { | ||
| 149 | i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL); | 145 | i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL); |
| 150 | if (!i) | 146 | if (!i) |
| 151 | goto auxerr; | 147 | goto auxerr; |
| 152 | if (i==2) | 148 | if (i==2) { |
| 153 | { | ||
| 154 | #ifdef CRYPTO_MDEBUG | 149 | #ifdef CRYPTO_MDEBUG |
| 155 | if (it->sname) | 150 | if (it->sname) |
| 156 | CRYPTO_pop_info(); | 151 | CRYPTO_pop_info(); |
| @@ -158,8 +153,7 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, | |||
| 158 | return 1; | 153 | return 1; |
| 159 | } | 154 | } |
| 160 | } | 155 | } |
| 161 | if (!combine) | 156 | if (!combine) { |
| 162 | { | ||
| 163 | *pval = malloc(it->size); | 157 | *pval = malloc(it->size); |
| 164 | if (!*pval) | 158 | if (!*pval) |
| 165 | goto memerr; | 159 | goto memerr; |
| @@ -170,15 +164,13 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, | |||
| 170 | goto auxerr; | 164 | goto auxerr; |
| 171 | break; | 165 | break; |
| 172 | 166 | ||
| 173 | case ASN1_ITYPE_NDEF_SEQUENCE: | 167 | case ASN1_ITYPE_NDEF_SEQUENCE: |
| 174 | case ASN1_ITYPE_SEQUENCE: | 168 | case ASN1_ITYPE_SEQUENCE: |
| 175 | if (asn1_cb) | 169 | if (asn1_cb) { |
| 176 | { | ||
| 177 | i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL); | 170 | i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL); |
| 178 | if (!i) | 171 | if (!i) |
| 179 | goto auxerr; | 172 | goto auxerr; |
| 180 | if (i==2) | 173 | if (i==2) { |
| 181 | { | ||
| 182 | #ifdef CRYPTO_MDEBUG | 174 | #ifdef CRYPTO_MDEBUG |
| 183 | if (it->sname) | 175 | if (it->sname) |
| 184 | CRYPTO_pop_info(); | 176 | CRYPTO_pop_info(); |
| @@ -186,8 +178,7 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, | |||
| 186 | return 1; | 178 | return 1; |
| 187 | } | 179 | } |
| 188 | } | 180 | } |
| 189 | if (!combine) | 181 | if (!combine) { |
| 190 | { | ||
| 191 | *pval = malloc(it->size); | 182 | *pval = malloc(it->size); |
| 192 | if (!*pval) | 183 | if (!*pval) |
| 193 | goto memerr; | 184 | goto memerr; |
| @@ -195,8 +186,7 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, | |||
| 195 | asn1_do_lock(pval, 0, it); | 186 | asn1_do_lock(pval, 0, it); |
| 196 | asn1_enc_init(pval, it); | 187 | asn1_enc_init(pval, it); |
| 197 | } | 188 | } |
| 198 | for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) | 189 | for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) { |
| 199 | { | ||
| 200 | pseqval = asn1_get_field_ptr(pval, tt); | 190 | pseqval = asn1_get_field_ptr(pval, tt); |
| 201 | if (!ASN1_template_new(pseqval, tt)) | 191 | if (!ASN1_template_new(pseqval, tt)) |
| 202 | goto memerr; | 192 | goto memerr; |
| @@ -231,10 +221,9 @@ static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) | |||
| 231 | { | 221 | { |
| 232 | const ASN1_EXTERN_FUNCS *ef; | 222 | const ASN1_EXTERN_FUNCS *ef; |
| 233 | 223 | ||
| 234 | switch(it->itype) | 224 | switch(it->itype) { |
| 235 | { | ||
| 236 | 225 | ||
| 237 | case ASN1_ITYPE_EXTERN: | 226 | case ASN1_ITYPE_EXTERN: |
| 238 | ef = it->funcs; | 227 | ef = it->funcs; |
| 239 | if (ef && ef->asn1_ex_clear) | 228 | if (ef && ef->asn1_ex_clear) |
| 240 | ef->asn1_ex_clear(pval, it); | 229 | ef->asn1_ex_clear(pval, it); |
| @@ -242,21 +231,21 @@ static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) | |||
| 242 | break; | 231 | break; |
| 243 | 232 | ||
| 244 | 233 | ||
| 245 | case ASN1_ITYPE_PRIMITIVE: | 234 | case ASN1_ITYPE_PRIMITIVE: |
| 246 | if (it->templates) | 235 | if (it->templates) |
| 247 | asn1_template_clear(pval, it->templates); | 236 | asn1_template_clear(pval, it->templates); |
| 248 | else | 237 | else |
| 249 | asn1_primitive_clear(pval, it); | 238 | asn1_primitive_clear(pval, it); |
| 250 | break; | 239 | break; |
| 251 | 240 | ||
| 252 | case ASN1_ITYPE_MSTRING: | 241 | case ASN1_ITYPE_MSTRING: |
| 253 | asn1_primitive_clear(pval, it); | 242 | asn1_primitive_clear(pval, it); |
| 254 | break; | 243 | break; |
| 255 | 244 | ||
| 256 | case ASN1_ITYPE_COMPAT: | 245 | case ASN1_ITYPE_COMPAT: |
| 257 | case ASN1_ITYPE_CHOICE: | 246 | case ASN1_ITYPE_CHOICE: |
| 258 | case ASN1_ITYPE_SEQUENCE: | 247 | case ASN1_ITYPE_SEQUENCE: |
| 259 | case ASN1_ITYPE_NDEF_SEQUENCE: | 248 | case ASN1_ITYPE_NDEF_SEQUENCE: |
| 260 | *pval = NULL; | 249 | *pval = NULL; |
| 261 | break; | 250 | break; |
| 262 | } | 251 | } |
| @@ -267,15 +256,13 @@ int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) | |||
| 267 | { | 256 | { |
| 268 | const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item); | 257 | const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item); |
| 269 | int ret; | 258 | int ret; |
| 270 | if (tt->flags & ASN1_TFLG_OPTIONAL) | 259 | if (tt->flags & ASN1_TFLG_OPTIONAL) { |
| 271 | { | ||
| 272 | asn1_template_clear(pval, tt); | 260 | asn1_template_clear(pval, tt); |
| 273 | return 1; | 261 | return 1; |
| 274 | } | 262 | } |
| 275 | /* If ANY DEFINED BY nothing to do */ | 263 | /* If ANY DEFINED BY nothing to do */ |
| 276 | 264 | ||
| 277 | if (tt->flags & ASN1_TFLG_ADB_MASK) | 265 | if (tt->flags & ASN1_TFLG_ADB_MASK) { |
| 278 | { | ||
| 279 | *pval = NULL; | 266 | *pval = NULL; |
| 280 | return 1; | 267 | return 1; |
| 281 | } | 268 | } |
| @@ -284,12 +271,10 @@ int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) | |||
| 284 | CRYPTO_push_info(tt->field_name); | 271 | CRYPTO_push_info(tt->field_name); |
| 285 | #endif | 272 | #endif |
| 286 | /* If SET OF or SEQUENCE OF, its a STACK */ | 273 | /* If SET OF or SEQUENCE OF, its a STACK */ |
| 287 | if (tt->flags & ASN1_TFLG_SK_MASK) | 274 | if (tt->flags & ASN1_TFLG_SK_MASK) { |
| 288 | { | ||
| 289 | STACK_OF(ASN1_VALUE) *skval; | 275 | STACK_OF(ASN1_VALUE) *skval; |
| 290 | skval = sk_ASN1_VALUE_new_null(); | 276 | skval = sk_ASN1_VALUE_new_null(); |
| 291 | if (!skval) | 277 | if (!skval) { |
| 292 | { | ||
| 293 | ASN1err(ASN1_F_ASN1_TEMPLATE_NEW, ERR_R_MALLOC_FAILURE); | 278 | ASN1err(ASN1_F_ASN1_TEMPLATE_NEW, ERR_R_MALLOC_FAILURE); |
| 294 | ret = 0; | 279 | ret = 0; |
| 295 | goto done; | 280 | goto done; |
| @@ -328,8 +313,7 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) | |||
| 328 | ASN1_STRING *str; | 313 | ASN1_STRING *str; |
| 329 | int utype; | 314 | int utype; |
| 330 | 315 | ||
| 331 | if (it && it->funcs) | 316 | if (it && it->funcs) { |
| 332 | { | ||
| 333 | const ASN1_PRIMITIVE_FUNCS *pf = it->funcs; | 317 | const ASN1_PRIMITIVE_FUNCS *pf = it->funcs; |
| 334 | if (pf->prim_new) | 318 | if (pf->prim_new) |
| 335 | return pf->prim_new(pval, it); | 319 | return pf->prim_new(pval, it); |
| @@ -339,21 +323,20 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) | |||
| 339 | utype = -1; | 323 | utype = -1; |
| 340 | else | 324 | else |
| 341 | utype = it->utype; | 325 | utype = it->utype; |
| 342 | switch(utype) | 326 | switch(utype) { |
| 343 | { | 327 | case V_ASN1_OBJECT: |
| 344 | case V_ASN1_OBJECT: | ||
| 345 | *pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef); | 328 | *pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef); |
| 346 | return 1; | 329 | return 1; |
| 347 | 330 | ||
| 348 | case V_ASN1_BOOLEAN: | 331 | case V_ASN1_BOOLEAN: |
| 349 | *(ASN1_BOOLEAN *)pval = it->size; | 332 | *(ASN1_BOOLEAN *)pval = it->size; |
| 350 | return 1; | 333 | return 1; |
| 351 | 334 | ||
| 352 | case V_ASN1_NULL: | 335 | case V_ASN1_NULL: |
| 353 | *pval = (ASN1_VALUE *)1; | 336 | *pval = (ASN1_VALUE *)1; |
| 354 | return 1; | 337 | return 1; |
| 355 | 338 | ||
| 356 | case V_ASN1_ANY: | 339 | case V_ASN1_ANY: |
| 357 | typ = malloc(sizeof(ASN1_TYPE)); | 340 | typ = malloc(sizeof(ASN1_TYPE)); |
| 358 | if (!typ) | 341 | if (!typ) |
| 359 | return 0; | 342 | return 0; |
| @@ -362,7 +345,7 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) | |||
| 362 | *pval = (ASN1_VALUE *)typ; | 345 | *pval = (ASN1_VALUE *)typ; |
| 363 | break; | 346 | break; |
| 364 | 347 | ||
| 365 | default: | 348 | default: |
| 366 | str = ASN1_STRING_type_new(utype); | 349 | str = ASN1_STRING_type_new(utype); |
| 367 | if (it->itype == ASN1_ITYPE_MSTRING && str) | 350 | if (it->itype == ASN1_ITYPE_MSTRING && str) |
| 368 | str->flags |= ASN1_STRING_FLAG_MSTRING; | 351 | str->flags |= ASN1_STRING_FLAG_MSTRING; |
| @@ -377,8 +360,7 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) | |||
| 377 | static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) | 360 | static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) |
| 378 | { | 361 | { |
| 379 | int utype; | 362 | int utype; |
| 380 | if (it && it->funcs) | 363 | if (it && it->funcs) { |
| 381 | { | ||
| 382 | const ASN1_PRIMITIVE_FUNCS *pf = it->funcs; | 364 | const ASN1_PRIMITIVE_FUNCS *pf = it->funcs; |
| 383 | if (pf->prim_clear) | 365 | if (pf->prim_clear) |
| 384 | pf->prim_clear(pval, it); | 366 | pf->prim_clear(pval, it); |
