| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/asn1/tasn_fre.c |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /* | - | ||||||||||||
| 2 | * Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved. | - | ||||||||||||
| 3 | * | - | ||||||||||||
| 4 | * Licensed under the OpenSSL license (the "License"). You may not use | - | ||||||||||||
| 5 | * this file except in compliance with the License. You can obtain a copy | - | ||||||||||||
| 6 | * in the file LICENSE in the source distribution or at | - | ||||||||||||
| 7 | * https://www.openssl.org/source/license.html | - | ||||||||||||
| 8 | */ | - | ||||||||||||
| 9 | - | |||||||||||||
| 10 | #include <stddef.h> | - | ||||||||||||
| 11 | #include <openssl/asn1.h> | - | ||||||||||||
| 12 | #include <openssl/asn1t.h> | - | ||||||||||||
| 13 | #include <openssl/objects.h> | - | ||||||||||||
| 14 | #include "asn1_locl.h" | - | ||||||||||||
| 15 | - | |||||||||||||
| 16 | /* Free up an ASN1 structure */ | - | ||||||||||||
| 17 | - | |||||||||||||
| 18 | void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it) | - | ||||||||||||
| 19 | { | - | ||||||||||||
| 20 | asn1_item_embed_free(&val, it, 0); | - | ||||||||||||
| 21 | } executed 1150500 times by 2 tests: end of blockExecuted by:
| 1150500 | ||||||||||||
| 22 | - | |||||||||||||
| 23 | void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it) | - | ||||||||||||
| 24 | { | - | ||||||||||||
| 25 | asn1_item_embed_free(pval, it, 0); | - | ||||||||||||
| 26 | } executed 629352 times by 1 test: end of blockExecuted by:
| 629352 | ||||||||||||
| 27 | - | |||||||||||||
| 28 | void asn1_item_embed_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed) | - | ||||||||||||
| 29 | { | - | ||||||||||||
| 30 | const ASN1_TEMPLATE *tt = NULL, *seqtt; | - | ||||||||||||
| 31 | const ASN1_EXTERN_FUNCS *ef; | - | ||||||||||||
| 32 | const ASN1_AUX *aux = it->funcs; | - | ||||||||||||
| 33 | ASN1_aux_cb *asn1_cb; | - | ||||||||||||
| 34 | int i; | - | ||||||||||||
| 35 | - | |||||||||||||
| 36 | if (!pval)
| 0-7658496 | ||||||||||||
| 37 | return; never executed: return; | 0 | ||||||||||||
| 38 | if ((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval)
| 873915-4245722 | ||||||||||||
| 39 | return; executed 873915 times by 1 test: return;Executed by:
| 873915 | ||||||||||||
| 40 | if (aux && aux->asn1_cb)
| 208407-6050738 | ||||||||||||
| 41 | asn1_cb = aux->asn1_cb; executed 525436 times by 2 tests: asn1_cb = aux->asn1_cb;Executed by:
| 525436 | ||||||||||||
| 42 | else | - | ||||||||||||
| 43 | asn1_cb = 0; executed 6259145 times by 2 tests: asn1_cb = 0;Executed by:
| 6259145 | ||||||||||||
| 44 | - | |||||||||||||
| 45 | switch (it->itype) { | - | ||||||||||||
| 46 | - | |||||||||||||
| 47 | case ASN1_ITYPE_PRIMITIVE: executed 4245722 times by 2 tests: case 0x0:Executed by:
| 4245722 | ||||||||||||
| 48 | if (it->templates)
| 191828-4053894 | ||||||||||||
| 49 | asn1_template_free(pval, it->templates); executed 191828 times by 1 test: asn1_template_free(pval, it->templates);Executed by:
| 191828 | ||||||||||||
| 50 | else | - | ||||||||||||
| 51 | asn1_primitive_free(pval, it, embed); executed 4053894 times by 2 tests: asn1_primitive_free(pval, it, embed);Executed by:
| 4053894 | ||||||||||||
| 52 | break; executed 4245722 times by 2 tests: break;Executed by:
| 4245722 | ||||||||||||
| 53 | - | |||||||||||||
| 54 | case ASN1_ITYPE_MSTRING: executed 440593 times by 1 test: case 0x5:Executed by:
| 440593 | ||||||||||||
| 55 | asn1_primitive_free(pval, it, embed); | - | ||||||||||||
| 56 | break; executed 440593 times by 1 test: break;Executed by:
| 440593 | ||||||||||||
| 57 | - | |||||||||||||
| 58 | case ASN1_ITYPE_CHOICE: executed 221755 times by 1 test: case 0x2:Executed by:
| 221755 | ||||||||||||
| 59 | if (asn1_cb) {
| 32587-189168 | ||||||||||||
| 60 | i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL); | - | ||||||||||||
| 61 | if (i == 2)
| 0-32587 | ||||||||||||
| 62 | return; never executed: return; | 0 | ||||||||||||
| 63 | } executed 32587 times by 1 test: end of blockExecuted by:
| 32587 | ||||||||||||
| 64 | i = asn1_get_choice_selector(pval, it); | - | ||||||||||||
| 65 | if ((i >= 0) && (i < it->tcount)) {
| 0-128753 | ||||||||||||
| 66 | ASN1_VALUE **pchval; | - | ||||||||||||
| 67 | - | |||||||||||||
| 68 | tt = it->templates + i; | - | ||||||||||||
| 69 | pchval = asn1_get_field_ptr(pval, tt); | - | ||||||||||||
| 70 | asn1_template_free(pchval, tt); | - | ||||||||||||
| 71 | } executed 128753 times by 1 test: end of blockExecuted by:
| 128753 | ||||||||||||
| 72 | if (asn1_cb)
| 32587-189168 | ||||||||||||
| 73 | asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL); executed 32587 times by 1 test: asn1_cb(3, pval, it, ((void *)0) );Executed by:
| 32587 | ||||||||||||
| 74 | if (embed == 0) {
| 5986-215769 | ||||||||||||
| 75 | OPENSSL_free(*pval); | - | ||||||||||||
| 76 | *pval = NULL; | - | ||||||||||||
| 77 | } executed 215769 times by 1 test: end of blockExecuted by:
| 215769 | ||||||||||||
| 78 | break; executed 221755 times by 1 test: break;Executed by:
| 221755 | ||||||||||||
| 79 | - | |||||||||||||
| 80 | case ASN1_ITYPE_EXTERN: executed 162664 times by 1 test: case 0x4:Executed by:
| 162664 | ||||||||||||
| 81 | ef = it->funcs; | - | ||||||||||||
| 82 | if (ef && ef->asn1_ex_free)
| 0-162664 | ||||||||||||
| 83 | ef->asn1_ex_free(pval, it); executed 162664 times by 1 test: ef->asn1_ex_free(pval, it);Executed by:
| 162664 | ||||||||||||
| 84 | break; executed 162664 times by 1 test: break;Executed by:
| 162664 | ||||||||||||
| 85 | - | |||||||||||||
| 86 | case ASN1_ITYPE_NDEF_SEQUENCE: executed 50927 times by 1 test: case 0x6:Executed by:
| 50927 | ||||||||||||
| 87 | case ASN1_ITYPE_SEQUENCE: executed 1662920 times by 2 tests: case 0x1:Executed by:
| 1662920 | ||||||||||||
| 88 | if (asn1_do_lock(pval, -1, it) != 0) /* if error or ref-counter > 0 */
| 35281-1678566 | ||||||||||||
| 89 | return; executed 35281 times by 1 test: return;Executed by:
| 35281 | ||||||||||||
| 90 | if (asn1_cb) {
| 293216-1385350 | ||||||||||||
| 91 | i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL); | - | ||||||||||||
| 92 | if (i == 2)
| 27583-265633 | ||||||||||||
| 93 | return; executed 27583 times by 1 test: return;Executed by:
| 27583 | ||||||||||||
| 94 | } executed 265633 times by 1 test: end of blockExecuted by:
| 265633 | ||||||||||||
| 95 | asn1_enc_free(pval, it); | - | ||||||||||||
| 96 | /* | - | ||||||||||||
| 97 | * If we free up as normal we will invalidate any ANY DEFINED BY | - | ||||||||||||
| 98 | * field and we won't be able to determine the type of the field it | - | ||||||||||||
| 99 | * defines. So free up in reverse order. | - | ||||||||||||
| 100 | */ | - | ||||||||||||
| 101 | tt = it->templates + it->tcount; | - | ||||||||||||
| 102 | for (i = 0; i < it->tcount; i++) {
| 1650983-4837158 | ||||||||||||
| 103 | ASN1_VALUE **pseqval; | - | ||||||||||||
| 104 | - | |||||||||||||
| 105 | tt--; | - | ||||||||||||
| 106 | seqtt = asn1_do_adb(pval, tt, 0); | - | ||||||||||||
| 107 | if (!seqtt)
| 20812-4816346 | ||||||||||||
| 108 | continue; executed 20812 times by 1 test: continue;Executed by:
| 20812 | ||||||||||||
| 109 | pseqval = asn1_get_field_ptr(pval, seqtt); | - | ||||||||||||
| 110 | asn1_template_free(pseqval, seqtt); | - | ||||||||||||
| 111 | } executed 4816346 times by 2 tests: end of blockExecuted by:
| 4816346 | ||||||||||||
| 112 | if (asn1_cb)
| 265633-1385350 | ||||||||||||
| 113 | asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL); executed 265633 times by 1 test: asn1_cb(3, pval, it, ((void *)0) );Executed by:
| 265633 | ||||||||||||
| 114 | if (embed == 0) {
| 312117-1338866 | ||||||||||||
| 115 | OPENSSL_free(*pval); | - | ||||||||||||
| 116 | *pval = NULL; | - | ||||||||||||
| 117 | } executed 1338866 times by 2 tests: end of blockExecuted by:
| 1338866 | ||||||||||||
| 118 | break; executed 1650983 times by 2 tests: break;Executed by:
| 1650983 | ||||||||||||
| 119 | } | - | ||||||||||||
| 120 | } executed 6721717 times by 2 tests: end of blockExecuted by:
| 6721717 | ||||||||||||
| 121 | - | |||||||||||||
| 122 | void asn1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) | - | ||||||||||||
| 123 | { | - | ||||||||||||
| 124 | int embed = tt->flags & ASN1_TFLG_EMBED; | - | ||||||||||||
| 125 | ASN1_VALUE *tval; | - | ||||||||||||
| 126 | if (embed) {
| 783161-5293230 | ||||||||||||
| 127 | tval = (ASN1_VALUE *)pval; | - | ||||||||||||
| 128 | pval = &tval; | - | ||||||||||||
| 129 | } executed 783161 times by 1 test: end of blockExecuted by:
| 783161 | ||||||||||||
| 130 | if (tt->flags & ASN1_TFLG_SK_MASK) {
| 688095-5388296 | ||||||||||||
| 131 | STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval; | - | ||||||||||||
| 132 | int i; | - | ||||||||||||
| 133 | - | |||||||||||||
| 134 | for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
| 490348-688095 | ||||||||||||
| 135 | ASN1_VALUE *vtmp = sk_ASN1_VALUE_value(sk, i); | - | ||||||||||||
| 136 | - | |||||||||||||
| 137 | asn1_item_embed_free(&vtmp, ASN1_ITEM_ptr(tt->item), embed); | - | ||||||||||||
| 138 | } executed 490348 times by 1 test: end of blockExecuted by:
| 490348 | ||||||||||||
| 139 | sk_ASN1_VALUE_free(sk); | - | ||||||||||||
| 140 | *pval = NULL; | - | ||||||||||||
| 141 | } else { executed 688095 times by 1 test: end of blockExecuted by:
| 688095 | ||||||||||||
| 142 | asn1_item_embed_free(pval, ASN1_ITEM_ptr(tt->item), embed); | - | ||||||||||||
| 143 | } executed 5388296 times by 2 tests: end of blockExecuted by:
| 5388296 | ||||||||||||
| 144 | } | - | ||||||||||||
| 145 | - | |||||||||||||
| 146 | void asn1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed) | - | ||||||||||||
| 147 | { | - | ||||||||||||
| 148 | int utype; | - | ||||||||||||
| 149 | - | |||||||||||||
| 150 | /* Special case: if 'it' is a primitive with a free_func, use that. */ | - | ||||||||||||
| 151 | if (it) {
| 237207-4494487 | ||||||||||||
| 152 | const ASN1_PRIMITIVE_FUNCS *pf = it->funcs; | - | ||||||||||||
| 153 | - | |||||||||||||
| 154 | if (embed) {
| 465058-4029429 | ||||||||||||
| 155 | if (pf && pf->prim_clear) {
| 0-373108 | ||||||||||||
| 156 | pf->prim_clear(pval, it); | - | ||||||||||||
| 157 | return; executed 91950 times by 1 test: return;Executed by:
| 91950 | ||||||||||||
| 158 | } | - | ||||||||||||
| 159 | } else if (pf && pf->prim_free) { executed 373108 times by 1 test: end of blockExecuted by:
| 0-3957027 | ||||||||||||
| 160 | pf->prim_free(pval, it); | - | ||||||||||||
| 161 | return; executed 72402 times by 2 tests: return;Executed by:
| 72402 | ||||||||||||
| 162 | } | - | ||||||||||||
| 163 | } executed 4330135 times by 2 tests: end of blockExecuted by:
| 4330135 | ||||||||||||
| 164 | - | |||||||||||||
| 165 | /* Special case: if 'it' is NULL, free contents of ASN1_TYPE */ | - | ||||||||||||
| 166 | if (!it) {
| 237207-4330135 | ||||||||||||
| 167 | ASN1_TYPE *typ = (ASN1_TYPE *)*pval; | - | ||||||||||||
| 168 | - | |||||||||||||
| 169 | utype = typ->type; | - | ||||||||||||
| 170 | pval = &typ->value.asn1_value; | - | ||||||||||||
| 171 | if (!*pval)
| 52418-184789 | ||||||||||||
| 172 | return; executed 52418 times by 1 test: return;Executed by:
| 52418 | ||||||||||||
| 173 | } else if (it->itype == ASN1_ITYPE_MSTRING) { executed 184789 times by 1 test: end of blockExecuted by:
| 184789-3889542 | ||||||||||||
| 174 | utype = -1; | - | ||||||||||||
| 175 | if (!*pval)
| 0-440593 | ||||||||||||
| 176 | return; never executed: return; | 0 | ||||||||||||
| 177 | } else { executed 440593 times by 1 test: end of blockExecuted by:
| 440593 | ||||||||||||
| 178 | utype = it->utype; | - | ||||||||||||
| 179 | if ((utype != V_ASN1_BOOLEAN) && !*pval)
| 673290-3216252 | ||||||||||||
| 180 | return; executed 1181928 times by 1 test: return;Executed by:
| 1181928 | ||||||||||||
| 181 | } executed 2707614 times by 2 tests: end of blockExecuted by:
| 2707614 | ||||||||||||
| 182 | - | |||||||||||||
| 183 | switch (utype) { | - | ||||||||||||
| 184 | case V_ASN1_OBJECT: executed 974308 times by 1 test: case 6:Executed by:
| 974308 | ||||||||||||
| 185 | ASN1_OBJECT_free((ASN1_OBJECT *)*pval); | - | ||||||||||||
| 186 | break; executed 974308 times by 1 test: break;Executed by:
| 974308 | ||||||||||||
| 187 | - | |||||||||||||
| 188 | case V_ASN1_BOOLEAN: executed 674231 times by 1 test: case 1:Executed by:
| 674231 | ||||||||||||
| 189 | if (it)
| 941-673290 | ||||||||||||
| 190 | *(ASN1_BOOLEAN *)pval = it->size; executed 673290 times by 1 test: *(ASN1_BOOLEAN *)pval = it->size;Executed by:
| 673290 | ||||||||||||
| 191 | else | - | ||||||||||||
| 192 | *(ASN1_BOOLEAN *)pval = -1; executed 941 times by 1 test: *(ASN1_BOOLEAN *)pval = -1;Executed by:
| 941 | ||||||||||||
| 193 | return; executed 674231 times by 1 test: return;Executed by:
| 674231 | ||||||||||||
| 194 | - | |||||||||||||
| 195 | case V_ASN1_NULL: executed 1162 times by 1 test: case 5:Executed by:
| 1162 | ||||||||||||
| 196 | break; executed 1162 times by 1 test: break;Executed by:
| 1162 | ||||||||||||
| 197 | - | |||||||||||||
| 198 | case V_ASN1_ANY: executed 237207 times by 1 test: case -4:Executed by:
| 237207 | ||||||||||||
| 199 | asn1_primitive_free(pval, NULL, 0); | - | ||||||||||||
| 200 | OPENSSL_free(*pval); | - | ||||||||||||
| 201 | break; executed 237207 times by 1 test: break;Executed by:
| 237207 | ||||||||||||
| 202 | - | |||||||||||||
| 203 | default: executed 1446088 times by 2 tests: default:Executed by:
| 1446088 | ||||||||||||
| 204 | asn1_string_embed_free((ASN1_STRING *)*pval, embed); | - | ||||||||||||
| 205 | break; executed 1446088 times by 2 tests: break;Executed by:
| 1446088 | ||||||||||||
| 206 | } | - | ||||||||||||
| 207 | *pval = NULL; | - | ||||||||||||
| 208 | } executed 2658765 times by 2 tests: end of blockExecuted by:
| 2658765 | ||||||||||||
| Source code | Switch to Preprocessed file |