Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/ssl/bs_ber.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | - | |||||||||||||
5 | - | |||||||||||||
6 | - | |||||||||||||
7 | - | |||||||||||||
8 | - | |||||||||||||
9 | static const unsigned int kMaxDepth = 2048; | - | ||||||||||||
10 | - | |||||||||||||
11 | - | |||||||||||||
12 | static int | - | ||||||||||||
13 | cbs_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: cbs_get_any_asn1_element_internal(cbs, out,return cbs_get_any_asn1_element_internal(cbs, out, out_tag, out_header_len, 0); Executed by:
executed 31 times by 1 test: return cbs_get_any_asn1_element_internal(cbs, out, out_tag, out_header_len, 0); Executed by:
| 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:
| 31 | ||||||||||||
18 | } | - | ||||||||||||
19 | static int | - | ||||||||||||
20 | cbs_find_indefinite(const CBS *orig_in, char *indefinite_found, | - | ||||||||||||
21 | unsigned int depth) | - | ||||||||||||
22 | { | - | ||||||||||||
23 | CBS in; | - | ||||||||||||
24 | - | |||||||||||||
25 | if (depth > kMaxDepth
| 0-4 | ||||||||||||
26 | return never executed: 0;return 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
| 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,
| 0-4 | ||||||||||||
36 | &header_len)
| 0-4 | ||||||||||||
37 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
38 | - | |||||||||||||
39 | - | |||||||||||||
40 | if (CBS_len(&contents) == header_len
| 0-3 | ||||||||||||
41 | CBS_data(&contents)[header_len - 1] == 0x80
| 0-3 | ||||||||||||
42 | *indefinite_found = 1; | - | ||||||||||||
43 | return executed 3 times by 1 test: 1;return 1; Executed by:
executed 3 times by 1 test: return 1; Executed by:
| 3 | ||||||||||||
44 | } | - | ||||||||||||
45 | if (tag & 0x20
| 0-1 | ||||||||||||
46 | if (!CBS_skip(&contents, header_len)
| 0 | ||||||||||||
47 | !cbs_find_indefinite(&contents, indefinite_found,
| 0 | ||||||||||||
48 | depth + 1)
| 0 | ||||||||||||
49 | return never executed: 0;return 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:
| 1 | ||||||||||||
52 | - | |||||||||||||
53 | *indefinite_found = 0; | - | ||||||||||||
54 | return executed 1 time by 1 test: 1;return 1; Executed by:
executed 1 time by 1 test: return 1; Executed by:
| 1 | ||||||||||||
55 | } | - | ||||||||||||
56 | - | |||||||||||||
57 | - | |||||||||||||
58 | - | |||||||||||||
59 | - | |||||||||||||
60 | - | |||||||||||||
61 | - | |||||||||||||
62 | - | |||||||||||||
63 | static char | - | ||||||||||||
64 | is_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:
executed 6 times by 1 test: return (tag & 0xc0) == 0 && (tag & 0x1f) != ((0x00 | 0x20 | 0x10) & 0x1f) && (tag & 0x1f) != ((0x00 | 0x20 | 0x11) & 0x1f); Executed by:
| 1-6 | ||||||||||||
67 | (
executed 6 times by 1 test: return (tag & 0xc0) == 0 && (tag & 0x1f) != ((0x00 | 0x20 | 0x10) & 0x1f) && (tag & 0x1f) != ((0x00 | 0x20 | 0x11) & 0x1f); Executed by:
| 2-6 | ||||||||||||
68 | (
executed 6 times by 1 test: return (tag & 0xc0) == 0 && (tag & 0x1f) != ((0x00 | 0x20 | 0x10) & 0x1f) && (tag & 0x1f) != ((0x00 | 0x20 | 0x11) & 0x1f); Executed by:
| 0-6 | ||||||||||||
69 | } | - | ||||||||||||
70 | - | |||||||||||||
71 | - | |||||||||||||
72 | - | |||||||||||||
73 | - | |||||||||||||
74 | - | |||||||||||||
75 | - | |||||||||||||
76 | static char | - | ||||||||||||
77 | is_eoc(size_t header_len, CBS *contents) | - | ||||||||||||
78 | { | - | ||||||||||||
79 | const unsigned char eoc[] = {0x0, 0x0}; | - | ||||||||||||
80 | - | |||||||||||||
81 | return executed 13 times by 1 test: header_len == 2return header_len == 2 && CBS_mem_equal(contents, eoc, 2); Executed by:
executed 13 times by 1 test: return header_len == 2 && CBS_mem_equal(contents, eoc, 2); Executed by:
| 0-13 | ||||||||||||
82 | } | - | ||||||||||||
83 | static int | - | ||||||||||||
84 | cbs_convert_indefinite(CBS *in, CBB *out, char squash_header, | - | ||||||||||||
85 | char looking_for_eoc, unsigned int depth) | - | ||||||||||||
86 | { | - | ||||||||||||
87 | if (depth > kMaxDepth
| 0-12 | ||||||||||||
88 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
89 | - | |||||||||||||
90 | while (CBS_len(in) > 0
| 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,
| 0-26 | ||||||||||||
97 | &header_len)
| 0-26 | ||||||||||||
98 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
99 | - | |||||||||||||
100 | out_contents = out; | - | ||||||||||||
101 | - | |||||||||||||
102 | if (CBS_len(&contents) == header_len
| 13 | ||||||||||||
103 | if (is_eoc(header_len, &contents)
| 6-7 | ||||||||||||
104 | return executed 6 times by 1 test: looking_for_eoc;return looking_for_eoc; Executed by:
executed 6 times by 1 test: return looking_for_eoc; Executed by:
| 6 | ||||||||||||
105 | - | |||||||||||||
106 | if (header_len > 0
| 0-7 | ||||||||||||
107 | CBS_data(&contents)[header_len - 1] == 0x80
| 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
| 1-5 | ||||||||||||
113 | (
| 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(
| 0-1 | ||||||||||||
121 | &in_copy, &inner_contents,
| 0-1 | ||||||||||||
122 | &inner_tag, &inner_header_len)
| 0-1 | ||||||||||||
123 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
124 | - | |||||||||||||
125 | if (CBS_len(&inner_contents) >
| 0-1 | ||||||||||||
126 | inner_header_len
| 0-1 | ||||||||||||
127 | is_primitive_type(inner_tag)
| 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:
| 1 | ||||||||||||
130 | - | |||||||||||||
131 | if (!squash_header
| 0-6 | ||||||||||||
132 | unsigned int out_tag = tag; | - | ||||||||||||
133 | - | |||||||||||||
134 | if (squash_child_headers
| 2-4 | ||||||||||||
135 | out_tag &= executed 2 times by 1 test: out_tag &= ~0x20; Executed by:
| 2 | ||||||||||||
136 | ~0x20; executed 2 times by 1 test: out_tag &= ~0x20; Executed by:
| 2 | ||||||||||||
137 | - | |||||||||||||
138 | if (!CBB_add_asn1(out,
| 0-6 | ||||||||||||
139 | &out_contents_storage, out_tag)
| 0-6 | ||||||||||||
140 | return never executed: 0;return 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:
| 6 | ||||||||||||
144 | - | |||||||||||||
145 | if (!cbs_convert_indefinite(in, out_contents,
| 0-6 | ||||||||||||
146 | squash_child_headers,
| 0-6 | ||||||||||||
147 | 1 , depth + 1)
| 0-6 | ||||||||||||
148 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
149 | - | |||||||||||||
150 | if (out_contents != out
| 0-6 | ||||||||||||
151 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
152 | - | |||||||||||||
153 | continue; executed 6 times by 1 test: continue; Executed by:
| 6 | ||||||||||||
154 | } | - | ||||||||||||
155 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
156 | - | |||||||||||||
157 | if (!squash_header
| 3-11 | ||||||||||||
158 | if (!CBB_add_asn1(out, &out_contents_storage, tag)
| 0-11 | ||||||||||||
159 | return never executed: 0;return 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:
| 11 | ||||||||||||
163 | - | |||||||||||||
164 | if (!CBS_skip(&contents, header_len)
| 0-14 | ||||||||||||
165 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
166 | - | |||||||||||||
167 | if (tag & 0x20
| 3-11 | ||||||||||||
168 | if (!cbs_convert_indefinite(&contents, out_contents,
| 0-3 | ||||||||||||
169 | 0 ,
| 0-3 | ||||||||||||
170 | 0 , depth + 1)
| 0-3 | ||||||||||||
171 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
172 | } executed 3 times by 1 test: else {end of block Executed by:
| 3 | ||||||||||||
173 | if (!CBB_add_bytes(out_contents, CBS_data(&contents),
| 0-11 | ||||||||||||
174 | CBS_len(&contents))
| 0-11 | ||||||||||||
175 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
176 | } executed 11 times by 1 test: end of block Executed by:
| 11 | ||||||||||||
177 | - | |||||||||||||
178 | if (out_contents != out
| 0-11 | ||||||||||||
179 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
180 | } executed 14 times by 1 test: end of block Executed by:
| 14 | ||||||||||||
181 | - | |||||||||||||
182 | return executed 6 times by 1 test: looking_for_eoc == 0;return looking_for_eoc == 0; Executed by:
executed 6 times by 1 test: return looking_for_eoc == 0; Executed by:
| 6 | ||||||||||||
183 | } | - | ||||||||||||
184 | - | |||||||||||||
185 | int | - | ||||||||||||
186 | CBS_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)
| 0-4 | ||||||||||||
197 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
198 | - | |||||||||||||
199 | if (!conversion_needed
| 1-3 | ||||||||||||
200 | *out = | - | ||||||||||||
201 | ((void *)0) | - | ||||||||||||
202 | ; | - | ||||||||||||
203 | *out_len = 0; | - | ||||||||||||
204 | return executed 1 time by 1 test: 1;return 1; Executed by:
executed 1 time by 1 test: return 1; Executed by:
| 1 | ||||||||||||
205 | } | - | ||||||||||||
206 | - | |||||||||||||
207 | if (!CBB_init(&cbb, CBS_len(in))
| 0-3 | ||||||||||||
208 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
209 | if (!cbs_convert_indefinite(in, &cbb, 0, 0, 0)
| 0-3 | ||||||||||||
210 | CBB_cleanup(&cbb); | - | ||||||||||||
211 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
212 | } | - | ||||||||||||
213 | - | |||||||||||||
214 | return executed 3 times by 1 test: CBB_finish(&cbb, out, out_len);return CBB_finish(&cbb, out, out_len); Executed by:
executed 3 times by 1 test: return CBB_finish(&cbb, out, out_len); Executed by:
| 3 | ||||||||||||
215 | } | - | ||||||||||||
Switch to Source code | Preprocessed file |