OpenCoverage

bf_buff.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/bio/bf_buff.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * Copyright 1995-2016 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 <stdio.h>-
11#include <errno.h>-
12#include "bio_lcl.h"-
13#include "internal/cryptlib.h"-
14-
15static int buffer_write(BIO *h, const char *buf, int num);-
16static int buffer_read(BIO *h, char *buf, int size);-
17static int buffer_puts(BIO *h, const char *str);-
18static int buffer_gets(BIO *h, char *str, int size);-
19static long buffer_ctrl(BIO *h, int cmd, long arg1, void *arg2);-
20static int buffer_new(BIO *h);-
21static int buffer_free(BIO *data);-
22static long buffer_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fp);-
23#define DEFAULT_BUFFER_SIZE 4096-
24-
25static const BIO_METHOD methods_buffer = {-
26 BIO_TYPE_BUFFER,-
27 "buffer",-
28 /* TODO: Convert to new style write function */-
29 bwrite_conv,-
30 buffer_write,-
31 /* TODO: Convert to new style read function */-
32 bread_conv,-
33 buffer_read,-
34 buffer_puts,-
35 buffer_gets,-
36 buffer_ctrl,-
37 buffer_new,-
38 buffer_free,-
39 buffer_callback_ctrl,-
40};-
41-
42const BIO_METHOD *BIO_f_buffer(void)-
43{-
44 return &methods_buffer;
executed 9513 times by 1 test: return &methods_buffer;
Executed by:
  • libcrypto.so.1.1
9513
45}-
46-
47static int buffer_new(BIO *bi)-
48{-
49 BIO_F_BUFFER_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));-
50-
51 if (ctx == NULL)
ctx == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 9513 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-9513
52 return 0;
never executed: return 0;
0
53 ctx->ibuf_size = DEFAULT_BUFFER_SIZE;-
54 ctx->ibuf = OPENSSL_malloc(DEFAULT_BUFFER_SIZE);-
55 if (ctx->ibuf == NULL) {
ctx->ibuf == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 9513 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-9513
56 OPENSSL_free(ctx);-
57 return 0;
never executed: return 0;
0
58 }-
59 ctx->obuf_size = DEFAULT_BUFFER_SIZE;-
60 ctx->obuf = OPENSSL_malloc(DEFAULT_BUFFER_SIZE);-
61 if (ctx->obuf == NULL) {
ctx->obuf == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 9513 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-9513
62 OPENSSL_free(ctx->ibuf);-
63 OPENSSL_free(ctx);-
64 return 0;
never executed: return 0;
0
65 }-
66-
67 bi->init = 1;-
68 bi->ptr = (char *)ctx;-
69 bi->flags = 0;-
70 return 1;
executed 9513 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
9513
71}-
72-
73static int buffer_free(BIO *a)-
74{-
75 BIO_F_BUFFER_CTX *b;-
76-
77 if (a == NULL)
a == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 9513 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-9513
78 return 0;
never executed: return 0;
0
79 b = (BIO_F_BUFFER_CTX *)a->ptr;-
80 OPENSSL_free(b->ibuf);-
81 OPENSSL_free(b->obuf);-
82 OPENSSL_free(a->ptr);-
83 a->ptr = NULL;-
84 a->init = 0;-
85 a->flags = 0;-
86 return 1;
executed 9513 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
9513
87}-
88-
89static int buffer_read(BIO *b, char *out, int outl)-
90{-
91 int i, num = 0;-
92 BIO_F_BUFFER_CTX *ctx;-
93-
94 if (out == NULL)
out == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
95 return 0;
never executed: return 0;
0
96 ctx = (BIO_F_BUFFER_CTX *)b->ptr;-
97-
98 if ((ctx == NULL) || (b->next_bio == NULL))
(ctx == ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
(b->next_bio == ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
0
99 return 0;
never executed: return 0;
0
100 num = 0;-
101 BIO_clear_retry_flags(b);-
102-
103 start:
code before this statement never executed: start:
0
104 i = ctx->ibuf_len;-
105 /* If there is stuff left over, grab it */-
106 if (i != 0) {
i != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
107 if (i > outl)
i > outlDescription
TRUEnever evaluated
FALSEnever evaluated
0
108 i = outl;
never executed: i = outl;
0
109 memcpy(out, &(ctx->ibuf[ctx->ibuf_off]), i);-
110 ctx->ibuf_off += i;-
111 ctx->ibuf_len -= i;-
112 num += i;-
113 if (outl == i)
outl == iDescription
TRUEnever evaluated
FALSEnever evaluated
0
114 return num;
never executed: return num;
0
115 outl -= i;-
116 out += i;-
117 }
never executed: end of block
0
118-
119 /*-
120 * We may have done a partial read. try to do more. We have nothing in-
121 * the buffer. If we get an error and have read some data, just return it-
122 * and let them retry to get the error again. copy direct to parent-
123 * address space-
124 */-
125 if (outl > ctx->ibuf_size) {
outl > ctx->ibuf_sizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
126 for (;;) {-
127 i = BIO_read(b->next_bio, out, outl);-
128 if (i <= 0) {
i <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
129 BIO_copy_next_retry(b);-
130 if (i < 0)
i < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
131 return ((num > 0) ? num : i);
never executed: return ((num > 0) ? num : i);
(num > 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
132 if (i == 0)
i == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
133 return num;
never executed: return num;
0
134 }
never executed: end of block
0
135 num += i;-
136 if (outl == i)
outl == iDescription
TRUEnever evaluated
FALSEnever evaluated
0
137 return num;
never executed: return num;
0
138 out += i;-
139 outl -= i;-
140 }
never executed: end of block
0
141 }
never executed: end of block
0
142 /* else */-
143-
144 /* we are going to be doing some buffering */-
145 i = BIO_read(b->next_bio, ctx->ibuf, ctx->ibuf_size);-
146 if (i <= 0) {
i <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
147 BIO_copy_next_retry(b);-
148 if (i < 0)
i < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
149 return ((num > 0) ? num : i);
never executed: return ((num > 0) ? num : i);
(num > 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
150 if (i == 0)
i == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
151 return num;
never executed: return num;
0
152 }
never executed: end of block
0
153 ctx->ibuf_off = 0;-
154 ctx->ibuf_len = i;-
155-
156 /* Lets re-read using ourselves :-) */-
157 goto start;
never executed: goto start;
0
158}-
159-
160static int buffer_write(BIO *b, const char *in, int inl)-
161{-
162 int i, num = 0;-
163 BIO_F_BUFFER_CTX *ctx;-
164-
165 if ((in == NULL) || (inl <= 0))
(in == ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 32043 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
(inl <= 0)Description
TRUEnever evaluated
FALSEevaluated 32043 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-32043
166 return 0;
never executed: return 0;
0
167 ctx = (BIO_F_BUFFER_CTX *)b->ptr;-
168 if ((ctx == NULL) || (b->next_bio == NULL))
(ctx == ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 32043 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
(b->next_bio == ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 32043 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-32043
169 return 0;
never executed: return 0;
0
170-
171 BIO_clear_retry_flags(b);-
172 start:
code before this statement executed 32043 times by 1 test: start:
Executed by:
  • libcrypto.so.1.1
32043
173 i = ctx->obuf_size - (ctx->obuf_len + ctx->obuf_off);-
174 /* add to buffer and return */-
175 if (i >= inl) {
i >= inlDescription
TRUEevaluated 32037 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 6 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
6-32037
176 memcpy(&(ctx->obuf[ctx->obuf_off + ctx->obuf_len]), in, inl);-
177 ctx->obuf_len += inl;-
178 return (num + inl);
executed 32037 times by 1 test: return (num + inl);
Executed by:
  • libcrypto.so.1.1
32037
179 }-
180 /* else */-
181 /* stuff already in buffer, so add to it first, then flush */-
182 if (ctx->obuf_len != 0) {
ctx->obuf_len != 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2-4
183 if (i > 0) { /* lets fill it up if we can */
i > 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-2
184 memcpy(&(ctx->obuf[ctx->obuf_off + ctx->obuf_len]), in, i);-
185 in += i;-
186 inl -= i;-
187 num += i;-
188 ctx->obuf_len += i;-
189 }
executed 2 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
2
190 /* we now have a full buffer needing flushing */-
191 for (;;) {-
192 i = BIO_write(b->next_bio, &(ctx->obuf[ctx->obuf_off]),-
193 ctx->obuf_len);-
194 if (i <= 0) {
i <= 0Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2
195 BIO_copy_next_retry(b);-
196-
197 if (i < 0)
i < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
198 return ((num > 0) ? num : i);
never executed: return ((num > 0) ? num : i);
(num > 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
199 if (i == 0)
i == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
200 return num;
never executed: return num;
0
201 }
never executed: end of block
0
202 ctx->obuf_off += i;-
203 ctx->obuf_len -= i;-
204 if (ctx->obuf_len == 0)
ctx->obuf_len == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-2
205 break;
executed 2 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
2
206 }
never executed: end of block
0
207 }
executed 2 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
2
208 /*-
209 * we only get here if the buffer has been flushed and we still have-
210 * stuff to write-
211 */-
212 ctx->obuf_off = 0;-
213-
214 /* we now have inl bytes to write */-
215 while (inl >= ctx->obuf_size) {
inl >= ctx->obuf_sizeDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-6
216 i = BIO_write(b->next_bio, in, inl);-
217 if (i <= 0) {
i <= 0Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-6
218 BIO_copy_next_retry(b);-
219 if (i < 0)
i < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
220 return ((num > 0) ? num : i);
never executed: return ((num > 0) ? num : i);
(num > 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
221 if (i == 0)
i == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
222 return num;
never executed: return num;
0
223 }
never executed: end of block
0
224 num += i;-
225 in += i;-
226 inl -= i;-
227 if (inl == 0)
inl == 0Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-6
228 return num;
executed 6 times by 1 test: return num;
Executed by:
  • libcrypto.so.1.1
6
229 }
never executed: end of block
0
230-
231 /*-
232 * copy the rest into the buffer since we have only a small amount left-
233 */-
234 goto start;
never executed: goto start;
0
235}-
236-
237static long buffer_ctrl(BIO *b, int cmd, long num, void *ptr)-
238{-
239 BIO *dbio;-
240 BIO_F_BUFFER_CTX *ctx;-
241 long ret = 1;-
242 char *p1, *p2;-
243 int r, i, *ip;-
244 int ibs, obs;-
245-
246 ctx = (BIO_F_BUFFER_CTX *)b->ptr;-
247-
248 switch (cmd) {-
249 case BIO_CTRL_RESET:
never executed: case 1:
0
250 ctx->ibuf_off = 0;-
251 ctx->ibuf_len = 0;-
252 ctx->obuf_off = 0;-
253 ctx->obuf_len = 0;-
254 if (b->next_bio == NULL)
b->next_bio == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
255 return 0;
never executed: return 0;
0
256 ret = BIO_ctrl(b->next_bio, cmd, num, ptr);-
257 break;
never executed: break;
0
258 case BIO_CTRL_EOF:
never executed: case 2:
0
259 if (ctx->ibuf_len > 0)
ctx->ibuf_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
260 return 0;
never executed: return 0;
0
261 ret = BIO_ctrl(b->next_bio, cmd, num, ptr);-
262 break;
never executed: break;
0
263 case BIO_CTRL_INFO:
never executed: case 3:
0
264 ret = (long)ctx->obuf_len;-
265 break;
never executed: break;
0
266 case BIO_C_GET_BUFF_NUM_LINES:
never executed: case 116:
0
267 ret = 0;-
268 p1 = ctx->ibuf;-
269 for (i = 0; i < ctx->ibuf_len; i++) {
i < ctx->ibuf_lenDescription
TRUEnever evaluated
FALSEnever evaluated
0
270 if (p1[ctx->ibuf_off + i] == '\n')
p1[ctx->ibuf_off + i] == '\n'Description
TRUEnever evaluated
FALSEnever evaluated
0
271 ret++;
never executed: ret++;
0
272 }
never executed: end of block
0
273 break;
never executed: break;
0
274 case BIO_CTRL_WPENDING:
executed 3009 times by 1 test: case 13:
Executed by:
  • libcrypto.so.1.1
3009
275 ret = (long)ctx->obuf_len;-
276 if (ret == 0) {
ret == 0Description
TRUEevaluated 825 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2184 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
825-2184
277 if (b->next_bio == NULL)
b->next_bio == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 825 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-825
278 return 0;
never executed: return 0;
0
279 ret = BIO_ctrl(b->next_bio, cmd, num, ptr);-
280 }
executed 825 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
825
281 break;
executed 3009 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
3009
282 case BIO_CTRL_PENDING:
never executed: case 10:
0
283 ret = (long)ctx->ibuf_len;-
284 if (ret == 0) {
ret == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
285 if (b->next_bio == NULL)
b->next_bio == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
286 return 0;
never executed: return 0;
0
287 ret = BIO_ctrl(b->next_bio, cmd, num, ptr);-
288 }
never executed: end of block
0
289 break;
never executed: break;
0
290 case BIO_C_SET_BUFF_READ_DATA:
never executed: case 122:
0
291 if (num > ctx->ibuf_size) {
num > ctx->ibuf_sizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
292 p1 = OPENSSL_malloc((int)num);-
293 if (p1 == NULL)
p1 == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
294 goto malloc_error;
never executed: goto malloc_error;
0
295 OPENSSL_free(ctx->ibuf);-
296 ctx->ibuf = p1;-
297 }
never executed: end of block
0
298 ctx->ibuf_off = 0;-
299 ctx->ibuf_len = (int)num;-
300 memcpy(ctx->ibuf, ptr, (int)num);-
301 ret = 1;-
302 break;
never executed: break;
0
303 case BIO_C_SET_BUFF_SIZE:
executed 9434 times by 1 test: case 117:
Executed by:
  • libcrypto.so.1.1
9434
304 if (ptr != NULL) {
ptr != ((void *)0)Description
TRUEevaluated 9434 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-9434
305 ip = (int *)ptr;-
306 if (*ip == 0) {
*ip == 0Description
TRUEevaluated 9243 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 191 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
191-9243
307 ibs = (int)num;-
308 obs = ctx->obuf_size;-
309 } else { /* if (*ip == 1) */
executed 9243 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
9243
310-
311 ibs = ctx->ibuf_size;-
312 obs = (int)num;-
313 }
executed 191 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
191
314 } else {-
315 ibs = (int)num;-
316 obs = (int)num;-
317 }
never executed: end of block
0
318 p1 = ctx->ibuf;-
319 p2 = ctx->obuf;-
320 if ((ibs > DEFAULT_BUFFER_SIZE) && (ibs != ctx->ibuf_size)) {
(ibs > 4096)Description
TRUEnever evaluated
FALSEevaluated 9434 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
(ibs != ctx->ibuf_size)Description
TRUEnever evaluated
FALSEnever evaluated
0-9434
321 p1 = OPENSSL_malloc((int)num);-
322 if (p1 == NULL)
p1 == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
323 goto malloc_error;
never executed: goto malloc_error;
0
324 }
never executed: end of block
0
325 if ((obs > DEFAULT_BUFFER_SIZE) && (obs != ctx->obuf_size)) {
(obs > 4096)Description
TRUEevaluated 191 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 9243 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
(obs != ctx->obuf_size)Description
TRUEevaluated 191 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-9243
326 p2 = OPENSSL_malloc((int)num);-
327 if (p2 == NULL) {
p2 == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 191 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-191
328 if (p1 != ctx->ibuf)
p1 != ctx->ibufDescription
TRUEnever evaluated
FALSEnever evaluated
0
329 OPENSSL_free(p1);
never executed: CRYPTO_free(p1, __FILE__, 329);
0
330 goto malloc_error;
never executed: goto malloc_error;
0
331 }-
332 }
executed 191 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
191
333 if (ctx->ibuf != p1) {
ctx->ibuf != p1Description
TRUEnever evaluated
FALSEevaluated 9434 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-9434
334 OPENSSL_free(ctx->ibuf);-
335 ctx->ibuf = p1;-
336 ctx->ibuf_off = 0;-
337 ctx->ibuf_len = 0;-
338 ctx->ibuf_size = ibs;-
339 }
never executed: end of block
0
340 if (ctx->obuf != p2) {
ctx->obuf != p2Description
TRUEevaluated 191 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 9243 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
191-9243
341 OPENSSL_free(ctx->obuf);-
342 ctx->obuf = p2;-
343 ctx->obuf_off = 0;-
344 ctx->obuf_len = 0;-
345 ctx->obuf_size = obs;-
346 }
executed 191 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
191
347 break;
executed 9434 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
9434
348 case BIO_C_DO_STATE_MACHINE:
executed 191 times by 1 test: case 101:
Executed by:
  • libcrypto.so.1.1
191
349 if (b->next_bio == NULL)
b->next_bio == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 191 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-191
350 return 0;
never executed: return 0;
0
351 BIO_clear_retry_flags(b);-
352 ret = BIO_ctrl(b->next_bio, cmd, num, ptr);-
353 BIO_copy_next_retry(b);-
354 break;
executed 191 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
191
355-
356 case BIO_CTRL_FLUSH:
executed 17364 times by 1 test: case 11:
Executed by:
  • libcrypto.so.1.1
17364
357 if (b->next_bio == NULL)
b->next_bio == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 17364 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-17364
358 return 0;
never executed: return 0;
0
359 if (ctx->obuf_len <= 0) {
ctx->obuf_len <= 0Description
TRUEnever evaluated
FALSEevaluated 17364 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-17364
360 ret = BIO_ctrl(b->next_bio, cmd, num, ptr);-
361 break;
never executed: break;
0
362 }-
363-
364 for (;;) {-
365 BIO_clear_retry_flags(b);-
366 if (ctx->obuf_len > 0) {
ctx->obuf_len > 0Description
TRUEevaluated 17667 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 16748 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
16748-17667
367 r = BIO_write(b->next_bio,-
368 &(ctx->obuf[ctx->obuf_off]), ctx->obuf_len);-
369 BIO_copy_next_retry(b);-
370 if (r <= 0)
r <= 0Description
TRUEevaluated 616 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 17051 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
616-17051
371 return (long)r;
executed 616 times by 1 test: return (long)r;
Executed by:
  • libcrypto.so.1.1
616
372 ctx->obuf_off += r;-
373 ctx->obuf_len -= r;-
374 } else {
executed 17051 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
17051
375 ctx->obuf_len = 0;-
376 ctx->obuf_off = 0;-
377 break;
executed 16748 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
16748
378 }-
379 }-
380 ret = BIO_ctrl(b->next_bio, cmd, num, ptr);-
381 break;
executed 16748 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
16748
382 case BIO_CTRL_DUP:
never executed: case 12:
0
383 dbio = (BIO *)ptr;-
384 if (!BIO_set_read_buffer_size(dbio, ctx->ibuf_size) ||
!BIO_int_ctrl(...->ibuf_size,0)Description
TRUEnever evaluated
FALSEnever evaluated
0
385 !BIO_set_write_buffer_size(dbio, ctx->obuf_size))
!BIO_int_ctrl(...->obuf_size,1)Description
TRUEnever evaluated
FALSEnever evaluated
0
386 ret = 0;
never executed: ret = 0;
0
387 break;
never executed: break;
0
388 case BIO_CTRL_PEEK:
never executed: case 29:
0
389 /* Ensure there's stuff in the input buffer */-
390 {-
391 char fake_buf[1];-
392 (void)buffer_read(b, fake_buf, 0);-
393 }-
394 if (num > ctx->ibuf_len)
num > ctx->ibuf_lenDescription
TRUEnever evaluated
FALSEnever evaluated
0
395 num = ctx->ibuf_len;
never executed: num = ctx->ibuf_len;
0
396 memcpy(ptr, &(ctx->ibuf[ctx->ibuf_off]), num);-
397 ret = num;-
398 break;
never executed: break;
0
399 default:
executed 18845 times by 1 test: default:
Executed by:
  • libcrypto.so.1.1
18845
400 if (b->next_bio == NULL)
b->next_bio == ((void *)0)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 18841 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
4-18841
401 return 0;
executed 4 times by 1 test: return 0;
Executed by:
  • libcrypto.so.1.1
4
402 ret = BIO_ctrl(b->next_bio, cmd, num, ptr);-
403 break;
executed 18841 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
18841
404 }-
405 return ret;
executed 48223 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
48223
406 malloc_error:-
407 BIOerr(BIO_F_BUFFER_CTRL, ERR_R_MALLOC_FAILURE);-
408 return 0;
never executed: return 0;
0
409}-
410-
411static long buffer_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp)-
412{-
413 long ret = 1;-
414-
415 if (b->next_bio == NULL)
b->next_bio == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
416 return 0;
never executed: return 0;
0
417 switch (cmd) {-
418 default:
never executed: default:
0
419 ret = BIO_callback_ctrl(b->next_bio, cmd, fp);-
420 break;
never executed: break;
0
421 }-
422 return ret;
never executed: return ret;
0
423}-
424-
425static int buffer_gets(BIO *b, char *buf, int size)-
426{-
427 BIO_F_BUFFER_CTX *ctx;-
428 int num = 0, i, flag;-
429 char *p;-
430-
431 ctx = (BIO_F_BUFFER_CTX *)b->ptr;-
432 size--; /* reserve space for a '\0' */-
433 BIO_clear_retry_flags(b);-
434-
435 for (;;) {-
436 if (ctx->ibuf_len > 0) {
ctx->ibuf_len > 0Description
TRUEevaluated 113 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 350 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
113-350
437 p = &(ctx->ibuf[ctx->ibuf_off]);-
438 flag = 0;-
439 for (i = 0; (i < ctx->ibuf_len) && (i < size); i++) {
(i < ctx->ibuf_len)Description
TRUEevaluated 443 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 113 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
(i < size)Description
TRUEevaluated 443 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-443
440 *(buf++) = p[i];-
441 if (p[i] == '\n') {
p[i] == '\n'Description
TRUEnever evaluated
FALSEevaluated 443 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-443
442 flag = 1;-
443 i++;-
444 break;
never executed: break;
0
445 }-
446 }
executed 443 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
443
447 num += i;-
448 size -= i;-
449 ctx->ibuf_len -= i;-
450 ctx->ibuf_off += i;-
451 if (flag || size == 0) {
flagDescription
TRUEnever evaluated
FALSEevaluated 113 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
size == 0Description
TRUEnever evaluated
FALSEevaluated 113 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-113
452 *buf = '\0';-
453 return num;
never executed: return num;
0
454 }-
455 } else { /* read another chunk */
executed 113 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
113
456-
457 i = BIO_read(b->next_bio, ctx->ibuf, ctx->ibuf_size);-
458 if (i <= 0) {
i <= 0Description
TRUEevaluated 237 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 113 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
113-237
459 BIO_copy_next_retry(b);-
460 *buf = '\0';-
461 if (i < 0)
i < 0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 233 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
4-233
462 return ((num > 0) ? num : i);
executed 4 times by 1 test: return ((num > 0) ? num : i);
Executed by:
  • libcrypto.so.1.1
(num > 0)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
463 if (i == 0)
i == 0Description
TRUEevaluated 233 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-233
464 return num;
executed 233 times by 1 test: return num;
Executed by:
  • libcrypto.so.1.1
233
465 }
never executed: end of block
0
466 ctx->ibuf_len = i;-
467 ctx->ibuf_off = 0;-
468 }
executed 113 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
113
469 }-
470}
never executed: end of block
0
471-
472static int buffer_puts(BIO *b, const char *str)-
473{-
474 return buffer_write(b, str, strlen(str));
never executed: return buffer_write(b, str, strlen(str));
0
475}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2