OpenCoverage

bs_cbs.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/libressl/src/ssl/bs_cbs.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* $OpenBSD: bs_cbs.c,v 1.17 2015/06/24 09:44:18 jsing Exp $ */-
2/*-
3 * Copyright (c) 2014, Google Inc.-
4 *-
5 * Permission to use, copy, modify, and/or distribute this software for any-
6 * purpose with or without fee is hereby granted, provided that the above-
7 * copyright notice and this permission notice appear in all copies.-
8 *-
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES-
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF-
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY-
12 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES-
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION-
14 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN-
15 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */-
16-
17#include <assert.h>-
18#include <stdlib.h>-
19#include <string.h>-
20-
21#include <openssl/opensslconf.h>-
22#include <openssl/buffer.h>-
23#include <openssl/crypto.h>-
24-
25#include "bytestring.h"-
26-
27void-
28CBS_init(CBS *cbs, const uint8_t *data, size_t len)-
29{-
30 cbs->data = data;-
31 cbs->initial_len = len;-
32 cbs->len = len;-
33}
executed 5272 times by 10 tests: end of block
Executed by:
  • asn1test
  • bytestringtest
  • cipher_list
  • cipherstest
  • clienttest
  • servertest
  • ssltest
  • tls_ext_alpn
  • tlsexttest
  • tlstest
5272
34-
35void-
36CBS_dup(const CBS *cbs, CBS *out)-
37{-
38 CBS_init(out, CBS_data(cbs), CBS_len(cbs));-
39 out->initial_len = cbs->initial_len;-
40}
executed 139 times by 6 tests: end of block
Executed by:
  • bytestringtest
  • servertest
  • ssltest
  • tls_ext_alpn
  • tlsexttest
  • tlstest
139
41-
42static int-
43cbs_get(CBS *cbs, const uint8_t **p, size_t n)-
44{-
45 if (cbs->len < n)
cbs->len < nDescription
TRUEevaluated 41 times by 3 tests
Evaluated by:
  • bytestringtest
  • cipher_list
  • tls_ext_alpn
FALSEevaluated 12534 times by 10 tests
Evaluated by:
  • asn1test
  • bytestringtest
  • cipher_list
  • cipherstest
  • clienttest
  • servertest
  • ssltest
  • tls_ext_alpn
  • tlsexttest
  • tlstest
41-12534
46 return 0;
executed 41 times by 3 tests: return 0;
Executed by:
  • bytestringtest
  • cipher_list
  • tls_ext_alpn
41
47-
48 *p = cbs->data;-
49 cbs->data += n;-
50 cbs->len -= n;-
51 return 1;
executed 12534 times by 10 tests: return 1;
Executed by:
  • asn1test
  • bytestringtest
  • cipher_list
  • cipherstest
  • clienttest
  • servertest
  • ssltest
  • tls_ext_alpn
  • tlsexttest
  • tlstest
12534
52}-
53-
54size_t-
55CBS_offset(const CBS *cbs)-
56{-
57 return cbs->initial_len - cbs->len;
executed 11 times by 1 test: return cbs->initial_len - cbs->len;
Executed by:
  • bytestringtest
11
58}-
59-
60int-
61CBS_skip(CBS *cbs, size_t len)-
62{-
63 const uint8_t *dummy;-
64 return cbs_get(cbs, &dummy, len);
executed 148 times by 3 tests: return cbs_get(cbs, &dummy, len);
Executed by:
  • asn1test
  • bytestringtest
  • ssltest
148
65}-
66-
67const uint8_t *-
68CBS_data(const CBS *cbs)-
69{-
70 return cbs->data;
executed 959 times by 7 tests: return cbs->data;
Executed by:
  • asn1test
  • bytestringtest
  • servertest
  • ssltest
  • tls_ext_alpn
  • tlsexttest
  • tlstest
959
71}-
72-
73size_t-
74CBS_len(const CBS *cbs)-
75{-
76 return cbs->len;
executed 5934 times by 8 tests: return cbs->len;
Executed by:
  • asn1test
  • bytestringtest
  • cipher_list
  • servertest
  • ssltest
  • tls_ext_alpn
  • tlsexttest
  • tlstest
5934
77}-
78-
79int-
80CBS_stow(const CBS *cbs, uint8_t **out_ptr, size_t *out_len)-
81{-
82 free(*out_ptr);-
83 *out_ptr = NULL;-
84 *out_len = 0;-
85-
86 if (cbs->len == 0)
cbs->len == 0Description
TRUEnever evaluated
FALSEevaluated 132 times by 5 tests
Evaluated by:
  • asn1test
  • ssltest
  • tls_ext_alpn
  • tlsexttest
  • tlstest
0-132
87 return 1;
never executed: return 1;
0
88-
89 if ((*out_ptr = malloc(cbs->len)) == NULL)
(*out_ptr = ma...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 132 times by 5 tests
Evaluated by:
  • asn1test
  • ssltest
  • tls_ext_alpn
  • tlsexttest
  • tlstest
0-132
90 return 0;
never executed: return 0;
0
91-
92 memcpy(*out_ptr, cbs->data, cbs->len);-
93-
94 *out_len = cbs->len;-
95 return 1;
executed 132 times by 5 tests: return 1;
Executed by:
  • asn1test
  • ssltest
  • tls_ext_alpn
  • tlsexttest
  • tlstest
132
96}-
97-
98int-
99CBS_strdup(const CBS *cbs, char **out_ptr)-
100{-
101 free(*out_ptr);-
102 *out_ptr = strndup((const char *)cbs->data, cbs->len);
never executed: __len = __n + 1;
never executed: end of block
__n < __lenDescription
TRUEnever evaluated
FALSEnever evaluated
__retval != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
((const char *... ))[0] == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons... *)cbs->data )Description
TRUEnever evaluated
FALSEevaluated 6 times by 3 tests
Evaluated by:
  • asn1test
  • tlsexttest
  • tlstest
