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