OpenCoverage

bs_ber.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/libressl/src/ssl/bs_ber.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9static const unsigned int kMaxDepth = 2048;-
10-
11-
12static int-
13cbs_nonstrict_get_any_asn1_element(CBS *cbs, CBS *out, unsigned int *out_tag,-
14 size_t *out_header_len)-
15{-
16 return
executed 31 times by 1 test: return cbs_get_any_asn1_element_internal(cbs, out, out_tag, out_header_len, 0);
Executed by:
  • bytestringtest
cbs_get_any_asn1_element_internal(cbs, out,
executed 31 times by 1 test: return cbs_get_any_asn1_element_internal(cbs, out, out_tag, out_header_len, 0);
Executed by:
  • bytestringtest
31
17 out_tag, out_header_len, 0);
executed 31 times by 1 test: return cbs_get_any_asn1_element_internal(cbs, out, out_tag, out_header_len, 0);
Executed by:
  • bytestringtest
31
18}-
19static int-
20cbs_find_indefinite(const CBS *orig_in, char *indefinite_found,-
21 unsigned int depth)-
22{-
23 CBS in;-
24-
25 if (depth > kMaxDepth
depth > kMaxDepthDescription
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • bytestringtest
)
0-4
26 return
never executed: return 0;
0;
never executed: return 0;
0
27-
28 CBS_init(&in, CBS_data(orig_in), CBS_len(orig_in));-
29-
30 while (CBS_len(&in) > 0
CBS_len(&in) > 0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 1 time by 1 test
Evaluated by:
  • bytestringtest
) {
1-4
31 CBS contents;-
32 unsigned int tag;-
33 size_t header_len;-
34-
35 if (!cbs_nonstrict_get_any_asn1_element(&in, &contents, &tag,
!cbs_nonstrict..., &header_len)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • bytestringtest
0-4
36 &header_len)
!cbs_nonstrict..., &header_len)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • bytestringtest
)
0-4
37 return
never executed: return 0;
0;
never executed: return 0;
0
38-
39-
40 if (CBS_len(&contents) == header_len
CBS_len(&conte... == header_lenDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 1 time by 1 test
Evaluated by:
  • bytestringtest
&& header_len > 0
header_len > 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • bytestringtest
FALSEnever evaluated
&&
0-3
41 CBS_data(&contents)[header_len - 1] == 0x80
CBS_data(&cont...n - 1] == 0x80Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • bytestringtest
FALSEnever evaluated
) {
0-3
42 *indefinite_found = 1;-
43 return
executed 3 times by 1 test: return 1;
Executed by:
  • bytestringtest
1;
executed 3 times by 1 test: return 1;
Executed by:
  • bytestringtest
3
44 }-
45 if (tag & 0x20
tag & 0x20Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • bytestringtest
) {
0-1
46 if (!CBS_skip(&contents, header_len)
!CBS_skip(&con...s, header_len)Description
TRUEnever evaluated
FALSEnever evaluated
||
0
47 !cbs_find_indefinite(&contents, indefinite_found,
!cbs_find_inde...nd, depth + 1)Description
TRUEnever evaluated
FALSEnever evaluated
0
48 depth + 1)
!cbs_find_inde...nd, depth + 1)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
49 return
never executed: return 0;
0;
never executed: return 0;
0
50 }
never executed: end of block
0
51 }
executed 1 time by 1 test: end of block
Executed by:
  • bytestringtest
1
52-
53 *indefinite_found = 0;-
54 return
executed 1 time by 1 test: return 1;
Executed by:
  • bytestringtest
1;
executed 1 time by 1 test: return 1;
Executed by:
  • bytestringtest
1
55}-
56-
57-
58-
59-
60-
61-
62-
63static char-
64is_primitive_type(unsigned int tag)-
65{-
66 return
executed 6 times by 1 test: return (tag & 0xc0) == 0 && (tag & 0x1f) != ((0x00 | 0x20 | 0x10) & 0x1f) && (tag & 0x1f) != ((0x00 | 0x20 | 0x11) & 0x1f);
Executed by:
  • bytestringtest
(
(tag & 0xc0) == 0Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 1 time by 1 test
Evaluated by:
  • bytestringtest
tag & 0xc0) == 0
(tag & 0xc0) == 0Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 1 time by 1 test
Evaluated by:
  • bytestringtest
&&
executed 6 times by 1 test: return (tag & 0xc0) == 0 && (tag & 0x1f) != ((0x00 | 0x20 | 0x10) & 0x1f) && (tag & 0x1f) != ((0x00 | 0x20 | 0x11) & 0x1f);
Executed by:
  • bytestringtest
1-6
67 (
(tag & 0x1f) !... 0x10) & 0x1f)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 3 times by 1 test
Evaluated by:
  • bytestringtest