((size_t)(cons...->data ) == 1)Description
TRUEnever evaluated
FALSEnever evaluated
0-6
103 return (*out_ptr != NULL);
executed 6 times by 3 tests: return (*out_ptr != ((void *)0) );
Executed by:
  • asn1test
  • tlsexttest
  • tlstest
6
104}-
105-
106int-
107CBS_write_bytes(const CBS *cbs, uint8_t *dst, size_t dst_len, size_t *copied)-
108{-
109 if (dst_len < cbs->len)
dst_len < cbs->lenDescription
TRUEnever evaluated
FALSEevaluated 361 times by 5 tests
Evaluated by:
  • asn1test
  • bytestringtest
  • servertest
  • ssltest
  • tlstest
0-361
110 return 0;
never executed: return 0;
0
111-
112 memmove(dst, cbs->data, cbs->len);-
113-
114 if (copied != NULL)
copied != ((void *)0)Description
TRUEevaluated 73 times by 4 tests
Evaluated by:
  • asn1test
  • bytestringtest
  • ssltest
  • tlstest
FALSEevaluated 288 times by 3 tests
Evaluated by:
  • servertest
  • ssltest
  • tlstest
73-288
115 *copied = cbs->len;
executed 73 times by 4 tests: *copied = cbs->len;
Executed by:
  • asn1test
  • bytestringtest
  • ssltest
  • tlstest
73
116-
117 return 1;
executed 361 times by 5 tests: return 1;
Executed by:
  • asn1test
  • bytestringtest
  • servertest
  • ssltest
  • tlstest
361
118}-
119-
120int-
121CBS_contains_zero_byte(const CBS *cbs)-
122{-
123 return memchr(cbs->data, 0, cbs->len) != NULL;
executed 67 times by 4 tests: return memchr(cbs->data, 0, cbs->len) != ((void *)0) ;
Executed by:
  • asn1test
  • ssltest
  • tlsexttest
  • tlstest
67
124}-
125-
126int-
127CBS_mem_equal(const CBS *cbs, const uint8_t *data, size_t len)-
128{-
129 if (len != cbs->len)
len != cbs->lenDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tlsexttest
FALSEevaluated 270 times by 4 tests
Evaluated by:
  • bytestringtest
  • ssltest
  • tlsexttest
  • tlstest
1-270
130 return 0;
executed 1 time by 1 test: return 0;
Executed by:
  • tlsexttest
1
131-
132 return timingsafe_memcmp(cbs->data, data, len) == 0;
executed 270 times by 4 tests: return timingsafe_memcmp(cbs->data, data, len) == 0;
Executed by:
  • bytestringtest
  • ssltest
  • tlsexttest
  • tlstest
270
133}-
134-
135static int-
136cbs_get_u(CBS *cbs, uint32_t *out, size_t len)-
137{-
138 uint32_t result = 0;-
139 size_t i;-
140 const uint8_t *data;-
141-
142 if (len < 1 || len > 4)
len < 1Description
TRUEnever evaluated
FALSEevaluated 7138 times by 9 tests
Evaluated by:
  • asn1test
  • bytestringtest
  • cipher_list
  • cipherstest
  • servertest
  • ssltest
  • tls_ext_alpn
  • tlsexttest
  • tlstest
len > 4Description
TRUEnever evaluated
FALSEevaluated 7138 times by 9 tests
Evaluated by:
  • asn1test
  • bytestringtest
  • cipher_list
  • cipherstest
  • servertest
  • ssltest
  • tls_ext_alpn
  • tlsexttest
  • tlstest
0-7138
143 return 0;
never executed: return 0;
0
144-
145 if (!cbs_get(cbs, &data, len))
!cbs_get(cbs, &data, len)Description
TRUEevaluated 6 times by 2 tests
Evaluated by:
  • cipher_list
  • tls_ext_alpn
FALSEevaluated 7132 times by 9 tests
Evaluated by:
  • asn1test
  • bytestringtest
  • cipher_list
  • cipherstest
  • servertest
  • ssltest
  • tls_ext_alpn
  • tlsexttest
  • tlstest
6-7132
146 return 0;
executed 6 times by 2 tests: return 0;
Executed by:
  • cipher_list
  • tls_ext_alpn
6
147-
148 for (i = 0; i < len; i++) {
i < lenDescription
TRUEevaluated 14973 times by 9 tests
Evaluated by:
  • asn1test
  • bytestringtest
  • cipher_list
  • cipherstest
  • servertest
  • ssltest
  • tls_ext_alpn
  • tlsexttest
  • tlstest
FALSEevaluated 7132 times by 9 tests
Evaluated by:
  • asn1test
  • bytestringtest
  • cipher_list
  • cipherstest
  • servertest
  • ssltest
  • tls_ext_alpn
  • tlsexttest
  • tlstest
7132-14973
149 result <<= 8;-
150 result |= data[i];-
151 }
executed 14973 times by 9 tests: end of block
Executed by:
  • asn1test
  • bytestringtest
  • cipher_list
  • cipherstest
  • servertest
  • ssltest
  • tls_ext_alpn
  • tlsexttest
  • tlstest
14973
152 *out = result;-
153 return 1;
executed 7132 times by 9 tests: return 1;
Executed by:
  • asn1test
  • bytestringtest
  • cipher_list
  • cipherstest
  • servertest
  • ssltest
  • tls_ext_alpn
  • tlsexttest
  • tlstest
7132
154}-
155-
156int-
157CBS_get_u8(CBS *cbs, uint8_t *out)-
158{-
159 const uint8_t *v;-
160-
161 if (!cbs_get(cbs, &v, 1))
!cbs_get(cbs, &v, 1)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 3071 times by 7 tests
Evaluated by:
  • asn1test
  • bytestringtest
  • clienttest
  • servertest
  • ssltest
  • tlsexttest
  • tlstest
2-3071
162 return 0;
executed 2 times by 1 test: return 0;
Executed by:
  • bytestringtest
2
163-
164 *out = *v;-
165 return 1;
executed 3071 times by 7 tests: return 1;
Executed by:
  • asn1test
  • bytestringtest
  • clienttest
  • servertest
  • ssltest
  • tlsexttest
  • tlstest
3071
166}-
167-
168int-
169CBS_get_u16(CBS *cbs, uint16_t *out)-
170{-
171 uint32_t v;-
172-
173 if (!cbs_get_u(cbs, &v, 2))
!cbs_get_u(cbs, &v, 2)Description
TRUEevaluated 4 times by 2 tests
Evaluated by:
  • cipher_list
  • tls_ext_alpn
FALSEevaluated 4498 times by 9 tests
Evaluated by:
  • asn1test
  • bytestringtest
  • cipher_list
  • cipherstest
  • servertest
  • ssltest
  • tls_ext_alpn
  • tlsexttest
  • tlstest
4-4498
174 return 0;
executed 4 times by 2 tests: return 0;
Executed by:
  • cipher_list
  • tls_ext_alpn
4
175-
176 *out = v;-
177 return 1;
executed 4498 times by 9 tests: return 1;
Executed by:
  • asn1test
  • bytestringtest
  • cipher_list
  • cipherstest
  • servertest
  • ssltest
  • tls_ext_alpn
  • tlsexttest
  • tlstest
4498
178}-
179-
180int-
181CBS_get_u24(CBS *cbs, uint32_t *out)-
182{-
183 return cbs_get_u(cbs, out, 3);
executed 874 times by 4 tests: return cbs_get_u(cbs, out, 3);
Executed by:
  • bytestringtest
  • servertest
  • ssltest
  • tlstest
874
184}-
185-
186int-
187CBS_get_u32(CBS *cbs, uint32_t *out)-
188{-
189 return cbs_get_u(cbs, out, 4);
executed 60 times by 2 tests: return cbs_get_u(cbs, out, 4);
Executed by:
  • bytestringtest
  • ssltest
60
190}-
191-
192int-
193CBS_get_bytes(CBS *cbs, CBS *out, size_t len)-
194{-
195 const uint8_t *v;-
196-
197 if (!cbs_get(cbs, &v, len))
!cbs_get(cbs, &v, len)Description
TRUEevaluated 30 times by 2 tests
Evaluated by:
  • bytestringtest
  • tls_ext_alpn
FALSEevaluated 2186 times by 7 tests
Evaluated by:
  • asn1test
  • bytestringtest
  • servertest
  • ssltest
  • tls_ext_alpn
  • tlsexttest
  • tlstest
30-2186
198 return 0;
executed 30 times by 2 tests: return 0;
Executed by:
  • bytestringtest
  • tls_ext_alpn
30
199-
200 CBS_init(out, v, len);-
201 return 1;
executed 2186 times by 7 tests: return 1;
Executed by:
  • asn1test
  • bytestringtest
  • servertest
  • ssltest
  • tls_ext_alpn
  • tlsexttest
  • tlstest
2186
202}-
203-
204static int-
205cbs_get_length_prefixed(CBS *cbs, CBS *out, size_t len_len)-
206{-
207 uint32_t len;-
208-
209 if (!cbs_get_u(cbs, &len, len_len))
!cbs_get_u(cbs, &len, len_len)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tls_ext_alpn
FALSEevaluated 1694 times by 6 tests
Evaluated by:
  • bytestringtest
  • servertest
  • ssltest
  • tls_ext_alpn
  • tlsexttest
  • tlstest
2-1694
210 return 0;
executed 2 times by 1 test: return 0;
Executed by:
  • tls_ext_alpn
2
211-
212 return CBS_get_bytes(cbs, out, len);
executed 1694 times by 6 tests: return CBS_get_bytes(cbs, out, len);
Executed by:
  • bytestringtest
  • servertest
  • ssltest
  • tls_ext_alpn
  • tlsexttest
  • tlstest
1694
213}-
214-
215int-
216CBS_get_u8_length_prefixed(CBS *cbs, CBS *out)-
217{-
218 return cbs_get_length_prefixed(cbs, out, 1);
executed 438 times by 6 tests: return cbs_get_length_prefixed(cbs, out, 1);
Executed by:
  • bytestringtest
  • servertest
  • ssltest
  • tls_ext_alpn
  • tlsexttest
  • tlstest
438
219}-
220-
221int-
222CBS_get_u16_length_prefixed(CBS *cbs, CBS *out)-
223{-
224 return cbs_get_length_prefixed(cbs, out, 2);
executed 1102 times by 6 tests: return cbs_get_length_prefixed(cbs, out, 2);
Executed by:
  • bytestringtest
  • servertest
  • ssltest
  • tls_ext_alpn
  • tlsexttest
  • tlstest
1102
225}-
226-
227int-
228CBS_get_u24_length_prefixed(CBS *cbs, CBS *out)-
229{-
230 return cbs_get_length_prefixed(cbs, out, 3);
executed 156 times by 3 tests: return cbs_get_length_prefixed(cbs, out, 3);
Executed by:
  • bytestringtest
  • ssltest
  • tlstest
156
231}-
232-
233int-
234CBS_get_any_asn1_element(CBS *cbs, CBS *out, unsigned int *out_tag,-
235 size_t *out_header_len)-
236{-
237 return cbs_get_any_asn1_element_internal(cbs, out, out_tag,
executed 70 times by 2 tests: return cbs_get_any_asn1_element_internal(cbs, out, out_tag, out_header_len, 1);
Executed by:
  • asn1test
  • bytestringtest
70
238 out_header_len, 1);
executed 70 times by 2 tests: return cbs_get_any_asn1_element_internal(cbs, out, out_tag, out_header_len, 1);
Executed by:
  • asn1test
  • bytestringtest
70
239}-
240-
241/*-
242 * Review X.690 for details on ASN.1 DER encoding.-
243 *-
244 * If non-strict mode is enabled, then DER rules are relaxed-
245 * for indefinite constructs (violates DER but a little closer to BER).-
246 * Non-strict mode should only be used by bs_ber.c-
247 *-
248 * Sections 8, 10 and 11 for DER encoding-
249 */-
250int-
251cbs_get_any_asn1_element_internal(CBS *cbs, CBS *out, unsigned int *out_tag,-
252 size_t *out_header_len, int strict)-
253{-
254 uint8_t tag, length_byte;-
255 CBS header = *cbs;-
256 CBS throwaway;-
257 size_t len;-
258-
259 if (out == NULL)
out == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 101 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
0-101
260 out = &throwaway;
never executed: out = &throwaway;
0
261-
262 /*-
263 * Get identifier octet and length octet. Only 1 octet for each-
264 * is a CBS limitation.-
265 */-
266 if (!CBS_get_u8(&header, &tag) || !CBS_get_u8(&header, &length_byte))
!CBS_get_u8(&header, &tag)Description
TRUEnever evaluated
FALSEevaluated 101 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
!CBS_get_u8(&h... &length_byte)Description
TRUEnever evaluated
FALSEevaluated 101 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
0-101
267 return 0;
never executed: return 0;
0
268-
269 /* CBS limitation: long form tags are not supported. */-
270 if ((tag & 0x1f) == 0x1f)
(tag & 0x1f) == 0x1fDescription
TRUEnever evaluated
FALSEevaluated 101 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
0-101
271 return 0;
never executed: return 0;
0
272-
273 if (out_tag != NULL)
out_tag != ((void *)0)Description
TRUEevaluated 101 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
FALSEnever evaluated
0-101
274 *out_tag = tag;
executed 101 times by 2 tests: *out_tag = tag;
Executed by:
  • asn1test
  • bytestringtest
101
275-
276 if ((length_byte & 0x80) == 0) {
(length_byte & 0x80) == 0Description
TRUEevaluated 84 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
FALSEevaluated 17 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
17-84
277 /* Short form length. */-
278 len = ((size_t) length_byte) + 2;-
279 if (out_header_len != NULL)
out_header_len != ((void *)0)Description
TRUEevaluated 84 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
FALSEnever evaluated
0-84
280 *out_header_len = 2;
executed 84 times by 2 tests: *out_header_len = 2;
Executed by:
  • asn1test
  • bytestringtest
84
281-
282 } else {
executed 84 times by 2 tests: end of block
Executed by:
  • asn1test
  • bytestringtest
84
283 /* Long form length. */-
284 const size_t num_bytes = length_byte & 0x7f;-
285 uint32_t len32;-
286-
287 /* ASN.1 reserved value for future extensions */-
288 if (num_bytes == 0x7f)
num_bytes == 0x7fDescription
TRUEnever evaluated
FALSEevaluated 17 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
0-17
289 return 0;
never executed: return 0;
0
290-
291 /* Handle indefinite form length */-
292 if (num_bytes == 0) {
num_bytes == 0Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 6 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
6-11
293 /* DER encoding doesn't allow for indefinite form. */-
294 if (strict)
strictDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 10 times by 1 test
Evaluated by:
  • bytestringtest
1-10
295 return 0;
executed 1 time by 1 test: return 0;
Executed by:
  • bytestringtest
1
296-
297 /* Primitive cannot use indefinite in BER or DER. */-
298 if ((tag & CBS_ASN1_CONSTRUCTED) == 0)
(tag & 0x20) == 0Description
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • bytestringtest
0-10
299 return 0;
never executed: return 0;
0
300-
301 /* Constructed, indefinite length allowed in BER. */-
302 if (out_header_len != NULL)
out_header_len != ((void *)0)Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • bytestringtest
FALSEnever evaluated
0-10
303 *out_header_len = 2;
executed 10 times by 1 test: *out_header_len = 2;
Executed by:
  • bytestringtest
10
304 return CBS_get_bytes(cbs, out, 2);
executed 10 times by 1 test: return CBS_get_bytes(cbs, out, 2);
Executed by:
  • bytestringtest
10
305 }-
306-
307 /* CBS limitation. */-
308 if (num_bytes > 4)
num_bytes > 4Description
TRUEnever evaluated
FALSEevaluated 6 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
0-6
309 return 0;
never executed: return 0;
0
310-
311 if (!cbs_get_u(&header, &len32, num_bytes))
!cbs_get_u(&he...32, num_bytes)Description
TRUEnever evaluated
FALSEevaluated 6 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
0-6
312 return 0;
never executed: return 0;
0
313-
314 /* DER has a minimum length octet requirement. */-
315 if (len32 < 128)
len32 < 128Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 5 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
1-5
316 /* Should have used short form instead */-
317 return 0;
executed 1 time by 1 test: return 0;
Executed by:
  • bytestringtest
1
318-
319 if ((len32 >> ((num_bytes - 1) * 8)) == 0)
(len32 >> ((nu... 1) * 8)) == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 4 times by 1 test
Evaluated by:
  • asn1test
1-4
320 /* Length should have been at least one byte shorter. */-
321 return 0;
executed 1 time by 1 test: return 0;
Executed by:
  • bytestringtest
1
322-
323 len = len32;-
324 if (len + 2 + num_bytes < len)
len + 2 + num_bytes < lenDescription
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • asn1test
0-4
325 /* Overflow. */-
326 return 0;
never executed: return 0;
0
327-
328 len += 2 + num_bytes;-
329 if (out_header_len != NULL)
out_header_len != ((void *)0)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • asn1test
FALSEnever evaluated
0-4
330 *out_header_len = 2 + num_bytes;
executed 4 times by 1 test: *out_header_len = 2 + num_bytes;
Executed by:
  • asn1test
4
331 }
executed 4 times by 1 test: end of block
Executed by:
  • asn1test
4
332-
333 return CBS_get_bytes(cbs, out, len);
executed 88 times by 2 tests: return CBS_get_bytes(cbs, out, len);
Executed by:
  • asn1test
  • bytestringtest
88
334}-
335-
336static int-
337cbs_get_asn1(CBS *cbs, CBS *out, unsigned int tag_value, int skip_header)-
338{-
339 size_t header_len;-
340 unsigned int tag;-
341 CBS throwaway;-
342-
343 if (out == NULL)
out == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 70 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
0-70
344 out = &throwaway;
never executed: out = &throwaway;
0
345-
346 if (!CBS_get_any_asn1_element(cbs, out, &tag, &header_len) ||
!CBS_get_any_a..., &header_len)Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 65 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
5-65
347 tag != tag_value)
tag != tag_valueDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 63 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
2-63
348 return 0;
executed 7 times by 1 test: return 0;
Executed by:
  • bytestringtest
