OpenCoverage

tasn_fre.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/asn1/tasn_fre.c
Source codeSwitch to Preprocessed file
LineSourceCount
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-
18void 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 block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
1150500
22-
23void 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 block
Executed by:
  • libcrypto.so.1.1
629352
27-
28void 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)
!pvalDescription
TRUEnever evaluated
FALSEevaluated 7658496 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-7658496
37 return;
never executed: return;
0
38 if ((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval)
(it->itype != 0x0)Description
TRUEevaluated 3412774 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 4245722 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
!*pvalDescription
TRUEevaluated 873915 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2538859 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
873915-4245722
39 return;
executed 873915 times by 1 test: return;
Executed by:
  • libcrypto.so.1.1
873915
40 if (aux && aux->asn1_cb)
auxDescription
TRUEevaluated 733843 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 6050738 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
aux->asn1_cbDescription
TRUEevaluated 525436 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 208407 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
208407-6050738
41 asn1_cb = aux->asn1_cb;
executed 525436 times by 2 tests: asn1_cb = aux->asn1_cb;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
525436
42 else-
43 asn1_cb = 0;
executed 6259145 times by 2 tests: asn1_cb = 0;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
6259145
44-
45 switch (it->itype) {-
46-
47 case ASN1_ITYPE_PRIMITIVE:
executed 4245722 times by 2 tests: case 0x0:
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
4245722
48 if (it->templates)
it->templatesDescription
TRUEevaluated 191828 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4053894 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
191828-4053894
49 asn1_template_free(pval, it->templates);
executed 191828 times by 1 test: asn1_template_free(pval, it->templates);
Executed by:
  • libcrypto.so.1.1
191828
50 else-
51 asn1_primitive_free(pval, it, embed);
executed 4053894 times by 2 tests: asn1_primitive_free(pval, it, embed);
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
4053894
52 break;
executed 4245722 times by 2 tests: break;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
4245722
53-
54 case ASN1_ITYPE_MSTRING:
executed 440593 times by 1 test: case 0x5:
Executed by:
  • libcrypto.so.1.1
440593
55 asn1_primitive_free(pval, it, embed);-
56 break;
executed 440593 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
440593
57-
58 case ASN1_ITYPE_CHOICE:
executed 221755 times by 1 test: case 0x2:
Executed by:
  • libcrypto.so.1.1
221755
59 if (asn1_cb) {
asn1_cbDescription
TRUEevaluated 32587 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 189168 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
32587-189168
60 i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL);-
61 if (i == 2)
i == 2Description
TRUEnever evaluated
FALSEevaluated 32587 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-32587
62 return;
never executed: return;
0
63 }
executed 32587 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
32587
64 i = asn1_get_choice_selector(pval, it);-
65 if ((i >= 0) && (i < it->tcount)) {
(i >= 0)Description
TRUEevaluated 128753 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 93002 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
(i < it->tcount)Description
TRUEevaluated 128753 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
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 block
Executed by:
  • libcrypto.so.1.1
128753
72 if (asn1_cb)
asn1_cbDescription
TRUEevaluated 32587 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 189168 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
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:
  • libcrypto.so.1.1
32587
74 if (embed == 0) {
embed == 0Description
TRUEevaluated 215769 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 5986 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
5986-215769
75 OPENSSL_free(*pval);-
76 *pval = NULL;-
77 }
executed 215769 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
215769
78 break;
executed 221755 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
221755
79-
80 case ASN1_ITYPE_EXTERN:
executed 162664 times by 1 test: case 0x4:
Executed by:
  • libcrypto.so.1.1
162664
81 ef = it->funcs;-
82 if (ef && ef->asn1_ex_free)
efDescription
TRUEevaluated 162664 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
ef->asn1_ex_freeDescription
TRUEevaluated 162664 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-162664
83 ef->asn1_ex_free(pval, it);
executed 162664 times by 1 test: ef->asn1_ex_free(pval, it);
Executed by:
  • libcrypto.so.1.1
162664
84 break;
executed 162664 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
162664
85-
86 case ASN1_ITYPE_NDEF_SEQUENCE:
executed 50927 times by 1 test: case 0x6:
Executed by:
  • libcrypto.so.1.1
50927
87 case ASN1_ITYPE_SEQUENCE:
executed 1662920 times by 2 tests: case 0x1:
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
1662920
88 if (asn1_do_lock(pval, -1, it) != 0) /* if error or ref-counter > 0 */
asn1_do_lock(p..., -1, it) != 0Description
TRUEevaluated 35281 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1678566 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
35281-1678566
89 return;
executed 35281 times by 1 test: return;
Executed by:
  • libcrypto.so.1.1
35281
90 if (asn1_cb) {
asn1_cbDescription
TRUEevaluated 293216 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1385350 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
293216-1385350
91 i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL);-
92 if (i == 2)
i == 2Description
TRUEevaluated 27583 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 265633 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
27583-265633
93 return;
executed 27583 times by 1 test: return;
Executed by:
  • libcrypto.so.1.1
27583
94 }
executed 265633 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
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++) {
i < it->tcountDescription
TRUEevaluated 4837158 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 1650983 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
1650983-4837158
103 ASN1_VALUE **pseqval;-
104-
105 tt--;-
106 seqtt = asn1_do_adb(pval, tt, 0);-
107 if (!seqtt)
!seqttDescription
TRUEevaluated 20812 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4816346 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
20812-4816346
108 continue;
executed 20812 times by 1 test: continue;
Executed by:
  • libcrypto.so.1.1
20812
109 pseqval = asn1_get_field_ptr(pval, seqtt);-
110 asn1_template_free(pseqval, seqtt);-
111 }
executed 4816346 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
4816346
112 if (asn1_cb)
asn1_cbDescription
TRUEevaluated 265633 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1385350 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
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:
  • libcrypto.so.1.1
