Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/bio/bf_nbio.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||
2 | - | |||||||||||||||||||
3 | - | |||||||||||||||||||
4 | - | |||||||||||||||||||
5 | - | |||||||||||||||||||
6 | static int nbiof_write(BIO *h, const char *buf, int num); | - | ||||||||||||||||||
7 | static int nbiof_read(BIO *h, char *buf, int size); | - | ||||||||||||||||||
8 | static int nbiof_puts(BIO *h, const char *str); | - | ||||||||||||||||||
9 | static int nbiof_gets(BIO *h, char *str, int size); | - | ||||||||||||||||||
10 | static long nbiof_ctrl(BIO *h, int cmd, long arg1, void *arg2); | - | ||||||||||||||||||
11 | static int nbiof_new(BIO *h); | - | ||||||||||||||||||
12 | static int nbiof_free(BIO *data); | - | ||||||||||||||||||
13 | static long nbiof_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); | - | ||||||||||||||||||
14 | - | |||||||||||||||||||
15 | typedef struct nbio_test_st { | - | ||||||||||||||||||
16 | - | |||||||||||||||||||
17 | int lrn; | - | ||||||||||||||||||
18 | int lwn; | - | ||||||||||||||||||
19 | } NBIO_TEST; | - | ||||||||||||||||||
20 | - | |||||||||||||||||||
21 | static const BIO_METHOD methods_nbiof = { | - | ||||||||||||||||||
22 | .type = (16|0x0200), | - | ||||||||||||||||||
23 | .name = "non-blocking IO test filter", | - | ||||||||||||||||||
24 | .bwrite = nbiof_write, | - | ||||||||||||||||||
25 | .bread = nbiof_read, | - | ||||||||||||||||||
26 | .bputs = nbiof_puts, | - | ||||||||||||||||||
27 | .bgets = nbiof_gets, | - | ||||||||||||||||||
28 | .ctrl = nbiof_ctrl, | - | ||||||||||||||||||
29 | .create = nbiof_new, | - | ||||||||||||||||||
30 | .destroy = nbiof_free, | - | ||||||||||||||||||
31 | .callback_ctrl = nbiof_callback_ctrl | - | ||||||||||||||||||
32 | }; | - | ||||||||||||||||||
33 | - | |||||||||||||||||||
34 | const BIO_METHOD * | - | ||||||||||||||||||
35 | BIO_f_nbio_test(void) | - | ||||||||||||||||||
36 | { | - | ||||||||||||||||||
37 | return never executed: (&methods_nbiof);return (&methods_nbiof); never executed: return (&methods_nbiof); | 0 | ||||||||||||||||||
38 | } | - | ||||||||||||||||||
39 | - | |||||||||||||||||||
40 | static int | - | ||||||||||||||||||
41 | nbiof_new(BIO *bi) | - | ||||||||||||||||||
42 | { | - | ||||||||||||||||||
43 | NBIO_TEST *nt; | - | ||||||||||||||||||
44 | - | |||||||||||||||||||
45 | if (!(nt = malloc(sizeof(NBIO_TEST)))
| 0 | ||||||||||||||||||
46 | return never executed: (0);return (0); never executed: return (0); | 0 | ||||||||||||||||||
47 | nt->lrn = -1; | - | ||||||||||||||||||
48 | nt->lwn = -1; | - | ||||||||||||||||||
49 | bi->ptr = (char *)nt; | - | ||||||||||||||||||
50 | bi->init = 1; | - | ||||||||||||||||||
51 | bi->flags = 0; | - | ||||||||||||||||||
52 | return never executed: (1);return (1); never executed: return (1); | 0 | ||||||||||||||||||
53 | } | - | ||||||||||||||||||
54 | - | |||||||||||||||||||
55 | static int | - | ||||||||||||||||||
56 | nbiof_free(BIO *a) | - | ||||||||||||||||||
57 | { | - | ||||||||||||||||||
58 | if (a ==
| 0 | ||||||||||||||||||
59 | ((void *)0)
| 0 | ||||||||||||||||||
60 | ) | - | ||||||||||||||||||
61 | return never executed: (0);return (0); never executed: return (0); | 0 | ||||||||||||||||||
62 | free(a->ptr); | - | ||||||||||||||||||
63 | a->ptr = | - | ||||||||||||||||||
64 | ((void *)0) | - | ||||||||||||||||||
65 | ; | - | ||||||||||||||||||
66 | a->init = 0; | - | ||||||||||||||||||
67 | a->flags = 0; | - | ||||||||||||||||||
68 | return never executed: (1);return (1); never executed: return (1); | 0 | ||||||||||||||||||
69 | } | - | ||||||||||||||||||
70 | - | |||||||||||||||||||
71 | static int | - | ||||||||||||||||||
72 | nbiof_read(BIO *b, char *out, int outl) | - | ||||||||||||||||||
73 | { | - | ||||||||||||||||||
74 | int ret = 0; | - | ||||||||||||||||||
75 | int num; | - | ||||||||||||||||||
76 | unsigned char n; | - | ||||||||||||||||||
77 | - | |||||||||||||||||||
78 | if (out ==
| 0 | ||||||||||||||||||
79 | ((void *)0)
| 0 | ||||||||||||||||||
80 | ) | - | ||||||||||||||||||
81 | return never executed: (0);return (0); never executed: return (0); | 0 | ||||||||||||||||||
82 | if (b->next_bio ==
| 0 | ||||||||||||||||||
83 | ((void *)0)
| 0 | ||||||||||||||||||
84 | ) | - | ||||||||||||||||||
85 | return never executed: (0);return (0); never executed: return (0); | 0 | ||||||||||||||||||
86 | - | |||||||||||||||||||
87 | BIO_clear_flags(b, ((0x01|0x02|0x04)|0x08)); | - | ||||||||||||||||||
88 | - | |||||||||||||||||||
89 | arc4random_buf(&n, 1); | - | ||||||||||||||||||
90 | num = (n & 0x07); | - | ||||||||||||||||||
91 | - | |||||||||||||||||||
92 | if (outl > num
| 0 | ||||||||||||||||||
93 | outl = num; never executed: outl = num; | 0 | ||||||||||||||||||
94 | - | |||||||||||||||||||
95 | if (num == 0
| 0 | ||||||||||||||||||
96 | ret = -1; | - | ||||||||||||||||||
97 | BIO_set_flags(b, (0x01|0x08)); | - | ||||||||||||||||||
98 | } never executed: else {end of block | 0 | ||||||||||||||||||
99 | ret = BIO_read(b->next_bio, out, outl); | - | ||||||||||||||||||
100 | if (ret < 0
| 0 | ||||||||||||||||||
101 | BIO_copy_next_retry(b); never executed: BIO_copy_next_retry(b); | 0 | ||||||||||||||||||
102 | } never executed: end of block | 0 | ||||||||||||||||||
103 | return never executed: (ret);return (ret); never executed: return (ret); | 0 | ||||||||||||||||||
104 | } | - | ||||||||||||||||||
105 | - | |||||||||||||||||||
106 | static int | - | ||||||||||||||||||
107 | nbiof_write(BIO *b, const char *in, int inl) | - | ||||||||||||||||||
108 | { | - | ||||||||||||||||||
109 | NBIO_TEST *nt; | - | ||||||||||||||||||
110 | int ret = 0; | - | ||||||||||||||||||
111 | int num; | - | ||||||||||||||||||
112 | unsigned char n; | - | ||||||||||||||||||
113 | - | |||||||||||||||||||
114 | if ((
| 0 | ||||||||||||||||||
115 | ((void *)0)
| 0 | ||||||||||||||||||
116 | )
| 0 | ||||||||||||||||||
117 | return never executed: (0);return (0); never executed: return (0); | 0 | ||||||||||||||||||
118 | if (b->next_bio ==
| 0 | ||||||||||||||||||
119 | ((void *)0)
| 0 | ||||||||||||||||||
120 | ) | - | ||||||||||||||||||
121 | return never executed: (0);return (0); never executed: return (0); | 0 | ||||||||||||||||||
122 | nt = (NBIO_TEST *)b->ptr; | - | ||||||||||||||||||
123 | - | |||||||||||||||||||
124 | BIO_clear_flags(b, ((0x01|0x02|0x04)|0x08)); | - | ||||||||||||||||||
125 | - | |||||||||||||||||||
126 | if (nt->lwn > 0
| 0 | ||||||||||||||||||
127 | num = nt->lwn; | - | ||||||||||||||||||
128 | nt->lwn = 0; | - | ||||||||||||||||||
129 | } never executed: else {end of block | 0 | ||||||||||||||||||
130 | arc4random_buf(&n, 1); | - | ||||||||||||||||||
131 | num = (n&7); | - | ||||||||||||||||||
132 | } never executed: end of block | 0 | ||||||||||||||||||
133 | - | |||||||||||||||||||
134 | if (inl > num
| 0 | ||||||||||||||||||
135 | inl = num; never executed: inl = num; | 0 | ||||||||||||||||||
136 | - | |||||||||||||||||||
137 | if (num == 0
| 0 | ||||||||||||||||||
138 | ret = -1; | - | ||||||||||||||||||
139 | BIO_set_flags(b, (0x02|0x08)); | - | ||||||||||||||||||
140 | } never executed: else {end of block | 0 | ||||||||||||||||||
141 | ret = BIO_write(b->next_bio, in, inl); | - | ||||||||||||||||||
142 | if (ret < 0
| 0 | ||||||||||||||||||
143 | BIO_copy_next_retry(b); | - | ||||||||||||||||||
144 | nt->lwn = inl; | - | ||||||||||||||||||
145 | } never executed: end of block | 0 | ||||||||||||||||||
146 | } never executed: end of block | 0 | ||||||||||||||||||
147 | return never executed: (ret);return (ret); never executed: return (ret); | 0 | ||||||||||||||||||
148 | } | - | ||||||||||||||||||
149 | - | |||||||||||||||||||
150 | static long | - | ||||||||||||||||||
151 | nbiof_ctrl(BIO *b, int cmd, long num, void *ptr) | - | ||||||||||||||||||
152 | { | - | ||||||||||||||||||
153 | long ret; | - | ||||||||||||||||||
154 | - | |||||||||||||||||||
155 | if (b->next_bio ==
| 0 | ||||||||||||||||||
156 | ((void *)0)
| 0 | ||||||||||||||||||
157 | ) | - | ||||||||||||||||||
158 | return never executed: (0);return (0); never executed: return (0); | 0 | ||||||||||||||||||
159 | switch (cmd) { | - | ||||||||||||||||||
160 | case never executed: 101:case 101: never executed: case 101: | 0 | ||||||||||||||||||
161 | BIO_clear_flags(b, ((0x01|0x02|0x04)|0x08)); | - | ||||||||||||||||||
162 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | - | ||||||||||||||||||
163 | BIO_copy_next_retry(b); | - | ||||||||||||||||||
164 | break; never executed: break; | 0 | ||||||||||||||||||
165 | case never executed: 12:case 12: never executed: case 12: | 0 | ||||||||||||||||||
166 | ret = 0L; | - | ||||||||||||||||||
167 | break; never executed: break; | 0 | ||||||||||||||||||
168 | default never executed: :default: never executed: default: | 0 | ||||||||||||||||||
169 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | - | ||||||||||||||||||
170 | break; never executed: break; | 0 | ||||||||||||||||||
171 | } | - | ||||||||||||||||||
172 | return never executed: (ret);return (ret); never executed: return (ret); | 0 | ||||||||||||||||||
173 | } | - | ||||||||||||||||||
174 | - | |||||||||||||||||||
175 | static long | - | ||||||||||||||||||
176 | nbiof_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) | - | ||||||||||||||||||
177 | { | - | ||||||||||||||||||
178 | long ret = 1; | - | ||||||||||||||||||
179 | - | |||||||||||||||||||
180 | if (b->next_bio ==
| 0 | ||||||||||||||||||
181 | ((void *)0)
| 0 | ||||||||||||||||||
182 | ) | - | ||||||||||||||||||
183 | return never executed: (0);return (0); never executed: return (0); | 0 | ||||||||||||||||||
184 | switch (cmd) { | - | ||||||||||||||||||
185 | default never executed: :default: never executed: default: | 0 | ||||||||||||||||||
186 | ret = BIO_callback_ctrl(b->next_bio, cmd, fp); | - | ||||||||||||||||||
187 | break; never executed: break; | 0 | ||||||||||||||||||
188 | } | - | ||||||||||||||||||
189 | return never executed: (ret);return (ret); never executed: return (ret); | 0 | ||||||||||||||||||
190 | } | - | ||||||||||||||||||
191 | - | |||||||||||||||||||
192 | static int | - | ||||||||||||||||||
193 | nbiof_gets(BIO *bp, char *buf, int size) | - | ||||||||||||||||||
194 | { | - | ||||||||||||||||||
195 | if (bp->next_bio ==
| 0 | ||||||||||||||||||
196 | ((void *)0)
| 0 | ||||||||||||||||||
197 | ) | - | ||||||||||||||||||
198 | return never executed: (0);return (0); never executed: return (0); | 0 | ||||||||||||||||||
199 | return never executed: (BIO_gets(bp->next_bio, buf, size));return (BIO_gets(bp->next_bio, buf, size)); never executed: return (BIO_gets(bp->next_bio, buf, size)); | 0 | ||||||||||||||||||
200 | } | - | ||||||||||||||||||
201 | - | |||||||||||||||||||
202 | static int | - | ||||||||||||||||||
203 | nbiof_puts(BIO *bp, const char *str) | - | ||||||||||||||||||
204 | { | - | ||||||||||||||||||
205 | if (bp->next_bio ==
| 0 | ||||||||||||||||||
206 | ((void *)0)
| 0 | ||||||||||||||||||
207 | ) | - | ||||||||||||||||||
208 | return never executed: (0);return (0); never executed: return (0); | 0 | ||||||||||||||||||
209 | return never executed: (BIO_puts(bp->next_bio, str));return (BIO_puts(bp->next_bio, str)); never executed: return (BIO_puts(bp->next_bio, str)); | 0 | ||||||||||||||||||
210 | } | - | ||||||||||||||||||
Switch to Source code | Preprocessed file |