7
349-
350 if (skip_header && !CBS_skip(out, header_len)) {
skip_headerDescription
TRUEevaluated 63 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
FALSEnever evaluated
!CBS_skip(out, header_len)Description
TRUEnever evaluated
FALSEevaluated 63 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
0-63
351 assert(0);-
352 return 0;
never executed: return 0;
0
353 }-
354-
355 return 1;
executed 63 times by 2 tests: return 1;
Executed by:
  • asn1test
  • bytestringtest
63
356}-
357-
358int-
359CBS_get_asn1(CBS *cbs, CBS *out, unsigned int tag_value)-
360{-
361 return cbs_get_asn1(cbs, out, tag_value, 1 /* skip header */);
executed 70 times by 2 tests: return cbs_get_asn1(cbs, out, tag_value, 1 );
Executed by:
  • asn1test
  • bytestringtest
70
362}-
363-
364int-
365CBS_get_asn1_element(CBS *cbs, CBS *out, unsigned int tag_value)-
366{-
367 return cbs_get_asn1(cbs, out, tag_value, 0 /* include header */);
never executed: return cbs_get_asn1(cbs, out, tag_value, 0 );
0
368}-
369-
370int-
371CBS_peek_asn1_tag(const CBS *cbs, unsigned int tag_value)-
372{-
373 if (CBS_len(cbs) < 1)
CBS_len(cbs) < 1Description
TRUEevaluated 14 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
FALSEevaluated 29 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
14-29
374 return 0;
executed 14 times by 2 tests: return 0;
Executed by:
  • asn1test
  • bytestringtest
14
375-
376 /*-
377 * Tag number 31 indicates the start of a long form number.-
378 * This is valid in ASN.1, but CBS only supports short form.-
379 */-
380 if ((tag_value & 0x1f) == 0x1f)
(tag_value & 0x1f) == 0x1fDescription
TRUEnever evaluated
FALSEevaluated 29 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
0-29
381 return 0;
never executed: return 0;
0
382-
383 return CBS_data(cbs)[0] == tag_value;
executed 29 times by 2 tests: return CBS_data(cbs)[0] == tag_value;
Executed by:
  • asn1test
  • bytestringtest
29
384}-
385-
386/* Encoding details are in ASN.1: X.690 section 8.3 */-
387int-
388CBS_get_asn1_uint64(CBS *cbs, uint64_t *out)-
389{-
390 CBS bytes;-
391 const uint8_t *data;-
392 size_t i, len;-
393-
394 if (!CBS_get_asn1(cbs, &bytes, CBS_ASN1_INTEGER))
!CBS_get_asn1(...| 0x00 | 0x2))Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 23 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
1-23
395 return 0;
executed 1 time by 1 test: return 0;
Executed by:
  • bytestringtest
