Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/bio/bss_mem.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||||||||
2 | - | |||||||||||||||||||||||||
3 | static int mem_write(BIO *h, const char *buf, int num); | - | ||||||||||||||||||||||||
4 | static int mem_read(BIO *h, char *buf, int size); | - | ||||||||||||||||||||||||
5 | static int mem_puts(BIO *h, const char *str); | - | ||||||||||||||||||||||||
6 | static int mem_gets(BIO *h, char *str, int size); | - | ||||||||||||||||||||||||
7 | static long mem_ctrl(BIO *h, int cmd, long arg1, void *arg2); | - | ||||||||||||||||||||||||
8 | static int mem_new(BIO *h); | - | ||||||||||||||||||||||||
9 | static int mem_free(BIO *data); | - | ||||||||||||||||||||||||
10 | - | |||||||||||||||||||||||||
11 | static const BIO_METHOD mem_method = { | - | ||||||||||||||||||||||||
12 | .type = (1|0x0400), | - | ||||||||||||||||||||||||
13 | .name = "memory buffer", | - | ||||||||||||||||||||||||
14 | .bwrite = mem_write, | - | ||||||||||||||||||||||||
15 | .bread = mem_read, | - | ||||||||||||||||||||||||
16 | .bputs = mem_puts, | - | ||||||||||||||||||||||||
17 | .bgets = mem_gets, | - | ||||||||||||||||||||||||
18 | .ctrl = mem_ctrl, | - | ||||||||||||||||||||||||
19 | .create = mem_new, | - | ||||||||||||||||||||||||
20 | .destroy = mem_free | - | ||||||||||||||||||||||||
21 | }; | - | ||||||||||||||||||||||||
22 | - | |||||||||||||||||||||||||
23 | - | |||||||||||||||||||||||||
24 | - | |||||||||||||||||||||||||
25 | - | |||||||||||||||||||||||||
26 | const BIO_METHOD * | - | ||||||||||||||||||||||||
27 | BIO_s_mem(void) | - | ||||||||||||||||||||||||
28 | { | - | ||||||||||||||||||||||||
29 | return executed 424 times by 8 tests: (&mem_method);return (&mem_method); Executed by:
executed 424 times by 8 tests: return (&mem_method); Executed by:
| 424 | ||||||||||||||||||||||||
30 | } | - | ||||||||||||||||||||||||
31 | - | |||||||||||||||||||||||||
32 | BIO * | - | ||||||||||||||||||||||||
33 | BIO_new_mem_buf(const void *buf, int len) | - | ||||||||||||||||||||||||
34 | { | - | ||||||||||||||||||||||||
35 | BIO *ret; | - | ||||||||||||||||||||||||
36 | BUF_MEM *b; | - | ||||||||||||||||||||||||
37 | size_t sz; | - | ||||||||||||||||||||||||
38 | - | |||||||||||||||||||||||||
39 | if (!buf
| 0-137 | ||||||||||||||||||||||||
40 | ERR_put_error(32,(0xfff),(115),__FILE__,104); | - | ||||||||||||||||||||||||
41 | return never executed: return ((void *)0) ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
42 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
43 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
44 | } | - | ||||||||||||||||||||||||
45 | sz = (
| 1-136 | ||||||||||||||||||||||||
46 | if (!(ret = BIO_new(BIO_s_mem()))
| 0-137 | ||||||||||||||||||||||||
47 | return never executed: return ((void *)0) ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
48 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
49 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
50 | b = (BUF_MEM *)ret->ptr; | - | ||||||||||||||||||||||||
51 | b->data = (void *)buf; | - | ||||||||||||||||||||||||
52 | b->length = sz; | - | ||||||||||||||||||||||||
53 | b->max = sz; | - | ||||||||||||||||||||||||
54 | ret->flags |= 0x200; | - | ||||||||||||||||||||||||
55 | - | |||||||||||||||||||||||||
56 | ret->num = 0; | - | ||||||||||||||||||||||||
57 | return executed 137 times by 7 tests: ret;return ret; Executed by:
executed 137 times by 7 tests: return ret; Executed by:
| 137 | ||||||||||||||||||||||||
58 | } | - | ||||||||||||||||||||||||
59 | - | |||||||||||||||||||||||||
60 | static int | - | ||||||||||||||||||||||||
61 | mem_new(BIO *bi) | - | ||||||||||||||||||||||||
62 | { | - | ||||||||||||||||||||||||
63 | BUF_MEM *b; | - | ||||||||||||||||||||||||
64 | - | |||||||||||||||||||||||||
65 | if ((
| 0-424 | ||||||||||||||||||||||||
66 | ((void *)0)
| 0-424 | ||||||||||||||||||||||||
67 | ) | - | ||||||||||||||||||||||||
68 | return never executed: (0);return (0); never executed: return (0); | 0 | ||||||||||||||||||||||||
69 | bi->shutdown = 1; | - | ||||||||||||||||||||||||
70 | bi->init = 1; | - | ||||||||||||||||||||||||
71 | bi->num = -1; | - | ||||||||||||||||||||||||
72 | bi->ptr = (char *)b; | - | ||||||||||||||||||||||||
73 | return executed 424 times by 8 tests: (1);return (1); Executed by:
executed 424 times by 8 tests: return (1); Executed by:
| 424 | ||||||||||||||||||||||||
74 | } | - | ||||||||||||||||||||||||
75 | - | |||||||||||||||||||||||||
76 | static int | - | ||||||||||||||||||||||||
77 | mem_free(BIO *a) | - | ||||||||||||||||||||||||
78 | { | - | ||||||||||||||||||||||||
79 | if (a ==
| 0-421 | ||||||||||||||||||||||||
80 | ((void *)0)
| 0-421 | ||||||||||||||||||||||||
81 | ) | - | ||||||||||||||||||||||||
82 | return never executed: (0);return (0); never executed: return (0); | 0 | ||||||||||||||||||||||||
83 | if (a->shutdown
| 0-421 | ||||||||||||||||||||||||
84 | if ((
| 0-421 | ||||||||||||||||||||||||
85 | ((void *)0)
| 0-421 | ||||||||||||||||||||||||
86 | )
| 0-421 | ||||||||||||||||||||||||
87 | BUF_MEM *b; | - | ||||||||||||||||||||||||
88 | b = (BUF_MEM *)a->ptr; | - | ||||||||||||||||||||||||
89 | if (a->flags & 0x200
| 137-284 | ||||||||||||||||||||||||
90 | b->data = executed 137 times by 7 tests: b->data = ((void *)0) ; Executed by:
| 137 | ||||||||||||||||||||||||
91 | ((void *)0) executed 137 times by 7 tests: b->data = ((void *)0) ; Executed by:
| 137 | ||||||||||||||||||||||||
92 | ; executed 137 times by 7 tests: b->data = ((void *)0) ; Executed by:
| 137 | ||||||||||||||||||||||||
93 | BUF_MEM_free(b); | - | ||||||||||||||||||||||||
94 | a->ptr = | - | ||||||||||||||||||||||||
95 | ((void *)0) | - | ||||||||||||||||||||||||
96 | ; | - | ||||||||||||||||||||||||
97 | } executed 421 times by 8 tests: end of block Executed by:
| 421 | ||||||||||||||||||||||||
98 | } executed 421 times by 8 tests: end of block Executed by:
| 421 | ||||||||||||||||||||||||
99 | return executed 421 times by 8 tests: (1);return (1); Executed by:
executed 421 times by 8 tests: return (1); Executed by:
| 421 | ||||||||||||||||||||||||
100 | } | - | ||||||||||||||||||||||||
101 | - | |||||||||||||||||||||||||
102 | static int | - | ||||||||||||||||||||||||
103 | mem_read(BIO *b, char *out, int outl) | - | ||||||||||||||||||||||||
104 | { | - | ||||||||||||||||||||||||
105 | int ret = -1; | - | ||||||||||||||||||||||||
106 | BUF_MEM *bm; | - | ||||||||||||||||||||||||
107 | - | |||||||||||||||||||||||||
108 | bm = (BUF_MEM *)b->ptr; | - | ||||||||||||||||||||||||
109 | BIO_clear_flags(b, ((0x01|0x02|0x04)|0x08)); | - | ||||||||||||||||||||||||
110 | ret = (outl >=0
| 0-2211 | ||||||||||||||||||||||||
111 | if ((
| 0-2211 | ||||||||||||||||||||||||
112 | ((void *)0)
| 0-2211 | ||||||||||||||||||||||||
113 | )
| 0-2211 | ||||||||||||||||||||||||
114 | memcpy(out, bm->data, ret); | - | ||||||||||||||||||||||||
115 | bm->length -= ret; | - | ||||||||||||||||||||||||
116 | if (b->flags & 0x200
| 907-1056 | ||||||||||||||||||||||||
117 | bm->data += ret; executed 907 times by 7 tests: bm->data += ret; Executed by:
| 907 | ||||||||||||||||||||||||
118 | else { | - | ||||||||||||||||||||||||
119 | memmove(&(bm->data[0]), &(bm->data[ret]), bm->length); | - | ||||||||||||||||||||||||
120 | } executed 1056 times by 2 tests: end of block Executed by:
| 1056 | ||||||||||||||||||||||||
121 | } else if (bm->length == 0
| 0-248 | ||||||||||||||||||||||||
122 | ret = b->num; | - | ||||||||||||||||||||||||
123 | if (ret != 0
| 108-140 | ||||||||||||||||||||||||
124 | BIO_set_flags(b, (0x01|0x08)); executed 140 times by 1 test: BIO_set_flags(b, (0x01|0x08)); Executed by:
| 140 | ||||||||||||||||||||||||
125 | } executed 248 times by 5 tests: end of block Executed by:
| 248 | ||||||||||||||||||||||||
126 | return executed 2211 times by 8 tests: (ret);return (ret); Executed by:
executed 2211 times by 8 tests: return (ret); Executed by:
| 2211 | ||||||||||||||||||||||||
127 | } | - | ||||||||||||||||||||||||
128 | - | |||||||||||||||||||||||||
129 | static int | - | ||||||||||||||||||||||||
130 | mem_write(BIO *b, const char *in, int inl) | - | ||||||||||||||||||||||||
131 | { | - | ||||||||||||||||||||||||
132 | int ret = -1; | - | ||||||||||||||||||||||||
133 | int blen; | - | ||||||||||||||||||||||||
134 | BUF_MEM *bm; | - | ||||||||||||||||||||||||
135 | - | |||||||||||||||||||||||||
136 | bm = (BUF_MEM *)b->ptr; | - | ||||||||||||||||||||||||
137 | if (in ==
| 0-708 | ||||||||||||||||||||||||
138 | ((void *)0)
| 0-708 | ||||||||||||||||||||||||
139 | ) { | - | ||||||||||||||||||||||||
140 | ERR_put_error(32,(0xfff),(115),__FILE__,186); | - | ||||||||||||||||||||||||
141 | goto never executed: end;goto end; never executed: goto end; | 0 | ||||||||||||||||||||||||
142 | } | - | ||||||||||||||||||||||||
143 | - | |||||||||||||||||||||||||
144 | if (b->flags & 0x200
| 0-708 | ||||||||||||||||||||||||
145 | ERR_put_error(32,(0xfff),(126),__FILE__,191); | - | ||||||||||||||||||||||||
146 | goto never executed: end;goto end; never executed: goto end; | 0 | ||||||||||||||||||||||||
147 | } | - | ||||||||||||||||||||||||
148 | - | |||||||||||||||||||||||||
149 | BIO_clear_flags(b, ((0x01|0x02|0x04)|0x08)); | - | ||||||||||||||||||||||||
150 | blen = bm->length; | - | ||||||||||||||||||||||||
151 | if (BUF_MEM_grow_clean(bm, blen + inl) != (blen + inl)
| 0-708 | ||||||||||||||||||||||||
152 | goto never executed: end;goto end; never executed: goto end; | 0 | ||||||||||||||||||||||||
153 | memcpy(&(bm->data[blen]), in, inl); | - | ||||||||||||||||||||||||
154 | ret = inl; | - | ||||||||||||||||||||||||
155 | end: code before this statement executed 708 times by 6 tests: end: Executed by:
| 708 | ||||||||||||||||||||||||
156 | return executed 708 times by 6 tests: (ret);return (ret); Executed by:
executed 708 times by 6 tests: return (ret); Executed by:
| 708 | ||||||||||||||||||||||||
157 | } | - | ||||||||||||||||||||||||
158 | - | |||||||||||||||||||||||||
159 | static long | - | ||||||||||||||||||||||||
160 | mem_ctrl(BIO *b, int cmd, long num, void *ptr) | - | ||||||||||||||||||||||||
161 | { | - | ||||||||||||||||||||||||
162 | long ret = 1; | - | ||||||||||||||||||||||||
163 | char **pptr; | - | ||||||||||||||||||||||||
164 | - | |||||||||||||||||||||||||
165 | BUF_MEM *bm = (BUF_MEM *)b->ptr; | - | ||||||||||||||||||||||||
166 | - | |||||||||||||||||||||||||
167 | switch (cmd) { | - | ||||||||||||||||||||||||
168 | case executed 4 times by 1 test: 1:case 1: Executed by:
executed 4 times by 1 test: case 1: Executed by:
| 4 | ||||||||||||||||||||||||
169 | if (bm->data !=
| 0-4 | ||||||||||||||||||||||||
170 | ((void *)0)
| 0-4 | ||||||||||||||||||||||||
171 | ) { | - | ||||||||||||||||||||||||
172 | - | |||||||||||||||||||||||||
173 | if (b->flags & 0x200
| 0-4 | ||||||||||||||||||||||||
174 | bm->data -= bm->max - bm->length; | - | ||||||||||||||||||||||||
175 | bm->length = bm->max; | - | ||||||||||||||||||||||||
176 | } executed 4 times by 1 test: else {end of block Executed by:
| 4 | ||||||||||||||||||||||||
177 | memset(bm->data, 0, bm->max); | - | ||||||||||||||||||||||||
178 | bm->length = 0; | - | ||||||||||||||||||||||||
179 | } never executed: end of block | 0 | ||||||||||||||||||||||||
180 | } | - | ||||||||||||||||||||||||
181 | break; executed 4 times by 1 test: break; Executed by:
| 4 | ||||||||||||||||||||||||
182 | case never executed: 2:case 2: never executed: case 2: | 0 | ||||||||||||||||||||||||
183 | ret = (long)(bm->length == 0); | - | ||||||||||||||||||||||||
184 | break; never executed: break; | 0 | ||||||||||||||||||||||||
185 | case executed 4 times by 1 test: 130:case 130: Executed by:
executed 4 times by 1 test: case 130: Executed by:
| 4 | ||||||||||||||||||||||||
186 | b->num = (int)num; | - | ||||||||||||||||||||||||
187 | break; executed 4 times by 1 test: break; Executed by:
| 4 | ||||||||||||||||||||||||
188 | case executed 336 times by 6 tests: 3:case 3: Executed by:
executed 336 times by 6 tests: case 3: Executed by:
| 336 | ||||||||||||||||||||||||
189 | ret = (long)bm->length; | - | ||||||||||||||||||||||||
190 | if (ptr !=
| 0-336 | ||||||||||||||||||||||||
191 | ((void *)0)
| 0-336 | ||||||||||||||||||||||||
192 | ) { | - | ||||||||||||||||||||||||
193 | pptr = (char **)ptr; | - | ||||||||||||||||||||||||
194 | *pptr = (char *)&(bm->data[0]); | - | ||||||||||||||||||||||||
195 | } executed 336 times by 6 tests: end of block Executed by:
| 336 | ||||||||||||||||||||||||
196 | break; executed 336 times by 6 tests: break; Executed by:
| 336 | ||||||||||||||||||||||||
197 | case never executed: 114:case 114: never executed: case 114: | 0 | ||||||||||||||||||||||||
198 | mem_free(b); | - | ||||||||||||||||||||||||
199 | b->shutdown = (int)num; | - | ||||||||||||||||||||||||
200 | b->ptr = ptr; | - | ||||||||||||||||||||||||
201 | break; never executed: break; | 0 | ||||||||||||||||||||||||
202 | case executed 4 times by 1 test: 115:case 115: Executed by:
executed 4 times by 1 test: case 115: Executed by:
| 4 | ||||||||||||||||||||||||
203 | if (ptr !=
| 0-4 | ||||||||||||||||||||||||
204 | ((void *)0)
| 0-4 | ||||||||||||||||||||||||
205 | ) { | - | ||||||||||||||||||||||||
206 | pptr = (char **)ptr; | - | ||||||||||||||||||||||||
207 | *pptr = (char *)bm; | - | ||||||||||||||||||||||||
208 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||
209 | break; executed 4 times by 1 test: break; Executed by:
| 4 | ||||||||||||||||||||||||
210 | case never executed: 8:case 8: never executed: case 8: | 0 | ||||||||||||||||||||||||
211 | ret = (long)b->shutdown; | - | ||||||||||||||||||||||||
212 | break; never executed: break; | 0 | ||||||||||||||||||||||||
213 | case executed 139 times by 4 tests: 9:case 9: Executed by:
executed 139 times by 4 tests: case 9: Executed by:
| 139 | ||||||||||||||||||||||||
214 | b->shutdown = (int)num; | - | ||||||||||||||||||||||||
215 | break; executed 139 times by 4 tests: break; Executed by:
| 139 | ||||||||||||||||||||||||
216 | - | |||||||||||||||||||||||||
217 | case executed 45 times by 2 tests: 13:case 13: Executed by:
executed 45 times by 2 tests: case 13: Executed by:
| 45 | ||||||||||||||||||||||||
218 | ret = 0L; | - | ||||||||||||||||||||||||
219 | break; executed 45 times by 2 tests: break; Executed by:
| 45 | ||||||||||||||||||||||||
220 | case executed 560 times by 1 test: 10:case 10: Executed by:
executed 560 times by 1 test: case 10: Executed by:
| 560 | ||||||||||||||||||||||||
221 | ret = (long)bm->length; | - | ||||||||||||||||||||||||
222 | break; executed 560 times by 1 test: break; Executed by:
| 560 | ||||||||||||||||||||||||
223 | case never executed: 12:case 12: never executed: case 12: | 0 | ||||||||||||||||||||||||
224 | case executed 175 times by 4 tests: 11:case 11: Executed by:
executed 175 times by 4 tests: case 11: Executed by:
| 175 | ||||||||||||||||||||||||
225 | ret = 1; | - | ||||||||||||||||||||||||
226 | break; executed 175 times by 4 tests: break; Executed by:
| 175 | ||||||||||||||||||||||||
227 | case executed 243 times by 5 tests: 6:case 6: Executed by:
executed 243 times by 5 tests: case 6: Executed by:
| 243 | ||||||||||||||||||||||||
228 | case executed 85 times by 4 tests: 7:case 7: Executed by:
executed 85 times by 4 tests: case 7: Executed by:
| 85 | ||||||||||||||||||||||||
229 | default executed 189 times by 2 tests: :default: Executed by:
executed 189 times by 2 tests: default: Executed by:
| 189 | ||||||||||||||||||||||||
230 | ret = 0; | - | ||||||||||||||||||||||||
231 | break; executed 517 times by 5 tests: break; Executed by:
| 517 | ||||||||||||||||||||||||
232 | } | - | ||||||||||||||||||||||||
233 | return executed 1784 times by 6 tests: (ret);return (ret); Executed by:
executed 1784 times by 6 tests: return (ret); Executed by:
| 1784 | ||||||||||||||||||||||||
234 | } | - | ||||||||||||||||||||||||
235 | - | |||||||||||||||||||||||||
236 | static int | - | ||||||||||||||||||||||||
237 | mem_gets(BIO *bp, char *buf, int size) | - | ||||||||||||||||||||||||
238 | { | - | ||||||||||||||||||||||||
239 | int i, j; | - | ||||||||||||||||||||||||
240 | int ret = -1; | - | ||||||||||||||||||||||||
241 | char *p; | - | ||||||||||||||||||||||||
242 | BUF_MEM *bm = (BUF_MEM *)bp->ptr; | - | ||||||||||||||||||||||||
243 | - | |||||||||||||||||||||||||
244 | BIO_clear_flags(bp, ((0x01|0x02|0x04)|0x08)); | - | ||||||||||||||||||||||||
245 | j = bm->length; | - | ||||||||||||||||||||||||
246 | if ((
| 113-817 | ||||||||||||||||||||||||
247 | j = size - 1; executed 817 times by 4 tests: j = size - 1; Executed by:
| 817 | ||||||||||||||||||||||||
248 | if (j <= 0
| 11-919 | ||||||||||||||||||||||||
249 | *buf = '\0'; | - | ||||||||||||||||||||||||
250 | return executed 11 times by 2 tests: 0;return 0; Executed by:
executed 11 times by 2 tests: return 0; Executed by:
| 11 | ||||||||||||||||||||||||
251 | } | - | ||||||||||||||||||||||||
252 | p = bm->data; | - | ||||||||||||||||||||||||
253 | for (i = 0; i < j
| 3-56923 | ||||||||||||||||||||||||
254 | if (p[i] == '\n'
| 916-56007 | ||||||||||||||||||||||||
255 | i++; | - | ||||||||||||||||||||||||
256 | break; executed 916 times by 4 tests: break; Executed by:
| 916 | ||||||||||||||||||||||||
257 | } | - | ||||||||||||||||||||||||
258 | } executed 56007 times by 4 tests: end of block Executed by:
| 56007 | ||||||||||||||||||||||||
259 | - | |||||||||||||||||||||||||
260 | - | |||||||||||||||||||||||||
261 | - | |||||||||||||||||||||||||
262 | - | |||||||||||||||||||||||||
263 | - | |||||||||||||||||||||||||
264 | - | |||||||||||||||||||||||||
265 | i = mem_read(bp, buf, i); | - | ||||||||||||||||||||||||
266 | if (i > 0
| 0-919 | ||||||||||||||||||||||||
267 | buf[i] = '\0'; executed 919 times by 4 tests: buf[i] = '\0'; Executed by:
| 919 | ||||||||||||||||||||||||
268 | ret = i; | - | ||||||||||||||||||||||||
269 | return executed 919 times by 4 tests: (ret);return (ret); Executed by:
executed 919 times by 4 tests: return (ret); Executed by:
| 919 | ||||||||||||||||||||||||
270 | } | - | ||||||||||||||||||||||||
271 | - | |||||||||||||||||||||||||
272 | static int | - | ||||||||||||||||||||||||
273 | mem_puts(BIO *bp, const char *str) | - | ||||||||||||||||||||||||
274 | { | - | ||||||||||||||||||||||||
275 | int n, ret; | - | ||||||||||||||||||||||||
276 | - | |||||||||||||||||||||||||
277 | n = strlen(str); | - | ||||||||||||||||||||||||
278 | ret = mem_write(bp, str, n); | - | ||||||||||||||||||||||||
279 | - | |||||||||||||||||||||||||
280 | return never executed: (ret);return (ret); never executed: return (ret); | 0 | ||||||||||||||||||||||||
281 | } | - | ||||||||||||||||||||||||
Switch to Source code | Preprocessed file |