Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/ssl/packet.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* | - | ||||||||||||||||||
2 | * Copyright 2015-2018 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 "internal/cryptlib.h" | - | ||||||||||||||||||
11 | #include "packet_locl.h" | - | ||||||||||||||||||
12 | #include <openssl/sslerr.h> | - | ||||||||||||||||||
13 | - | |||||||||||||||||||
14 | #define DEFAULT_BUF_SIZE 256 | - | ||||||||||||||||||
15 | - | |||||||||||||||||||
16 | int WPACKET_allocate_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes) | - | ||||||||||||||||||
17 | { | - | ||||||||||||||||||
18 | if (!WPACKET_reserve_bytes(pkt, len, allocbytes))
| 5-1301556 | ||||||||||||||||||
19 | return 0; executed 5 times by 1 test: return 0; Executed by:
| 5 | ||||||||||||||||||
20 | - | |||||||||||||||||||
21 | pkt->written += len; | - | ||||||||||||||||||
22 | pkt->curr += len; | - | ||||||||||||||||||
23 | return 1; executed 1301556 times by 4 tests: return 1; Executed by:
| 1301556 | ||||||||||||||||||
24 | } | - | ||||||||||||||||||
25 | - | |||||||||||||||||||
26 | int WPACKET_sub_allocate_bytes__(WPACKET *pkt, size_t len, | - | ||||||||||||||||||
27 | unsigned char **allocbytes, size_t lenbytes) | - | ||||||||||||||||||
28 | { | - | ||||||||||||||||||
29 | if (!WPACKET_start_sub_packet_len__(pkt, lenbytes)
| 0-3776 | ||||||||||||||||||
30 | || !WPACKET_allocate_bytes(pkt, len, allocbytes)
| 0-3776 | ||||||||||||||||||
31 | || !WPACKET_close(pkt))
| 0-3776 | ||||||||||||||||||
32 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
33 | - | |||||||||||||||||||
34 | return 1; executed 3776 times by 2 tests: return 1; Executed by:
| 3776 | ||||||||||||||||||
35 | } | - | ||||||||||||||||||
36 | - | |||||||||||||||||||
37 | #define GETBUF(p) (((p)->staticbuf != NULL) \ | - | ||||||||||||||||||
38 | ? (p)->staticbuf : (unsigned char *)(p)->buf->data) | - | ||||||||||||||||||
39 | - | |||||||||||||||||||
40 | int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes) | - | ||||||||||||||||||
41 | { | - | ||||||||||||||||||
42 | /* Internal API, so should not fail */ | - | ||||||||||||||||||
43 | if (!ossl_assert(pkt->subs != NULL && len != 0))
| 0-1387935 | ||||||||||||||||||
44 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
45 | - | |||||||||||||||||||
46 | if (pkt->maxsize - pkt->written < len)
| 5-1387930 | ||||||||||||||||||
47 | return 0; executed 5 times by 1 test: return 0; Executed by:
| 5 | ||||||||||||||||||
48 | - | |||||||||||||||||||
49 | if (pkt->staticbuf == NULL && (pkt->buf->length - pkt->written < len)) {
| 5527-803507 | ||||||||||||||||||
50 | size_t newlen; | - | ||||||||||||||||||
51 | size_t reflen; | - | ||||||||||||||||||
52 | - | |||||||||||||||||||
53 | reflen = (len > pkt->buf->length) ? len : pkt->buf->length;
| 2178-3349 | ||||||||||||||||||
54 | - | |||||||||||||||||||
55 | if (reflen > SIZE_MAX / 2) {
| 0-5527 | ||||||||||||||||||
56 | newlen = SIZE_MAX; | - | ||||||||||||||||||
57 | } else { never executed: end of block | 0 | ||||||||||||||||||
58 | newlen = reflen * 2; | - | ||||||||||||||||||
59 | if (newlen < DEFAULT_BUF_SIZE)
| 2362-3165 | ||||||||||||||||||
60 | newlen = DEFAULT_BUF_SIZE; executed 2362 times by 2 tests: newlen = 256; Executed by:
| 2362 | ||||||||||||||||||
61 | } executed 5527 times by 2 tests: end of block Executed by:
| 5527 | ||||||||||||||||||
62 | if (BUF_MEM_grow(pkt->buf, newlen) == 0)
| 0-5527 | ||||||||||||||||||
63 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
64 | } executed 5527 times by 2 tests: end of block Executed by:
| 5527 | ||||||||||||||||||
65 | if (allocbytes != NULL)
| 108484-1279446 | ||||||||||||||||||
66 | *allocbytes = WPACKET_get_curr(pkt); executed 1279446 times by 4 tests: *allocbytes = WPACKET_get_curr(pkt); Executed by:
| 1279446 | ||||||||||||||||||
67 | - | |||||||||||||||||||
68 | return 1; executed 1387930 times by 4 tests: return 1; Executed by:
| 1387930 | ||||||||||||||||||
69 | } | - | ||||||||||||||||||
70 | - | |||||||||||||||||||
71 | int WPACKET_sub_reserve_bytes__(WPACKET *pkt, size_t len, | - | ||||||||||||||||||
72 | unsigned char **allocbytes, size_t lenbytes) | - | ||||||||||||||||||
73 | { | - | ||||||||||||||||||
74 | if (!WPACKET_reserve_bytes(pkt, lenbytes + len, allocbytes))
| 0-1114 | ||||||||||||||||||
75 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
76 | - | |||||||||||||||||||
77 | *allocbytes += lenbytes; | - | ||||||||||||||||||
78 | - | |||||||||||||||||||
79 | return 1; executed 1114 times by 1 test: return 1; Executed by:
| 1114 | ||||||||||||||||||
80 | } | - | ||||||||||||||||||
81 | - | |||||||||||||||||||
82 | static size_t maxmaxsize(size_t lenbytes) | - | ||||||||||||||||||
83 | { | - | ||||||||||||||||||
84 | if (lenbytes >= sizeof(size_t) || lenbytes == 0)
| 16-128620 | ||||||||||||||||||
85 | return SIZE_MAX; executed 133599 times by 4 tests: return (18446744073709551615UL) ; Executed by:
| 133599 | ||||||||||||||||||
86 | - | |||||||||||||||||||
87 | return ((size_t)1 << (lenbytes * 8)) - 1 + lenbytes; executed 16 times by 1 test: return ((size_t)1 << (lenbytes * 8)) - 1 + lenbytes; Executed by:
| 16 | ||||||||||||||||||
88 | } | - | ||||||||||||||||||
89 | - | |||||||||||||||||||
90 | static int wpacket_intern_init_len(WPACKET *pkt, size_t lenbytes) | - | ||||||||||||||||||
91 | { | - | ||||||||||||||||||
92 | unsigned char *lenchars; | - | ||||||||||||||||||
93 | - | |||||||||||||||||||
94 | pkt->curr = 0; | - | ||||||||||||||||||
95 | pkt->written = 0; | - | ||||||||||||||||||
96 | - | |||||||||||||||||||
97 | if ((pkt->subs = OPENSSL_zalloc(sizeof(*pkt->subs))) == NULL) {
| 0-128615 | ||||||||||||||||||
98 | SSLerr(SSL_F_WPACKET_INTERN_INIT_LEN, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||
99 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
100 | } | - | ||||||||||||||||||
101 | - | |||||||||||||||||||
102 | if (lenbytes == 0)
| 11-128604 | ||||||||||||||||||
103 | return 1; executed 128604 times by 4 tests: return 1; Executed by:
| 128604 | ||||||||||||||||||
104 | - | |||||||||||||||||||
105 | pkt->subs->pwritten = lenbytes; | - | ||||||||||||||||||
106 | pkt->subs->lenbytes = lenbytes; | - | ||||||||||||||||||
107 | - | |||||||||||||||||||
108 | if (!WPACKET_allocate_bytes(pkt, lenbytes, &lenchars)) {
| 0-11 | ||||||||||||||||||
109 | OPENSSL_free(pkt->subs); | - | ||||||||||||||||||
110 | pkt->subs = NULL; | - | ||||||||||||||||||
111 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
112 | } | - | ||||||||||||||||||
113 | pkt->subs->packet_len = lenchars - GETBUF(pkt);
| 1-10 | ||||||||||||||||||
114 | - | |||||||||||||||||||
115 | return 1; executed 11 times by 1 test: return 1; Executed by:
| 11 | ||||||||||||||||||
116 | } | - | ||||||||||||||||||
117 | - | |||||||||||||||||||
118 | int WPACKET_init_static_len(WPACKET *pkt, unsigned char *buf, size_t len, | - | ||||||||||||||||||
119 | size_t lenbytes) | - | ||||||||||||||||||
120 | { | - | ||||||||||||||||||
121 | size_t max = maxmaxsize(lenbytes); | - | ||||||||||||||||||
122 | - | |||||||||||||||||||
123 | /* Internal API, so should not fail */ | - | ||||||||||||||||||
124 | if (!ossl_assert(buf != NULL && len > 0))
| 0-102574 | ||||||||||||||||||
125 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
126 | - | |||||||||||||||||||
127 | pkt->staticbuf = buf; | - | ||||||||||||||||||
128 | pkt->buf = NULL; | - | ||||||||||||||||||
129 | pkt->maxsize = (max < len) ? max : len;
| 0-102574 | ||||||||||||||||||
130 | - | |||||||||||||||||||
131 | return wpacket_intern_init_len(pkt, lenbytes); executed 102574 times by 4 tests: return wpacket_intern_init_len(pkt, lenbytes); Executed by:
| 102574 | ||||||||||||||||||
132 | } | - | ||||||||||||||||||
133 | - | |||||||||||||||||||
134 | int WPACKET_init_len(WPACKET *pkt, BUF_MEM *buf, size_t lenbytes) | - | ||||||||||||||||||
135 | { | - | ||||||||||||||||||
136 | /* Internal API, so should not fail */ | - | ||||||||||||||||||
137 | if (!ossl_assert(buf != NULL))
| 0-26041 | ||||||||||||||||||
138 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
139 | - | |||||||||||||||||||
140 | pkt->staticbuf = NULL; | - | ||||||||||||||||||
141 | pkt->buf = buf; | - | ||||||||||||||||||
142 | pkt->maxsize = maxmaxsize(lenbytes); | - | ||||||||||||||||||
143 | - | |||||||||||||||||||
144 | return wpacket_intern_init_len(pkt, lenbytes); executed 26041 times by 2 tests: return wpacket_intern_init_len(pkt, lenbytes); Executed by:
| 26041 | ||||||||||||||||||
145 | } | - | ||||||||||||||||||
146 | - | |||||||||||||||||||
147 | int WPACKET_init(WPACKET *pkt, BUF_MEM *buf) | - | ||||||||||||||||||
148 | { | - | ||||||||||||||||||
149 | return WPACKET_init_len(pkt, buf, 0); executed 26031 times by 2 tests: return WPACKET_init_len(pkt, buf, 0); Executed by:
| 26031 | ||||||||||||||||||
150 | } | - | ||||||||||||||||||
151 | - | |||||||||||||||||||
152 | int WPACKET_set_flags(WPACKET *pkt, unsigned int flags) | - | ||||||||||||||||||
153 | { | - | ||||||||||||||||||
154 | /* Internal API, so should not fail */ | - | ||||||||||||||||||
155 | if (!ossl_assert(pkt->subs != NULL))
| 0-6485 | ||||||||||||||||||
156 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
157 | - | |||||||||||||||||||
158 | pkt->subs->flags = flags; | - | ||||||||||||||||||
159 | - | |||||||||||||||||||
160 | return 1; executed 6485 times by 2 tests: return 1; Executed by:
| 6485 | ||||||||||||||||||
161 | } | - | ||||||||||||||||||
162 | - | |||||||||||||||||||
163 | /* Store the |value| of length |len| at location |data| */ | - | ||||||||||||||||||
164 | static int put_value(unsigned char *data, size_t value, size_t len) | - | ||||||||||||||||||
165 | { | - | ||||||||||||||||||
166 | for (data += len - 1; len > 0; len--) {
| 1069608-1953018 | ||||||||||||||||||
167 | *data = (unsigned char)(value & 0xff); | - | ||||||||||||||||||
168 | data--; | - | ||||||||||||||||||
169 | value >>= 8; | - | ||||||||||||||||||
170 | } executed 1953018 times by 4 tests: end of block Executed by:
| 1953018 | ||||||||||||||||||
171 | - | |||||||||||||||||||
172 | /* Check whether we could fit the value in the assigned number of bytes */ | - | ||||||||||||||||||
173 | if (value > 0)
| 0-1069608 | ||||||||||||||||||
174 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
175 | - | |||||||||||||||||||
176 | return 1; executed 1069608 times by 4 tests: return 1; Executed by:
| 1069608 | ||||||||||||||||||
177 | } | - | ||||||||||||||||||
178 | - | |||||||||||||||||||
179 | - | |||||||||||||||||||
180 | /* | - | ||||||||||||||||||
181 | * Internal helper function used by WPACKET_close(), WPACKET_finish() and | - | ||||||||||||||||||
182 | * WPACKET_fill_lengths() to close a sub-packet and write out its length if | - | ||||||||||||||||||
183 | * necessary. If |doclose| is 0 then it goes through the motions of closing | - | ||||||||||||||||||
184 | * (i.e. it fills in all the lengths), but doesn't actually close anything. | - | ||||||||||||||||||
185 | */ | - | ||||||||||||||||||
186 | static int wpacket_intern_close(WPACKET *pkt, WPACKET_SUB *sub, int doclose) | - | ||||||||||||||||||
187 | { | - | ||||||||||||||||||
188 | size_t packlen = pkt->written - sub->pwritten; | - | ||||||||||||||||||
189 | - | |||||||||||||||||||
190 | if (packlen == 0
| 27343-339922 | ||||||||||||||||||
191 | && (sub->flags & WPACKET_FLAGS_NON_ZERO_LENGTH) != 0)
| 2-27341 | ||||||||||||||||||
192 | return 0; executed 2 times by 1 test: return 0; Executed by:
| 2 | ||||||||||||||||||
193 | - | |||||||||||||||||||
194 | if (packlen == 0
| 27341-339922 | ||||||||||||||||||
195 | && sub->flags & WPACKET_FLAGS_ABANDON_ON_ZERO_LENGTH) {
| 74-27267 | ||||||||||||||||||
196 | /* We can't handle this case. Return an error */ | - | ||||||||||||||||||
197 | if (!doclose)
| 0-74 | ||||||||||||||||||
198 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
199 | - | |||||||||||||||||||
200 | /* Deallocate any bytes allocated for the length of the WPACKET */ | - | ||||||||||||||||||
201 | if ((pkt->curr - sub->lenbytes) == sub->packet_len) {
| 0-74 | ||||||||||||||||||
202 | pkt->written -= sub->lenbytes; | - | ||||||||||||||||||
203 | pkt->curr -= sub->lenbytes; | - | ||||||||||||||||||
204 | } executed 74 times by 2 tests: end of block Executed by:
| 74 | ||||||||||||||||||
205 | - | |||||||||||||||||||
206 | /* Don't write out the packet length */ | - | ||||||||||||||||||
207 | sub->packet_len = 0; | - | ||||||||||||||||||
208 | sub->lenbytes = 0; | - | ||||||||||||||||||
209 | } executed 74 times by 2 tests: end of block Executed by:
| 74 | ||||||||||||||||||
210 | - | |||||||||||||||||||
211 | /* Write out the WPACKET length if needed */ | - | ||||||||||||||||||
212 | if (sub->lenbytes > 0
| 130293-236970 | ||||||||||||||||||
213 | && !put_value(&GETBUF(pkt)[sub->packet_len], packlen,
| 0-236970 | ||||||||||||||||||
214 | sub->lenbytes))
| 0-236970 | ||||||||||||||||||
215 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
216 | - | |||||||||||||||||||
217 | if (doclose) {
| 520-366743 | ||||||||||||||||||
218 | pkt->subs = sub->parent; | - | ||||||||||||||||||
219 | OPENSSL_free(sub); | - | ||||||||||||||||||
220 | } executed 366743 times by 4 tests: end of block Executed by:
| 366743 | ||||||||||||||||||
221 | - | |||||||||||||||||||
222 | return 1; executed 367263 times by 4 tests: return 1; Executed by:
| 367263 | ||||||||||||||||||
223 | } | - | ||||||||||||||||||
224 | - | |||||||||||||||||||
225 | int WPACKET_fill_lengths(WPACKET *pkt) | - | ||||||||||||||||||
226 | { | - | ||||||||||||||||||
227 | WPACKET_SUB *sub; | - | ||||||||||||||||||
228 | - | |||||||||||||||||||
229 | if (!ossl_assert(pkt->subs != NULL))
| 0-174 | ||||||||||||||||||
230 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
231 | - | |||||||||||||||||||
232 | for (sub = pkt->subs; sub != NULL; sub = sub->parent) {
| 174-520 | ||||||||||||||||||
233 | if (!wpacket_intern_close(pkt, sub, 0))
| 0-520 | ||||||||||||||||||
234 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
235 | } executed 520 times by 2 tests: end of block Executed by:
| 520 | ||||||||||||||||||
236 | - | |||||||||||||||||||
237 | return 1; executed 174 times by 2 tests: return 1; Executed by:
| 174 | ||||||||||||||||||
238 | } | - | ||||||||||||||||||
239 | - | |||||||||||||||||||
240 | int WPACKET_close(WPACKET *pkt) | - | ||||||||||||||||||
241 | { | - | ||||||||||||||||||
242 | /* | - | ||||||||||||||||||
243 | * Internal API, so should not fail - but we do negative testing of this | - | ||||||||||||||||||
244 | * so no assert (otherwise the tests fail) | - | ||||||||||||||||||
245 | */ | - | ||||||||||||||||||
246 | if (pkt->subs == NULL || pkt->subs->parent == NULL)
| 1-238224 | ||||||||||||||||||
247 | return 0; executed 3 times by 1 test: return 0; Executed by:
| 3 | ||||||||||||||||||
248 | - | |||||||||||||||||||
249 | return wpacket_intern_close(pkt, pkt->subs, 1); executed 238222 times by 3 tests: return wpacket_intern_close(pkt, pkt->subs, 1); Executed by:
| 238222 | ||||||||||||||||||
250 | } | - | ||||||||||||||||||
251 | - | |||||||||||||||||||
252 | int WPACKET_finish(WPACKET *pkt) | - | ||||||||||||||||||
253 | { | - | ||||||||||||||||||
254 | int ret; | - | ||||||||||||||||||
255 | - | |||||||||||||||||||
256 | /* | - | ||||||||||||||||||
257 | * Internal API, so should not fail - but we do negative testing of this | - | ||||||||||||||||||
258 | * so no assert (otherwise the tests fail) | - | ||||||||||||||||||
259 | */ | - | ||||||||||||||||||
260 | if (pkt->subs == NULL || pkt->subs->parent != NULL)
| 1-128524 | ||||||||||||||||||
261 | return 0; executed 2 times by 1 test: return 0; Executed by:
| 2 | ||||||||||||||||||
262 | - | |||||||||||||||||||
263 | ret = wpacket_intern_close(pkt, pkt->subs, 1); | - | ||||||||||||||||||
264 | if (ret) {
| 1-128522 | ||||||||||||||||||
265 | OPENSSL_free(pkt->subs); | - | ||||||||||||||||||
266 | pkt->subs = NULL; | - | ||||||||||||||||||
267 | } executed 128522 times by 4 tests: end of block Executed by:
| 128522 | ||||||||||||||||||
268 | - | |||||||||||||||||||
269 | return ret; executed 128523 times by 4 tests: return ret; Executed by:
| 128523 | ||||||||||||||||||
270 | } | - | ||||||||||||||||||
271 | - | |||||||||||||||||||
272 | int WPACKET_start_sub_packet_len__(WPACKET *pkt, size_t lenbytes) | - | ||||||||||||||||||
273 | { | - | ||||||||||||||||||
274 | WPACKET_SUB *sub; | - | ||||||||||||||||||
275 | unsigned char *lenchars; | - | ||||||||||||||||||
276 | - | |||||||||||||||||||
277 | /* Internal API, so should not fail */ | - | ||||||||||||||||||
278 | if (!ossl_assert(pkt->subs != NULL))
| 0-238342 | ||||||||||||||||||
279 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
280 | - | |||||||||||||||||||
281 | if ((sub = OPENSSL_zalloc(sizeof(*sub))) == NULL) {
| 0-238342 | ||||||||||||||||||
282 | SSLerr(SSL_F_WPACKET_START_SUB_PACKET_LEN__, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||
283 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
284 | } | - | ||||||||||||||||||
285 | - | |||||||||||||||||||
286 | sub->parent = pkt->subs; | - | ||||||||||||||||||
287 | pkt->subs = sub; | - | ||||||||||||||||||
288 | sub->pwritten = pkt->written + lenbytes; | - | ||||||||||||||||||
289 | sub->lenbytes = lenbytes; | - | ||||||||||||||||||
290 | - | |||||||||||||||||||
291 | if (lenbytes == 0) {
| 1534-236808 | ||||||||||||||||||
292 | sub->packet_len = 0; | - | ||||||||||||||||||
293 | return 1; executed 1534 times by 2 tests: return 1; Executed by:
| 1534 | ||||||||||||||||||
294 | } | - | ||||||||||||||||||
295 | - | |||||||||||||||||||
296 | if (!WPACKET_allocate_bytes(pkt, lenbytes, &lenchars))
| 0-236808 | ||||||||||||||||||
297 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
298 | /* Convert to an offset in case the underlying BUF_MEM gets realloc'd */ | - | ||||||||||||||||||
299 | sub->packet_len = lenchars - GETBUF(pkt);
| 96579-140229 | ||||||||||||||||||
300 | - | |||||||||||||||||||
301 | return 1; executed 236808 times by 3 tests: return 1; Executed by:
| 236808 | ||||||||||||||||||
302 | } | - | ||||||||||||||||||
303 | - | |||||||||||||||||||
304 | int WPACKET_start_sub_packet(WPACKET *pkt) | - | ||||||||||||||||||
305 | { | - | ||||||||||||||||||
306 | return WPACKET_start_sub_packet_len__(pkt, 0); executed 1534 times by 2 tests: return WPACKET_start_sub_packet_len__(pkt, 0); Executed by:
| 1534 | ||||||||||||||||||
307 | } | - | ||||||||||||||||||
308 | - | |||||||||||||||||||
309 | int WPACKET_put_bytes__(WPACKET *pkt, unsigned int val, size_t size) | - | ||||||||||||||||||
310 | { | - | ||||||||||||||||||
311 | unsigned char *data; | - | ||||||||||||||||||
312 | - | |||||||||||||||||||
313 | /* Internal API, so should not fail */ | - | ||||||||||||||||||
314 | if (!ossl_assert(size <= sizeof(unsigned int))
| 0-832643 | ||||||||||||||||||
315 | || !WPACKET_allocate_bytes(pkt, size, &data)
| 5-832638 | ||||||||||||||||||
316 | || !put_value(data, val, size))
| 0-832638 | ||||||||||||||||||
317 | return 0; executed 5 times by 1 test: return 0; Executed by:
| 5 | ||||||||||||||||||
318 | - | |||||||||||||||||||
319 | return 1; executed 832638 times by 4 tests: return 1; Executed by:
| 832638 | ||||||||||||||||||
320 | } | - | ||||||||||||||||||
321 | - | |||||||||||||||||||
322 | int WPACKET_set_max_size(WPACKET *pkt, size_t maxsize) | - | ||||||||||||||||||
323 | { | - | ||||||||||||||||||
324 | WPACKET_SUB *sub; | - | ||||||||||||||||||
325 | size_t lenbytes; | - | ||||||||||||||||||
326 | - | |||||||||||||||||||
327 | /* Internal API, so should not fail */ | - | ||||||||||||||||||
328 | if (!ossl_assert(pkt->subs != NULL))
| 0-5000 | ||||||||||||||||||
329 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
330 | - | |||||||||||||||||||
331 | /* Find the WPACKET_SUB for the top level */ | - | ||||||||||||||||||
332 | for (sub = pkt->subs; sub->parent != NULL; sub = sub->parent)
| 4992-5000 | ||||||||||||||||||
333 | continue; executed 4992 times by 1 test: continue; Executed by:
| 4992 | ||||||||||||||||||
334 | - | |||||||||||||||||||
335 | lenbytes = sub->lenbytes; | - | ||||||||||||||||||
336 | if (lenbytes == 0)
| 5-4995 | ||||||||||||||||||
337 | lenbytes = sizeof(pkt->maxsize); executed 4995 times by 2 tests: lenbytes = sizeof(pkt->maxsize); Executed by:
| 4995 | ||||||||||||||||||
338 | - | |||||||||||||||||||
339 | if (maxmaxsize(lenbytes) < maxsize || maxsize < pkt->written)
| 1-4999 | ||||||||||||||||||
340 | return 0; executed 2 times by 1 test: return 0; Executed by:
| 2 | ||||||||||||||||||
341 | - | |||||||||||||||||||
342 | pkt->maxsize = maxsize; | - | ||||||||||||||||||
343 | - | |||||||||||||||||||
344 | return 1; executed 4998 times by 2 tests: return 1; Executed by:
| 4998 | ||||||||||||||||||
345 | } | - | ||||||||||||||||||
346 | - | |||||||||||||||||||
347 | int WPACKET_memset(WPACKET *pkt, int ch, size_t len) | - | ||||||||||||||||||
348 | { | - | ||||||||||||||||||
349 | unsigned char *dest; | - | ||||||||||||||||||
350 | - | |||||||||||||||||||
351 | if (len == 0)
| 0-11 | ||||||||||||||||||
352 | return 1; never executed: return 1; | 0 | ||||||||||||||||||
353 | - | |||||||||||||||||||
354 | if (!WPACKET_allocate_bytes(pkt, len, &dest))
| 0-11 | ||||||||||||||||||
355 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
356 | - | |||||||||||||||||||
357 | memset(dest, ch, len); | - | ||||||||||||||||||
358 | - | |||||||||||||||||||
359 | return 1; executed 11 times by 1 test: return 1; Executed by:
| 11 | ||||||||||||||||||
360 | } | - | ||||||||||||||||||
361 | - | |||||||||||||||||||
362 | int WPACKET_memcpy(WPACKET *pkt, const void *src, size_t len) | - | ||||||||||||||||||
363 | { | - | ||||||||||||||||||
364 | unsigned char *dest; | - | ||||||||||||||||||
365 | - | |||||||||||||||||||
366 | if (len == 0)
| 23885-147944 | ||||||||||||||||||
367 | return 1; executed 23885 times by 2 tests: return 1; Executed by:
| 23885 | ||||||||||||||||||
368 | - | |||||||||||||||||||
369 | if (!WPACKET_allocate_bytes(pkt, len, &dest))
| 0-147944 | ||||||||||||||||||
370 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
371 | - | |||||||||||||||||||
372 | memcpy(dest, src, len); | - | ||||||||||||||||||
373 | - | |||||||||||||||||||
374 | return 1; executed 147944 times by 3 tests: return 1; Executed by:
| 147944 | ||||||||||||||||||
375 | } | - | ||||||||||||||||||
376 | - | |||||||||||||||||||
377 | int WPACKET_sub_memcpy__(WPACKET *pkt, const void *src, size_t len, | - | ||||||||||||||||||
378 | size_t lenbytes) | - | ||||||||||||||||||
379 | { | - | ||||||||||||||||||
380 | if (!WPACKET_start_sub_packet_len__(pkt, lenbytes)
| 0-53436 | ||||||||||||||||||
381 | || !WPACKET_memcpy(pkt, src, len)
| 0-53436 | ||||||||||||||||||
382 | || !WPACKET_close(pkt))
| 0-53436 | ||||||||||||||||||
383 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
384 | - | |||||||||||||||||||
385 | return 1; executed 53436 times by 3 tests: return 1; Executed by:
| 53436 | ||||||||||||||||||
386 | } | - | ||||||||||||||||||
387 | - | |||||||||||||||||||
388 | int WPACKET_get_total_written(WPACKET *pkt, size_t *written) | - | ||||||||||||||||||
389 | { | - | ||||||||||||||||||
390 | /* Internal API, so should not fail */ | - | ||||||||||||||||||
391 | if (!ossl_assert(written != NULL))
| 0-66553 | ||||||||||||||||||
392 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
393 | - | |||||||||||||||||||
394 | *written = pkt->written; | - | ||||||||||||||||||
395 | - | |||||||||||||||||||
396 | return 1; executed 66553 times by 4 tests: return 1; Executed by:
| 66553 | ||||||||||||||||||
397 | } | - | ||||||||||||||||||
398 | - | |||||||||||||||||||
399 | int WPACKET_get_length(WPACKET *pkt, size_t *len) | - | ||||||||||||||||||
400 | { | - | ||||||||||||||||||
401 | /* Internal API, so should not fail */ | - | ||||||||||||||||||
402 | if (!ossl_assert(pkt->subs != NULL && len != NULL))
| 0-150196 | ||||||||||||||||||
403 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
404 | - | |||||||||||||||||||
405 | *len = pkt->written - pkt->subs->pwritten; | - | ||||||||||||||||||
406 | - | |||||||||||||||||||
407 | return 1; executed 150196 times by 2 tests: return 1; Executed by:
| 150196 | ||||||||||||||||||
408 | } | - | ||||||||||||||||||
409 | - | |||||||||||||||||||
410 | unsigned char *WPACKET_get_curr(WPACKET *pkt) | - | ||||||||||||||||||
411 | { | - | ||||||||||||||||||
412 | return GETBUF(pkt) + pkt->curr; executed 1320670 times by 4 tests: return (((pkt)->staticbuf != ((void *)0) ) ? (pkt)->staticbuf : (unsigned char *)(pkt)->buf->data) + pkt->curr; Executed by:
| 516990-1320670 | ||||||||||||||||||
413 | } | - | ||||||||||||||||||
414 | - | |||||||||||||||||||
415 | void WPACKET_cleanup(WPACKET *pkt) | - | ||||||||||||||||||
416 | { | - | ||||||||||||||||||
417 | WPACKET_SUB *sub, *parent; | - | ||||||||||||||||||
418 | - | |||||||||||||||||||
419 | for (sub = pkt->subs; sub != NULL; sub = parent) {
| 93-214 | ||||||||||||||||||
420 | parent = sub->parent; | - | ||||||||||||||||||
421 | OPENSSL_free(sub); | - | ||||||||||||||||||
422 | } executed 214 times by 1 test: end of block Executed by:
| 214 | ||||||||||||||||||
423 | pkt->subs = NULL; | - | ||||||||||||||||||
424 | } executed 93 times by 1 test: end of block Executed by:
| 93 | ||||||||||||||||||
Source code | Switch to Preprocessed file |