1
396-
397 *out = 0;-
398 data = CBS_data(&bytes);-
399 len = CBS_len(&bytes);-
400-
401 if (len == 0)
len == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 22 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
1-22
402 /* An INTEGER is encoded with at least one content octet. */-
403 return 0;
executed 1 time by 1 test: return 0;
Executed by:
  • bytestringtest
1
404-
405 if ((data[0] & 0x80) != 0)
(data[0] & 0x80) != 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 20 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
2-20
406 /* Negative number. */-
407 return 0;
executed 2 times by 1 test: return 0;
Executed by:
  • bytestringtest
2
408-
409 if (data[0] == 0 && len > 1 && (data[1] & 0x80) == 0)
data[0] == 0Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 15 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
len > 1Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 1 time by 1 test
Evaluated by:
  • bytestringtest
(data[1] & 0x80) == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 3 times by 1 test
Evaluated by:
  • bytestringtest
1-15
410 /* Violates smallest encoding rule: excessive leading zeros. */-
411 return 0;
executed 1 time by 1 test: return 0;
Executed by:
  • bytestringtest
1
412-
413 for (i = 0; i < len; i++) {
i < lenDescription
TRUEevaluated 56 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
FALSEevaluated 18 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
18-56
414 if ((*out >> 56) != 0)
(*out >> 56) != 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 55 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
1-55
415 /* Too large to represent as a uint64_t. */-
416 return 0;
executed 1 time by 1 test: return 0;
Executed by:
  • bytestringtest
1
417-
418 *out <<= 8;-
419 *out |= data[i];-
420 }
executed 55 times by 2 tests: end of block
Executed by:
  • asn1test
  • bytestringtest
