Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/bio/bf_buff.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* $OpenBSD: bf_buff.c,v 1.25 2018/05/01 13:29:09 tb Exp $ */ | - | ||||||||||||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | - | ||||||||||||
3 | * All rights reserved. | - | ||||||||||||
4 | * | - | ||||||||||||
5 | * This package is an SSL implementation written | - | ||||||||||||
6 | * by Eric Young (eay@cryptsoft.com). | - | ||||||||||||
7 | * The implementation was written so as to conform with Netscapes SSL. | - | ||||||||||||
8 | * | - | ||||||||||||
9 | * This library is free for commercial and non-commercial use as long as | - | ||||||||||||
10 | * the following conditions are aheared to. The following conditions | - | ||||||||||||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | - | ||||||||||||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | - | ||||||||||||
13 | * included with this distribution is covered by the same copyright terms | - | ||||||||||||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | - | ||||||||||||
15 | * | - | ||||||||||||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | - | ||||||||||||
17 | * the code are not to be removed. | - | ||||||||||||
18 | * If this package is used in a product, Eric Young should be given attribution | - | ||||||||||||
19 | * as the author of the parts of the library used. | - | ||||||||||||
20 | * This can be in the form of a textual message at program startup or | - | ||||||||||||
21 | * in documentation (online or textual) provided with the package. | - | ||||||||||||
22 | * | - | ||||||||||||
23 | * Redistribution and use in source and binary forms, with or without | - | ||||||||||||
24 | * modification, are permitted provided that the following conditions | - | ||||||||||||
25 | * are met: | - | ||||||||||||
26 | * 1. Redistributions of source code must retain the copyright | - | ||||||||||||
27 | * notice, this list of conditions and the following disclaimer. | - | ||||||||||||
28 | * 2. Redistributions in binary form must reproduce the above copyright | - | ||||||||||||
29 | * notice, this list of conditions and the following disclaimer in the | - | ||||||||||||
30 | * documentation and/or other materials provided with the distribution. | - | ||||||||||||
31 | * 3. All advertising materials mentioning features or use of this software | - | ||||||||||||
32 | * must display the following acknowledgement: | - | ||||||||||||
33 | * "This product includes cryptographic software written by | - | ||||||||||||
34 | * Eric Young (eay@cryptsoft.com)" | - | ||||||||||||
35 | * The word 'cryptographic' can be left out if the rouines from the library | - | ||||||||||||
36 | * being used are not cryptographic related :-). | - | ||||||||||||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | - | ||||||||||||
38 | * the apps directory (application code) you must include an acknowledgement: | - | ||||||||||||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | - | ||||||||||||
40 | * | - | ||||||||||||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | - | ||||||||||||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | - | ||||||||||||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | - | ||||||||||||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | - | ||||||||||||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | - | ||||||||||||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | - | ||||||||||||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | - | ||||||||||||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | - | ||||||||||||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | - | ||||||||||||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | - | ||||||||||||
51 | * SUCH DAMAGE. | - | ||||||||||||
52 | * | - | ||||||||||||
53 | * The licence and distribution terms for any publically available version or | - | ||||||||||||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | - | ||||||||||||
55 | * copied and put under another distribution licence | - | ||||||||||||
56 | * [including the GNU Public Licence.] | - | ||||||||||||
57 | */ | - | ||||||||||||
58 | - | |||||||||||||
59 | #include <errno.h> | - | ||||||||||||
60 | #include <stdio.h> | - | ||||||||||||
61 | #include <string.h> | - | ||||||||||||
62 | - | |||||||||||||
63 | #include <openssl/bio.h> | - | ||||||||||||
64 | #include <openssl/err.h> | - | ||||||||||||
65 | - | |||||||||||||
66 | static int buffer_write(BIO *h, const char *buf, int num); | - | ||||||||||||
67 | static int buffer_read(BIO *h, char *buf, int size); | - | ||||||||||||
68 | static int buffer_puts(BIO *h, const char *str); | - | ||||||||||||
69 | static int buffer_gets(BIO *h, char *str, int size); | - | ||||||||||||
70 | static long buffer_ctrl(BIO *h, int cmd, long arg1, void *arg2); | - | ||||||||||||
71 | static int buffer_new(BIO *h); | - | ||||||||||||
72 | static int buffer_free(BIO *data); | - | ||||||||||||
73 | static long buffer_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); | - | ||||||||||||
74 | #define DEFAULT_BUFFER_SIZE 4096 | - | ||||||||||||
75 | - | |||||||||||||
76 | static const BIO_METHOD methods_buffer = { | - | ||||||||||||
77 | .type = BIO_TYPE_BUFFER, | - | ||||||||||||
78 | .name = "buffer", | - | ||||||||||||
79 | .bwrite = buffer_write, | - | ||||||||||||
80 | .bread = buffer_read, | - | ||||||||||||
81 | .bputs = buffer_puts, | - | ||||||||||||
82 | .bgets = buffer_gets, | - | ||||||||||||
83 | .ctrl = buffer_ctrl, | - | ||||||||||||
84 | .create = buffer_new, | - | ||||||||||||
85 | .destroy = buffer_free, | - | ||||||||||||
86 | .callback_ctrl = buffer_callback_ctrl | - | ||||||||||||
87 | }; | - | ||||||||||||
88 | - | |||||||||||||
89 | const BIO_METHOD * | - | ||||||||||||
90 | BIO_f_buffer(void) | - | ||||||||||||
91 | { | - | ||||||||||||
92 | return (&methods_buffer); executed 142 times by 5 tests: return (&methods_buffer); Executed by:
| 142 | ||||||||||||
93 | } | - | ||||||||||||
94 | - | |||||||||||||
95 | static int | - | ||||||||||||
96 | buffer_new(BIO *bi) | - | ||||||||||||
97 | { | - | ||||||||||||
98 | BIO_F_BUFFER_CTX *ctx; | - | ||||||||||||
99 | - | |||||||||||||
100 | ctx = malloc(sizeof(BIO_F_BUFFER_CTX)); | - | ||||||||||||
101 | if (ctx == NULL)
| 0-142 | ||||||||||||
102 | return (0); never executed: return (0); | 0 | ||||||||||||
103 | ctx->ibuf = malloc(DEFAULT_BUFFER_SIZE); | - | ||||||||||||
104 | if (ctx->ibuf == NULL) {
| 0-142 | ||||||||||||
105 | free(ctx); | - | ||||||||||||
106 | return (0); never executed: return (0); | 0 | ||||||||||||
107 | } | - | ||||||||||||
108 | ctx->obuf = malloc(DEFAULT_BUFFER_SIZE); | - | ||||||||||||
109 | if (ctx->obuf == NULL) {
| 0-142 | ||||||||||||
110 | free(ctx->ibuf); | - | ||||||||||||
111 | free(ctx); | - | ||||||||||||
112 | return (0); never executed: return (0); | 0 | ||||||||||||
113 | } | - | ||||||||||||
114 | ctx->ibuf_size = DEFAULT_BUFFER_SIZE; | - | ||||||||||||
115 | ctx->obuf_size = DEFAULT_BUFFER_SIZE; | - | ||||||||||||
116 | ctx->ibuf_len = 0; | - | ||||||||||||
117 | ctx->ibuf_off = 0; | - | ||||||||||||
118 | ctx->obuf_len = 0; | - | ||||||||||||
119 | ctx->obuf_off = 0; | - | ||||||||||||
120 | - | |||||||||||||
121 | bi->init = 1; | - | ||||||||||||
122 | bi->ptr = (char *)ctx; | - | ||||||||||||
123 | bi->flags = 0; | - | ||||||||||||
124 | return (1); executed 142 times by 5 tests: return (1); Executed by:
| 142 | ||||||||||||
125 | } | - | ||||||||||||
126 | - | |||||||||||||
127 | static int | - | ||||||||||||
128 | buffer_free(BIO *a) | - | ||||||||||||
129 | { | - | ||||||||||||
130 | BIO_F_BUFFER_CTX *b; | - | ||||||||||||
131 | - | |||||||||||||
132 | if (a == NULL)
| 0-142 | ||||||||||||
133 | return (0); never executed: return (0); | 0 | ||||||||||||
134 | b = (BIO_F_BUFFER_CTX *)a->ptr; | - | ||||||||||||
135 | free(b->ibuf); | - | ||||||||||||
136 | free(b->obuf); | - | ||||||||||||
137 | free(a->ptr); | - | ||||||||||||
138 | a->ptr = NULL; | - | ||||||||||||
139 | a->init = 0; | - | ||||||||||||
140 | a->flags = 0; | - | ||||||||||||
141 | return (1); executed 142 times by 5 tests: return (1); Executed by:
| 142 | ||||||||||||
142 | } | - | ||||||||||||
143 | - | |||||||||||||
144 | static int | - | ||||||||||||
145 | buffer_read(BIO *b, char *out, int outl) | - | ||||||||||||
146 | { | - | ||||||||||||
147 | int i, num = 0; | - | ||||||||||||
148 | BIO_F_BUFFER_CTX *ctx; | - | ||||||||||||
149 | - | |||||||||||||
150 | if (out == NULL)
| 0 | ||||||||||||
151 | return (0); never executed: return (0); | 0 | ||||||||||||
152 | ctx = (BIO_F_BUFFER_CTX *)b->ptr; | - | ||||||||||||
153 | - | |||||||||||||
154 | if ((ctx == NULL) || (b->next_bio == NULL))
| 0 | ||||||||||||
155 | return (0); never executed: return (0); | 0 | ||||||||||||
156 | num = 0; | - | ||||||||||||
157 | BIO_clear_retry_flags(b); | - | ||||||||||||
158 | - | |||||||||||||
159 | start: code before this statement never executed: start: | 0 | ||||||||||||
160 | i = ctx->ibuf_len; | - | ||||||||||||
161 | /* If there is stuff left over, grab it */ | - | ||||||||||||
162 | if (i != 0) {
| 0 | ||||||||||||
163 | if (i > outl)
| 0 | ||||||||||||
164 | i = outl; never executed: i = outl; | 0 | ||||||||||||
165 | memcpy(out, &(ctx->ibuf[ctx->ibuf_off]), i); | - | ||||||||||||
166 | ctx->ibuf_off += i; | - | ||||||||||||
167 | ctx->ibuf_len -= i; | - | ||||||||||||
168 | num += i; | - | ||||||||||||
169 | if (outl == i)
| 0 | ||||||||||||
170 | return (num); never executed: return (num); | 0 | ||||||||||||
171 | outl -= i; | - | ||||||||||||
172 | out += i; | - | ||||||||||||
173 | } never executed: end of block | 0 | ||||||||||||
174 | - | |||||||||||||
175 | /* We may have done a partial read. try to do more. | - | ||||||||||||
176 | * We have nothing in the buffer. | - | ||||||||||||
177 | * If we get an error and have read some data, just return it | - | ||||||||||||
178 | * and let them retry to get the error again. | - | ||||||||||||
179 | * copy direct to parent address space */ | - | ||||||||||||
180 | if (outl > ctx->ibuf_size) {
| 0 | ||||||||||||
181 | for (;;) { | - | ||||||||||||
182 | i = BIO_read(b->next_bio, out, outl); | - | ||||||||||||
183 | if (i <= 0) {
| 0 | ||||||||||||
184 | BIO_copy_next_retry(b); | - | ||||||||||||
185 | if (i < 0)
| 0 | ||||||||||||
186 | return ((num > 0) ? num : i); never executed: return ((num > 0) ? num : i);
| 0 | ||||||||||||
187 | if (i == 0)
| 0 | ||||||||||||
188 | return (num); never executed: return (num); | 0 | ||||||||||||
189 | } never executed: end of block | 0 | ||||||||||||
190 | num += i; | - | ||||||||||||
191 | if (outl == i)
| 0 | ||||||||||||
192 | return (num); never executed: return (num); | 0 | ||||||||||||
193 | out += i; | - | ||||||||||||
194 | outl -= i; | - | ||||||||||||
195 | } never executed: end of block | 0 | ||||||||||||
196 | } never executed: end of block | 0 | ||||||||||||
197 | /* else */ | - | ||||||||||||
198 | - | |||||||||||||
199 | /* we are going to be doing some buffering */ | - | ||||||||||||
200 | i = BIO_read(b->next_bio, ctx->ibuf, ctx->ibuf_size); | - | ||||||||||||
201 | if (i <= 0) {
| 0 | ||||||||||||
202 | BIO_copy_next_retry(b); | - | ||||||||||||
203 | if (i < 0)
| 0 | ||||||||||||
204 | return ((num > 0) ? num : i); never executed: return ((num > 0) ? num : i);
| 0 | ||||||||||||
205 | if (i == 0)
| 0 | ||||||||||||
206 | return (num); never executed: return (num); | 0 | ||||||||||||
207 | } never executed: end of block | 0 | ||||||||||||
208 | ctx->ibuf_off = 0; | - | ||||||||||||
209 | ctx->ibuf_len = i; | - | ||||||||||||
210 | - | |||||||||||||
211 | /* Lets re-read using ourselves :-) */ | - | ||||||||||||
212 | goto start; never executed: goto start; | 0 | ||||||||||||
213 | } | - | ||||||||||||
214 | - | |||||||||||||
215 | static int | - | ||||||||||||
216 | buffer_write(BIO *b, const char *in, int inl) | - | ||||||||||||
217 | { | - | ||||||||||||
218 | int i, num = 0; | - | ||||||||||||
219 | BIO_F_BUFFER_CTX *ctx; | - | ||||||||||||
220 | - | |||||||||||||
221 | if ((in == NULL) || (inl <= 0))
| 0-687 | ||||||||||||
222 | return (0); never executed: return (0); | 0 | ||||||||||||
223 | ctx = (BIO_F_BUFFER_CTX *)b->ptr; | - | ||||||||||||
224 | if ((ctx == NULL) || (b->next_bio == NULL))
| 0-687 | ||||||||||||
225 | return (0); never executed: return (0); | 0 | ||||||||||||
226 | - | |||||||||||||
227 | BIO_clear_retry_flags(b); | - | ||||||||||||
228 | start: code before this statement executed 687 times by 4 tests: start: Executed by:
| 687 | ||||||||||||
229 | i = ctx->obuf_size - (ctx->obuf_len + ctx->obuf_off); | - | ||||||||||||
230 | /* add to buffer and return */ | - | ||||||||||||
231 | if (i >= inl) {
| 0-687 | ||||||||||||
232 | memcpy(&(ctx->obuf[ctx->obuf_off + ctx->obuf_len]), in, inl); | - | ||||||||||||
233 | ctx->obuf_len += inl; | - | ||||||||||||
234 | return (num + inl); executed 687 times by 4 tests: return (num + inl); Executed by:
| 687 | ||||||||||||
235 | } | - | ||||||||||||
236 | /* else */ | - | ||||||||||||
237 | /* stuff already in buffer, so add to it first, then flush */ | - | ||||||||||||
238 | if (ctx->obuf_len != 0) {
| 0 | ||||||||||||
239 | if (i > 0) /* lets fill it up if we can */
| 0 | ||||||||||||
240 | { | - | ||||||||||||
241 | memcpy(&(ctx->obuf[ctx->obuf_off + ctx->obuf_len]), in, i); | - | ||||||||||||
242 | in += i; | - | ||||||||||||
243 | inl -= i; | - | ||||||||||||
244 | num += i; | - | ||||||||||||
245 | ctx->obuf_len += i; | - | ||||||||||||
246 | } never executed: end of block | 0 | ||||||||||||
247 | /* we now have a full buffer needing flushing */ | - | ||||||||||||
248 | for (;;) { | - | ||||||||||||
249 | i = BIO_write(b->next_bio, &(ctx->obuf[ctx->obuf_off]), | - | ||||||||||||
250 | ctx->obuf_len); | - | ||||||||||||
251 | if (i <= 0) {
| 0 | ||||||||||||
252 | BIO_copy_next_retry(b); | - | ||||||||||||
253 | - | |||||||||||||
254 | if (i < 0)
| 0 | ||||||||||||
255 | return ((num > 0) ? num : i); never executed: return ((num > 0) ? num : i);
| 0 | ||||||||||||
256 | if (i == 0)
| 0 | ||||||||||||
257 | return (num); never executed: return (num); | 0 | ||||||||||||
258 | } never executed: end of block | 0 | ||||||||||||
259 | ctx->obuf_off += i; | - | ||||||||||||
260 | ctx->obuf_len -= i; | - | ||||||||||||
261 | if (ctx->obuf_len == 0)
| 0 | ||||||||||||
262 | break; never executed: break; | 0 | ||||||||||||
263 | } never executed: end of block | 0 | ||||||||||||
264 | } never executed: end of block | 0 | ||||||||||||
265 | /* we only get here if the buffer has been flushed and we | - | ||||||||||||
266 | * still have stuff to write */ | - | ||||||||||||
267 | ctx->obuf_off = 0; | - | ||||||||||||
268 | - | |||||||||||||
269 | /* we now have inl bytes to write */ | - | ||||||||||||
270 | while (inl >= ctx->obuf_size) {
| 0 | ||||||||||||
271 | i = BIO_write(b->next_bio, in, inl); | - | ||||||||||||
272 | if (i <= 0) {
| 0 | ||||||||||||
273 | BIO_copy_next_retry(b); | - | ||||||||||||
274 | if (i < 0)
| 0 | ||||||||||||
275 | return ((num > 0) ? num : i); never executed: return ((num > 0) ? num : i);
| 0 | ||||||||||||
276 | if (i == 0)
| 0 | ||||||||||||
277 | return (num); never executed: return (num); | 0 | ||||||||||||
278 | } never executed: end of block | 0 | ||||||||||||
279 | num += i; | - | ||||||||||||
280 | in += i; | - | ||||||||||||
281 | inl -= i; | - | ||||||||||||
282 | if (inl == 0)
| 0 | ||||||||||||
283 | return (num); never executed: return (num); | 0 | ||||||||||||
284 | } never executed: end of block | 0 | ||||||||||||
285 | - | |||||||||||||
286 | /* copy the rest into the buffer since we have only a small | - | ||||||||||||
287 | * amount left */ | - | ||||||||||||
288 | goto start; never executed: goto start; | 0 | ||||||||||||
289 | } | - | ||||||||||||
290 | - | |||||||||||||
291 | static long | - | ||||||||||||
292 | buffer_ctrl(BIO *b, int cmd, long num, void *ptr) | - | ||||||||||||
293 | { | - | ||||||||||||
294 | BIO *dbio; | - | ||||||||||||
295 | BIO_F_BUFFER_CTX *ctx; | - | ||||||||||||
296 | long ret = 1; | - | ||||||||||||
297 | char *p1, *p2; | - | ||||||||||||
298 | int r, i, *ip; | - | ||||||||||||
299 | int ibs, obs; | - | ||||||||||||
300 | - | |||||||||||||
301 | ctx = (BIO_F_BUFFER_CTX *)b->ptr; | - | ||||||||||||
302 | - | |||||||||||||
303 | switch (cmd) { | - | ||||||||||||
304 | case BIO_CTRL_RESET: executed 139 times by 4 tests: case 1: Executed by:
| 139 | ||||||||||||
305 | ctx->ibuf_off = 0; | - | ||||||||||||
306 | ctx->ibuf_len = 0; | - | ||||||||||||
307 | ctx->obuf_off = 0; | - | ||||||||||||
308 | ctx->obuf_len = 0; | - | ||||||||||||
309 | if (b->next_bio == NULL)
| 0-139 | ||||||||||||
310 | return (0); executed 139 times by 4 tests: return (0); Executed by:
| 139 | ||||||||||||
311 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | - | ||||||||||||
312 | break; never executed: break; | 0 | ||||||||||||
313 | case BIO_CTRL_INFO: never executed: case 3: | 0 | ||||||||||||
314 | ret = (long)ctx->obuf_len; | - | ||||||||||||
315 | break; never executed: break; | 0 | ||||||||||||
316 | case BIO_C_GET_BUFF_NUM_LINES: never executed: case 116: | 0 | ||||||||||||
317 | ret = 0; | - | ||||||||||||
318 | p1 = ctx->ibuf; | - | ||||||||||||
319 | for (i = 0; i < ctx->ibuf_len; i++) {
| 0 | ||||||||||||
320 | if (p1[ctx->ibuf_off + i] == '\n')
| 0 | ||||||||||||
321 | ret++; never executed: ret++; | 0 | ||||||||||||
322 | } never executed: end of block | 0 | ||||||||||||
323 | break; never executed: break; | 0 | ||||||||||||
324 | case BIO_CTRL_WPENDING: executed 120 times by 1 test: case 13: Executed by:
| 120 | ||||||||||||
325 | ret = (long)ctx->obuf_len; | - | ||||||||||||
326 | if (ret == 0) {
| 33-87 | ||||||||||||
327 | if (b->next_bio == NULL)
| 0-33 | ||||||||||||
328 | return (0); never executed: return (0); | 0 | ||||||||||||
329 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | - | ||||||||||||
330 | } executed 33 times by 1 test: end of block Executed by:
| 33 | ||||||||||||
331 | break; executed 120 times by 1 test: break; Executed by:
| 120 | ||||||||||||
332 | case BIO_CTRL_PENDING: never executed: case 10: | 0 | ||||||||||||
333 | ret = (long)ctx->ibuf_len; | - | ||||||||||||
334 | if (ret == 0) {
| 0 | ||||||||||||
335 | if (b->next_bio == NULL)
| 0 | ||||||||||||
336 | return (0); never executed: return (0); | 0 | ||||||||||||
337 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | - | ||||||||||||
338 | } never executed: end of block | 0 | ||||||||||||
339 | break; never executed: break; | 0 | ||||||||||||
340 | case BIO_C_SET_BUFF_READ_DATA: never executed: case 122: | 0 | ||||||||||||
341 | if (num > ctx->ibuf_size) {
| 0 | ||||||||||||
342 | p1 = malloc(num); | - | ||||||||||||
343 | if (p1 == NULL)
| 0 | ||||||||||||
344 | goto malloc_error; never executed: goto malloc_error; | 0 | ||||||||||||
345 | free(ctx->ibuf); | - | ||||||||||||
346 | ctx->ibuf = p1; | - | ||||||||||||
347 | } never executed: end of block | 0 | ||||||||||||
348 | ctx->ibuf_off = 0; | - | ||||||||||||
349 | ctx->ibuf_len = (int)num; | - | ||||||||||||
350 | memcpy(ctx->ibuf, ptr, num); | - | ||||||||||||
351 | ret = 1; | - | ||||||||||||
352 | break; never executed: break; | 0 | ||||||||||||
353 | case BIO_C_SET_BUFF_SIZE: executed 139 times by 4 tests: case 117: Executed by:
| 139 | ||||||||||||
354 | if (ptr != NULL) {
| 0-139 | ||||||||||||
355 | ip = (int *)ptr; | - | ||||||||||||
356 | if (*ip == 0) {
| 0-139 | ||||||||||||
357 | ibs = (int)num; | - | ||||||||||||
358 | obs = ctx->obuf_size; | - | ||||||||||||
359 | } executed 139 times by 4 tests: end of block Executed by:
| 139 | ||||||||||||
360 | else /* if (*ip == 1) */ | - | ||||||||||||
361 | { | - | ||||||||||||
362 | ibs = ctx->ibuf_size; | - | ||||||||||||
363 | obs = (int)num; | - | ||||||||||||
364 | } never executed: end of block | 0 | ||||||||||||
365 | } else { | - | ||||||||||||
366 | ibs = (int)num; | - | ||||||||||||
367 | obs = (int)num; | - | ||||||||||||
368 | } never executed: end of block | 0 | ||||||||||||
369 | p1 = ctx->ibuf; | - | ||||||||||||
370 | p2 = ctx->obuf; | - | ||||||||||||
371 | if ((ibs > DEFAULT_BUFFER_SIZE) && (ibs != ctx->ibuf_size)) {
| 0-139 | ||||||||||||
372 | p1 = malloc(num); | - | ||||||||||||
373 | if (p1 == NULL)
| 0 | ||||||||||||
374 | goto malloc_error; never executed: goto malloc_error; | 0 | ||||||||||||
375 | } never executed: end of block | 0 | ||||||||||||
376 | if ((obs > DEFAULT_BUFFER_SIZE) && (obs != ctx->obuf_size)) {
| 0-139 | ||||||||||||
377 | p2 = malloc(num); | - | ||||||||||||
378 | if (p2 == NULL) {
| 0 | ||||||||||||
379 | if (p1 != ctx->ibuf)
| 0 | ||||||||||||
380 | free(p1); never executed: free(p1); | 0 | ||||||||||||
381 | goto malloc_error; never executed: goto malloc_error; | 0 | ||||||||||||
382 | } | - | ||||||||||||
383 | } never executed: end of block | 0 | ||||||||||||
384 | if (ctx->ibuf != p1) {
| 0-139 | ||||||||||||
385 | free(ctx->ibuf); | - | ||||||||||||
386 | ctx->ibuf = p1; | - | ||||||||||||
387 | ctx->ibuf_off = 0; | - | ||||||||||||
388 | ctx->ibuf_len = 0; | - | ||||||||||||
389 | ctx->ibuf_size = ibs; | - | ||||||||||||
390 | } never executed: end of block | 0 | ||||||||||||
391 | if (ctx->obuf != p2) {
| 0-139 | ||||||||||||
392 | free(ctx->obuf); | - | ||||||||||||
393 | ctx->obuf = p2; | - | ||||||||||||
394 | ctx->obuf_off = 0; | - | ||||||||||||
395 | ctx->obuf_len = 0; | - | ||||||||||||
396 | ctx->obuf_size = obs; | - | ||||||||||||
397 | } never executed: end of block | 0 | ||||||||||||
398 | break; executed 139 times by 4 tests: break; Executed by:
| 139 | ||||||||||||
399 | case BIO_C_DO_STATE_MACHINE: never executed: case 101: | 0 | ||||||||||||
400 | if (b->next_bio == NULL)
| 0 | ||||||||||||
401 | return (0); never executed: return (0); | 0 | ||||||||||||
402 | BIO_clear_retry_flags(b); | - | ||||||||||||
403 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | - | ||||||||||||
404 | BIO_copy_next_retry(b); | - | ||||||||||||
405 | break; never executed: break; | 0 | ||||||||||||
406 | - | |||||||||||||
407 | case BIO_CTRL_FLUSH: executed 581 times by 4 tests: case 11: Executed by:
| 581 | ||||||||||||
408 | if (b->next_bio == NULL)
| 0-581 | ||||||||||||
409 | return (0); never executed: return (0); | 0 | ||||||||||||
410 | if (ctx->obuf_len <= 0) {
| 0-581 | ||||||||||||
411 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | - | ||||||||||||
412 | break; never executed: break; | 0 | ||||||||||||
413 | } | - | ||||||||||||
414 | - | |||||||||||||
415 | for (;;) { | - | ||||||||||||
416 | BIO_clear_retry_flags(b); | - | ||||||||||||
417 | if (ctx->obuf_len > 0) {
| 205-771 | ||||||||||||
418 | r = BIO_write(b->next_bio, | - | ||||||||||||
419 | &(ctx->obuf[ctx->obuf_off]), | - | ||||||||||||
420 | ctx->obuf_len); | - | ||||||||||||
421 | BIO_copy_next_retry(b); | - | ||||||||||||
422 | if (r <= 0)
| 376-395 | ||||||||||||
423 | return ((long)r); executed 376 times by 2 tests: return ((long)r); Executed by:
| 376 | ||||||||||||
424 | ctx->obuf_off += r; | - | ||||||||||||
425 | ctx->obuf_len -= r; | - | ||||||||||||
426 | } else { executed 395 times by 4 tests: end of block Executed by:
| 395 | ||||||||||||
427 | ctx->obuf_len = 0; | - | ||||||||||||
428 | ctx->obuf_off = 0; | - | ||||||||||||
429 | break; executed 205 times by 4 tests: break; Executed by:
| 205 | ||||||||||||
430 | } | - | ||||||||||||
431 | } | - | ||||||||||||
432 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | - | ||||||||||||
433 | break; executed 205 times by 4 tests: break; Executed by:
| 205 | ||||||||||||
434 | case BIO_CTRL_DUP: never executed: case 12: | 0 | ||||||||||||
435 | dbio = (BIO *)ptr; | - | ||||||||||||
436 | if (!BIO_set_read_buffer_size(dbio, ctx->ibuf_size) ||
| 0 | ||||||||||||
437 | !BIO_set_write_buffer_size(dbio, ctx->obuf_size))
| 0 | ||||||||||||
438 | ret = 0; never executed: ret = 0; | 0 | ||||||||||||
439 | break; never executed: break; | 0 | ||||||||||||
440 | default: executed 306 times by 5 tests: default: Executed by:
| 306 | ||||||||||||
441 | if (b->next_bio == NULL)
| 0-306 | ||||||||||||
442 | return (0); never executed: return (0); | 0 | ||||||||||||
443 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | - | ||||||||||||
444 | break; executed 306 times by 5 tests: break; Executed by:
| 306 | ||||||||||||
445 | } | - | ||||||||||||
446 | return (ret); executed 770 times by 5 tests: return (ret); Executed by:
| 770 | ||||||||||||
447 | malloc_error: | - | ||||||||||||
448 | BIOerror(ERR_R_MALLOC_FAILURE); | - | ||||||||||||
449 | return (0); never executed: return (0); | 0 | ||||||||||||
450 | } | - | ||||||||||||
451 | - | |||||||||||||
452 | static long | - | ||||||||||||
453 | buffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) | - | ||||||||||||
454 | { | - | ||||||||||||
455 | long ret = 1; | - | ||||||||||||
456 | - | |||||||||||||
457 | if (b->next_bio == NULL)
| 0 | ||||||||||||
458 | return (0); never executed: return (0); | 0 | ||||||||||||
459 | switch (cmd) { | - | ||||||||||||
460 | default: never executed: default: | 0 | ||||||||||||
461 | ret = BIO_callback_ctrl(b->next_bio, cmd, fp); | - | ||||||||||||
462 | break; never executed: break; | 0 | ||||||||||||
463 | } | - | ||||||||||||
464 | return (ret); never executed: return (ret); | 0 | ||||||||||||
465 | } | - | ||||||||||||
466 | - | |||||||||||||
467 | static int | - | ||||||||||||
468 | buffer_gets(BIO *b, char *buf, int size) | - | ||||||||||||
469 | { | - | ||||||||||||
470 | BIO_F_BUFFER_CTX *ctx; | - | ||||||||||||
471 | int num = 0, i, flag; | - | ||||||||||||
472 | char *p; | - | ||||||||||||
473 | - | |||||||||||||
474 | ctx = (BIO_F_BUFFER_CTX *)b->ptr; | - | ||||||||||||
475 | size--; /* reserve space for a '\0' */ | - | ||||||||||||
476 | BIO_clear_retry_flags(b); | - | ||||||||||||
477 | - | |||||||||||||
478 | for (;;) { | - | ||||||||||||
479 | if (ctx->ibuf_len > 0) {
| 0 | ||||||||||||
480 | p = &(ctx->ibuf[ctx->ibuf_off]); | - | ||||||||||||
481 | flag = 0; | - | ||||||||||||
482 | for (i = 0; (i < ctx->ibuf_len) && (i < size); i++) {
| 0 | ||||||||||||
483 | *(buf++) = p[i]; | - | ||||||||||||
484 | if (p[i] == '\n') {
| 0 | ||||||||||||
485 | flag = 1; | - | ||||||||||||
486 | i++; | - | ||||||||||||
487 | break; never executed: break; | 0 | ||||||||||||
488 | } | - | ||||||||||||
489 | } never executed: end of block | 0 | ||||||||||||
490 | num += i; | - | ||||||||||||
491 | size -= i; | - | ||||||||||||
492 | ctx->ibuf_len -= i; | - | ||||||||||||
493 | ctx->ibuf_off += i; | - | ||||||||||||
494 | if (flag || size == 0) {
| 0 | ||||||||||||
495 | *buf = '\0'; | - | ||||||||||||
496 | return (num); never executed: return (num); | 0 | ||||||||||||
497 | } | - | ||||||||||||
498 | } never executed: end of block | 0 | ||||||||||||
499 | else /* read another chunk */ | - | ||||||||||||
500 | { | - | ||||||||||||
501 | i = BIO_read(b->next_bio, ctx->ibuf, ctx->ibuf_size); | - | ||||||||||||
502 | if (i <= 0) {
| 0 | ||||||||||||
503 | BIO_copy_next_retry(b); | - | ||||||||||||
504 | *buf = '\0'; | - | ||||||||||||
505 | if (i < 0)
| 0 | ||||||||||||
506 | return ((num > 0) ? num : i); never executed: return ((num > 0) ? num : i);
| 0 | ||||||||||||
507 | if (i == 0)
| 0 | ||||||||||||
508 | return (num); never executed: return (num); | 0 | ||||||||||||
509 | } never executed: end of block | 0 | ||||||||||||
510 | ctx->ibuf_len = i; | - | ||||||||||||
511 | ctx->ibuf_off = 0; | - | ||||||||||||
512 | } never executed: end of block | 0 | ||||||||||||
513 | } | - | ||||||||||||
514 | } never executed: end of block | 0 | ||||||||||||
515 | - | |||||||||||||
516 | static int | - | ||||||||||||
517 | buffer_puts(BIO *b, const char *str) | - | ||||||||||||
518 | { | - | ||||||||||||
519 | return (buffer_write(b, str, strlen(str))); never executed: return (buffer_write(b, str, strlen(str))); | 0 | ||||||||||||
520 | } | - | ||||||||||||
Source code | Switch to Preprocessed file |