tag & 0x1f) != ((0x00 | 0x20 | 0x10) & 0x1f)
(tag & 0x1f) !... 0x10) & 0x1f)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 3 times by 1 test
Evaluated by:
  • bytestringtest
&&
executed 6 times by 1 test: return (tag & 0xc0) == 0 && (tag & 0x1f) != ((0x00 | 0x20 | 0x10) & 0x1f) && (tag & 0x1f) != ((0x00 | 0x20 | 0x11) & 0x1f);
Executed by:
  • bytestringtest
2-6
68 (
(tag & 0x1f) !... 0x11) & 0x1f)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • bytestringtest
FALSEnever evaluated
tag & 0x1f) != ((0x00 | 0x20 | 0x11) & 0x1f)
(tag & 0x1f) !... 0x11) & 0x1f)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • bytestringtest
FALSEnever evaluated
;
executed 6 times by 1 test: return (tag & 0xc0) == 0 && (tag & 0x1f) != ((0x00 | 0x20 | 0x10) & 0x1f) && (tag & 0x1f) != ((0x00 | 0x20 | 0x11) & 0x1f);
Executed by:
  • bytestringtest
0-6
69}-
70-
71-
72-
73-
74-
75-
76static char-
77is_eoc(size_t header_len, CBS *contents)-
78{-
79 const unsigned char eoc[] = {0x0, 0x0};-
80-
81 return
executed 13 times by 1 test: return header_len == 2 && CBS_mem_equal(contents, eoc, 2);
Executed by:
  • bytestringtest
header_len == 2
header_len == 2Description
TRUEevaluated 13 times by 1 test
Evaluated by:
  • bytestringtest
FALSEnever evaluated
&& CBS_mem_equal(contents, eoc, 2)
CBS_mem_equal(...tents, eoc, 2)Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 7 times by 1 test
Evaluated by:
  • bytestringtest
;
executed 13 times by 1 test: return header_len == 2 && CBS_mem_equal(contents, eoc, 2);
Executed by:
  • bytestringtest
0-13
82}-
83static int-
84cbs_convert_indefinite(CBS *in, CBB *out, char squash_header,-
85 char looking_for_eoc, unsigned int depth)-
86{-
87 if (depth > kMaxDepth
depth > kMaxDepthDescription
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • bytestringtest
)
0-12
88 return
never executed: return 0;
0;
never executed: return 0;
0
89-
90 while (CBS_len(in) > 0
CBS_len(in) > 0Description
TRUEevaluated 26 times by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 6 times by 1 test
Evaluated by:
  • bytestringtest
) {
6-26
91 CBS contents;-
92 unsigned int tag;-
93 size_t header_len;-
94 CBB *out_contents, out_contents_storage;-
95-
96 if (!cbs_nonstrict_get_any_asn1_element(in, &contents, &tag,
!cbs_nonstrict..., &header_len)Description
TRUEnever evaluated
FALSEevaluated 26 times by 1 test
Evaluated by:
  • bytestringtest
0-26
97 &header_len)
!cbs_nonstrict..., &header_len)Description
TRUEnever evaluated
FALSEevaluated 26 times by 1 test
Evaluated by:
  • bytestringtest
)
0-26
98 return
never executed: return 0;
0;
never executed: return 0;
0
99-
100 out_contents = out;-
101-
102 if (CBS_len(&contents) == header_len
CBS_len(&conte... == header_lenDescription
TRUEevaluated 13 times by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 13 times by 1 test
Evaluated by:
  • bytestringtest
) {
13
103 if (is_eoc(header_len, &contents)
is_eoc(header_len, &contents)Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 7 times by 1 test
Evaluated by:
  • bytestringtest
)
6-7
104 return
executed 6 times by 1 test: return looking_for_eoc;
Executed by:
  • bytestringtest
looking_for_eoc;
executed 6 times by 1 test: return looking_for_eoc;
Executed by:
  • bytestringtest
6
105-
106 if (header_len > 0
header_len > 0Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • bytestringtest
FALSEnever evaluated
&&
0-7
107 CBS_data(&contents)[header_len - 1] == 0x80
CBS_data(&cont...n - 1] == 0x80Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 1 time by 1 test
Evaluated by:
  • bytestringtest
) {
1-6
108 const char context_specific = (tag & 0xc0)-
109 == 0x80;-
110 char squash_child_headers =-
111 is_primitive_type(tag);-
112 if (context_specific
context_specificDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 5 times by 1 test
Evaluated by:
  • bytestringtest
&&
1-5
113 (
(tag & 0x20)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • bytestringtest
FALSEnever evaluated
tag & 0x20)
(tag & 0x20)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • bytestringtest
FALSEnever evaluated
) {
0-1
114 CBS in_copy, inner_contents;-
115 unsigned int inner_tag;-
116 size_t inner_header_len;-
117-
118 CBS_init(&in_copy, CBS_data(in),-
119 CBS_len(in));-
120 if (!cbs_nonstrict_get_any_asn1_element(
!cbs_nonstrict...er_header_len)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • bytestringtest
0-1
121 &in_copy, &inner_contents,
!cbs_nonstrict...er_header_len)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • bytestringtest
0-1
122 &inner_tag, &inner_header_len)
!cbs_nonstrict...er_header_len)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • bytestringtest
)
0-1
123 return
never executed: return 0;
0;
never executed: return 0;
0
124-
125 if (CBS_len(&inner_contents) >
CBS_len(&inner...ner_header_lenDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • bytestringtest
0-1
126 inner_header_len
CBS_len(&inner...ner_header_lenDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • bytestringtest
&&
0-1
127 is_primitive_type(inner_tag)
is_primitive_type(inner_tag)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
128 squash_child_headers = 1;
never executed: squash_child_headers = 1;
0
129 }
executed 1 time by 1 test: end of block
Executed by:
  • bytestringtest
1
130-
131 if (!squash_header
!squash_headerDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • bytestringtest
FALSEnever evaluated
) {
0-6
132 unsigned int out_tag = tag;-
133-
134 if (squash_child_headers
squash_child_headersDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 4 times by 1 test
Evaluated by:
  • bytestringtest
)
2-4
135 out_tag &=
executed 2 times by 1 test: out_tag &= ~0x20;
Executed by:
  • bytestringtest
2
136 ~0x20;
executed 2 times by 1 test: out_tag &= ~0x20;
Executed by:
  • bytestringtest
2
137-
138 if (!CBB_add_asn1(out,
!CBB_add_asn1(...rage, out_tag)Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • bytestringtest
0-6
139 &out_contents_storage, out_tag)
!CBB_add_asn1(...rage, out_tag)Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • bytestringtest
)
0-6
140 return
never executed: return 0;
0;
never executed: return 0;
0
141-
142 out_contents = &out_contents_storage;-
143 }
executed 6 times by 1 test: end of block
Executed by:
  • bytestringtest
6
144-
145 if (!cbs_convert_indefinite(in, out_contents,
!cbs_convert_i...1 , depth + 1)Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • bytestringtest
0-6
146 squash_child_headers,
!cbs_convert_i...1 , depth + 1)Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • bytestringtest
0-6
147 1 , depth + 1)
!cbs_convert_i...1 , depth + 1)Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • bytestringtest
)
0-6
148 return
never executed: return 0;
0;
never executed: return 0;
0
149-
150 if (out_contents != out
out_contents != outDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • bytestringtest
FALSEnever evaluated
&& !CBB_flush(out)
!CBB_flush(out)Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • bytestringtest
)
0-6
151 return
never executed: return 0;
0;
never executed: return 0;
0
152-
153 continue;
executed 6 times by 1 test: continue;
Executed by:
  • bytestringtest