55
421-
422 return 1;
executed 18 times by 2 tests: return 1;
Executed by:
  • asn1test
  • bytestringtest
18
423}-
424-
425int-
426CBS_get_optional_asn1(CBS *cbs, CBS *out, int *out_present, unsigned int tag)-
427{-
428 if (CBS_peek_asn1_tag(cbs, tag)) {
CBS_peek_asn1_tag(cbs, tag)Description
TRUEevaluated 18 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
FALSEevaluated 22 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
18-22
429 if (!CBS_get_asn1(cbs, out, tag))
!CBS_get_asn1(cbs, out, tag)Description
TRUEnever evaluated
FALSEevaluated 18 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
0-18
430 return 0;
never executed: return 0;
0
431-
432 *out_present = 1;-
433 } else {
executed 18 times by 2 tests: end of block
Executed by:
  • asn1test
  • bytestringtest
18
434 *out_present = 0;-
435 }
executed 22 times by 2 tests: end of block
Executed by:
  • asn1test
  • bytestringtest
22
436 return 1;
executed 40 times by 2 tests: return 1;
Executed by:
  • asn1test
  • bytestringtest
40
437}-
438-
439int-
440CBS_get_optional_asn1_octet_string(CBS *cbs, CBS *out, int *out_present,-
441 unsigned int tag)-
442{-
443 CBS child;-
444 int present;-
445-
446 if (!CBS_get_optional_asn1(cbs, &child, &present, tag))
!CBS_get_optio...&present, tag)Description
TRUEnever evaluated
FALSEevaluated 14 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
0-14
447 return 0;
never executed: return 0;
0
448-
449 if (present) {
presentDescription
TRUEevaluated 7 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
FALSEevaluated 7 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
7
450 if (!CBS_get_asn1(&child, out, CBS_ASN1_OCTETSTRING) ||
!CBS_get_asn1(...| 0x00 | 0x4))Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 6 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
1-6
451 CBS_len(&child) != 0)
CBS_len(&child) != 0Description
TRUEnever evaluated
FALSEevaluated 6 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
0-6
452 return 0;
executed 1 time by 1 test: return 0;
Executed by:
  • bytestringtest