265633
114 if (embed == 0) {
embed == 0Description
TRUEevaluated 1338866 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 312117 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
312117-1338866
115 OPENSSL_free(*pval);-
116 *pval = NULL;-
117 }
executed 1338866 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
1338866
118 break;
executed 1650983 times by 2 tests: break;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
1650983
119 }-
120}
executed 6721717 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
6721717
121-
122void 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) {
embedDescription
TRUEevaluated 783161 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 5293230 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
783161-5293230
127 tval = (ASN1_VALUE *)pval;-
128 pval = &tval;-
129 }
executed 783161 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
783161
130 if (tt->flags & ASN1_TFLG_SK_MASK) {
tt->flags & (0x3 << 1)Description
TRUEevaluated 688095 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 5388296 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
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++) {
i < sk_ASN1_VALUE_num(sk)Description
TRUEevaluated 490348 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 688095 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
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 block
Executed by:
  • libcrypto.so.1.1
490348
139 sk_ASN1_VALUE_free(sk);-
140 *pval = NULL;-
141 } else {
executed 688095 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
688095
142 asn1_item_embed_free(pval, ASN1_ITEM_ptr(tt->item), embed);-
143 }
executed 5388296 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
5388296
144}-
145-
146void 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) {
itDescription
TRUEevaluated 4494487 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 237207 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
237207-4494487
152 const ASN1_PRIMITIVE_FUNCS *pf = it->funcs;-
153-
154 if (embed) {
embedDescription
TRUEevaluated 465058 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4029429 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
465058-4029429
155 if (pf && pf->prim_clear) {
pfDescription
TRUEevaluated 91950 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 373108 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
pf->prim_clearDescription
TRUEevaluated 91950 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-373108
156 pf->prim_clear(pval, it);-
157 return;
executed 91950 times by 1 test: return;
Executed by:
  • libcrypto.so.1.1
91950
158 }-
159 } else if (pf && pf->prim_free) {
executed 373108 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
pfDescription
TRUEevaluated 72402 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 3957027 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
pf->prim_freeDescription
TRUEevaluated 72402 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEnever evaluated
0-3957027
160 pf->prim_free(pval, it);-
161 return;
executed 72402 times by 2 tests: return;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
72402
162 }-
163 }
executed 4330135 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
4330135
164-
165 /* Special case: if 'it' is NULL, free contents of ASN1_TYPE */-
166 if (!it) {
!itDescription
TRUEevaluated 237207 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4330135 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
237207-4330135
167 ASN1_TYPE *typ = (ASN1_TYPE *)*pval;-
168-
169 utype = typ->type;-
170 pval = &typ->value.asn1_value;-
171 if (!*pval)
!*pvalDescription
TRUEevaluated 52418 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 184789 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
52418-184789
172 return;
executed 52418 times by 1 test: return;
Executed by:
  • libcrypto.so.1.1
52418
173 } else if (it->itype == ASN1_ITYPE_MSTRING) {
executed 184789 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
it->itype == 0x5Description
TRUEevaluated 440593 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3889542 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
184789-3889542
174 utype = -1;-
175 if (!*pval)
!*pvalDescription
TRUEnever evaluated
FALSEevaluated 440593 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-440593
176 return;
never executed: return;
0
177 } else {
executed 440593 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
440593
178 utype = it->utype;-
179 if ((utype != V_ASN1_BOOLEAN) && !*pval)
(utype != 1)Description
TRUEevaluated 3216252 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 673290 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
!*pvalDescription
TRUEevaluated 1181928 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2034324 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
673290-3216252
180 return;
executed 1181928 times by 1 test: return;
Executed by:
  • libcrypto.so.1.1
1181928
181 }
executed 2707614 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
2707614
182-
183 switch (utype) {-
184 case V_ASN1_OBJECT:
executed 974308 times by 1 test: case 6:
Executed by:
  • libcrypto.so.1.1
974308
185 ASN1_OBJECT_free((ASN1_OBJECT *)*pval);-
186 break;
executed 974308 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
974308
187-
188 case V_ASN1_BOOLEAN:
executed 674231 times by 1 test: case 1:
Executed by:
  • libcrypto.so.1.1
674231
189 if (it)
itDescription
TRUEevaluated 673290 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 941 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
941-673290
190 *(ASN1_BOOLEAN *)pval = it->size;
executed 673290 times by 1 test: *(ASN1_BOOLEAN *)pval = it->size;
Executed by:
  • libcrypto.so.1.1
673290
191 else-
192 *(ASN1_BOOLEAN *)pval = -1;
executed 941 times by 1 test: *(ASN1_BOOLEAN *)pval = -1;
Executed by:
  • libcrypto.so.1.1
941
193 return;
executed 674231 times by 1 test: return;
Executed by:
  • libcrypto.so.1.1
674231
194-
195 case V_ASN1_NULL:
executed 1162 times by 1 test: case 5:
Executed by:
  • libcrypto.so.1.1
1162
196 break;
executed 1162 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
1162
197-
198 case V_ASN1_ANY:
executed 237207 times by 1 test: case -4:
Executed by:
  • libcrypto.so.1.1
237207
199 asn1_primitive_free(pval, NULL, 0);-
200 OPENSSL_free(*pval);-
201 break;
executed 237207 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
237207
202-
203 default:
executed 1446088 times by 2 tests: default:
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
1446088
204 asn1_string_embed_free((ASN1_STRING *)*pval, embed);-
205 break;
executed 1446088 times by 2 tests: break;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
1446088
206 }-
207 *pval = NULL;-
208}
executed 2658765 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
2658765
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2