6
154 }-
155 }
executed 1 time by 1 test: end of block
Executed by:
  • bytestringtest
1
156-
157 if (!squash_header
!squash_headerDescription
TRUEevaluated 11 times by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 3 times by 1 test
Evaluated by:
  • bytestringtest
) {
3-11
158 if (!CBB_add_asn1(out, &out_contents_storage, tag)
!CBB_add_asn1(..._storage, tag)Description
TRUEnever evaluated
FALSEevaluated 11 times by 1 test
Evaluated by:
  • bytestringtest
)
0-11
159 return
never executed: return 0;
0;
never executed: return 0;
0
160-
161 out_contents = &out_contents_storage;-
162 }
executed 11 times by 1 test: end of block
Executed by:
  • bytestringtest
11
163-
164 if (!CBS_skip(&contents, header_len)
!CBS_skip(&con...s, header_len)Description
TRUEnever evaluated
FALSEevaluated 14 times by 1 test
Evaluated by:
  • bytestringtest
)
0-14
165 return
never executed: return 0;
0;
never executed: return 0;
0
166-
167 if (tag & 0x20
tag & 0x20Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 11 times by 1 test
Evaluated by:
  • bytestringtest
) {
3-11
168 if (!cbs_convert_indefinite(&contents, out_contents,
!cbs_convert_i...0 , depth + 1)Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • bytestringtest
0-3
169 0 ,
!cbs_convert_i...0 , depth + 1)Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • bytestringtest
0-3
170 0 , depth + 1)
!cbs_convert_i...0 , depth + 1)Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • bytestringtest
)
0-3
171 return
never executed: return 0;
0;
never executed: return 0;
0
172 }
executed 3 times by 1 test: end of block
Executed by:
  • bytestringtest