1
453 } else {
executed 6 times by 2 tests: end of block
Executed by:
  • asn1test
  • bytestringtest
6
454 CBS_init(out, NULL, 0);-
455 }
executed 7 times by 2 tests: end of block
Executed by:
  • asn1test
  • bytestringtest
7
456 if (out_present)
out_presentDescription
TRUEevaluated 12 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
FALSEevaluated 1 time by 1 test
Evaluated by:
  • bytestringtest
1-12
457 *out_present = present;
executed 12 times by 2 tests: *out_present = present;
Executed by:
  • asn1test
  • bytestringtest
12
458-
459 return 1;
executed 13 times by 2 tests: return 1;
Executed by:
  • asn1test
  • bytestringtest
13
460}-
461-
462int-
463CBS_get_optional_asn1_uint64(CBS *cbs, uint64_t *out, unsigned int tag,-
464 uint64_t default_value)-
465{-
466 CBS child;-
467 int present;-
468-
469 if (!CBS_get_optional_asn1(cbs, &child, &present, tag))
!CBS_get_optio...&present, tag)Description
TRUEnever evaluated
FALSEevaluated 16 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
0-16
470 return 0;
never executed: return 0;
0
471-
472 if (present) {
presentDescription
TRUEevaluated 6 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
FALSEevaluated 10 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
6-10
473 if (!CBS_get_asn1_uint64(&child, out) ||
!CBS_get_asn1_...4(&child, out)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 5 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
1-5
474 CBS_len(&child) != 0)
CBS_len(&child) != 0Description
TRUEnever evaluated
FALSEevaluated 5 times by 2 tests
Evaluated by:
  • asn1test
  • bytestringtest
0-5
475 return 0;
executed 1 time by 1 test: return 0;
Executed by:
  • bytestringtest
1
476 } else {
executed 5 times by 2 tests: end of block
Executed by:
  • asn1test
  • bytestringtest
5
477 *out = default_value;-
478 }
executed 10 times by 2 tests: end of block
Executed by:
  • asn1test
  • bytestringtest