else {
3
173 if (!CBB_add_bytes(out_contents, CBS_data(&contents),
!CBB_add_bytes...en(&contents))Description
TRUEnever evaluated
FALSEevaluated 11 times by 1 test
Evaluated by:
  • bytestringtest
0-11
174 CBS_len(&contents))
!CBB_add_bytes...en(&contents))Description
TRUEnever evaluated
FALSEevaluated 11 times by 1 test
Evaluated by:
  • bytestringtest
)
0-11
175 return
never executed: return 0;
0;
never executed: return 0;
0
176 }
executed 11 times by 1 test: end of block
Executed by:
  • bytestringtest
11
177-
178 if (out_contents != out
out_contents != outDescription
TRUEevaluated 11 times by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 3 times by 1 test
Evaluated by:
  • bytestringtest
&& !CBB_flush(out)
!CBB_flush(out)Description
TRUEnever evaluated
FALSEevaluated 11 times by 1 test
Evaluated by:
  • bytestringtest
)
0-11
179 return
never executed: return 0;
0;
never executed: return 0;
0
180 }
executed 14 times by 1 test: end of block
Executed by:
  • bytestringtest
14
181-
182 return
executed 6 times by 1 test: return looking_for_eoc == 0;
Executed by:
  • bytestringtest
looking_for_eoc == 0;
executed 6 times by 1 test: return looking_for_eoc == 0;
Executed by:
  • bytestringtest
6
183}-
184-
185int-
186CBS_asn1_indefinite_to_definite(CBS *in, uint8_t **out, size_t *out_len)-
187{-
188 CBB cbb;-
189-
190-
191-
192-
193-
194-
195 char conversion_needed;-
196 if (!cbs_find_indefinite(in, &conversion_needed, 0)
!cbs_find_inde...ion_needed, 0)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • bytestringtest
)
0-4
197 return
never executed: return 0;
0;
never executed: return 0;
0
198-
199 if (!conversion_needed
!conversion_neededDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 3 times by 1 test
Evaluated by:
  • bytestringtest
) {
1-3
200 *out = -
201 ((void *)0)-
202 ;-
203 *out_len = 0;-
204 return
executed 1 time by 1 test: return 1;
Executed by:
  • bytestringtest
1;
executed 1 time by 1 test: return 1;
Executed by:
  • bytestringtest
1
205 }-
206-
207 if (!CBB_init(&cbb, CBS_len(in))
!CBB_init(&cbb, CBS_len(in))Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • bytestringtest
)
0-3
208 return
never executed: return 0;
0;
never executed: return 0;
0
209 if (!cbs_convert_indefinite(in, &cbb, 0, 0, 0)
!cbs_convert_i...&cbb, 0, 0, 0)Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • bytestringtest
) {
0-3
210 CBB_cleanup(&cbb);-
211 return
never executed: return 0;
0;
never executed: return 0;
0
212 }-
213-
214 return
executed 3 times by 1 test: return CBB_finish(&cbb, out, out_len);
Executed by:
  • bytestringtest
CBB_finish(&cbb, out, out_len);
executed 3 times by 1 test: return CBB_finish(&cbb, out, out_len);
Executed by:
  • bytestringtest
3
215}-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.2.2