10
479 return 1;
executed 15 times by 2 tests: return 1;
Executed by:
  • asn1test
  • bytestringtest
15
480}-
481-
482int-
483CBS_get_optional_asn1_bool(CBS *cbs, int *out, unsigned int tag,-
484 int default_value)-
485{-
486 CBS child, child2;-
487 int present;-
488-
489 if (!CBS_get_optional_asn1(cbs, &child, &present, tag))
!CBS_get_optio...&present, tag)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • bytestringtest
0-4
490 return 0;
never executed: return 0;
0
491-
492 if (present) {
presentDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 1 time by 1 test
Evaluated by:
  • bytestringtest
1-3
493 uint8_t boolean;-
494-
495 if (!CBS_get_asn1(&child, &child2, CBS_ASN1_BOOLEAN) ||
!CBS_get_asn1(...| 0x00 | 0x1))Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • bytestringtest
0-3
496 CBS_len(&child2) != 1 || CBS_len(&child) != 0)
CBS_len(&child2) != 1Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • bytestringtest
CBS_len(&child) != 0Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • bytestringtest
0-3
497 return 0;
never executed: return 0;
0
498-
499 boolean = CBS_data(&child2)[0];-
500 if (boolean == 0)
boolean == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 2 times by 1 test
Evaluated by:
  • bytestringtest
1-2
501 *out = 0;
executed 1 time by 1 test: *out = 0;
Executed by:
  • bytestringtest
1
502 else if (boolean == 0xff)
boolean == 0xffDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • bytestringtest
FALSEevaluated 1 time by 1 test
Evaluated by:
  • bytestringtest
1
503 *out = 1;
executed 1 time by 1 test: *out = 1;
Executed by:
  • bytestringtest
1
504 else-
505 return 0;
executed 1 time by 1 test: return 0;
Executed by:
  • bytestringtest
1
506-
507 } else {-
508 *out = default_value;-
509 }
executed 1 time by 1 test: end of block
Executed by:
  • bytestringtest
1
510 return 1;
executed 3 times by 1 test: return 1;
Executed by:
  • bytestringtest
3
511}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2