Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/bio/bss_file.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||||||||
2 | - | |||||||||||||||||||||||||
3 | static int file_write(BIO *h, const char *buf, int num); | - | ||||||||||||||||||||||||
4 | static int file_read(BIO *h, char *buf, int size); | - | ||||||||||||||||||||||||
5 | static int file_puts(BIO *h, const char *str); | - | ||||||||||||||||||||||||
6 | static int file_gets(BIO *h, char *str, int size); | - | ||||||||||||||||||||||||
7 | static long file_ctrl(BIO *h, int cmd, long arg1, void *arg2); | - | ||||||||||||||||||||||||
8 | static int file_new(BIO *h); | - | ||||||||||||||||||||||||
9 | static int file_free(BIO *data); | - | ||||||||||||||||||||||||
10 | - | |||||||||||||||||||||||||
11 | static const BIO_METHOD methods_filep = { | - | ||||||||||||||||||||||||
12 | .type = (2|0x0400), | - | ||||||||||||||||||||||||
13 | .name = "FILE pointer", | - | ||||||||||||||||||||||||
14 | .bwrite = file_write, | - | ||||||||||||||||||||||||
15 | .bread = file_read, | - | ||||||||||||||||||||||||
16 | .bputs = file_puts, | - | ||||||||||||||||||||||||
17 | .bgets = file_gets, | - | ||||||||||||||||||||||||
18 | .ctrl = file_ctrl, | - | ||||||||||||||||||||||||
19 | .create = file_new, | - | ||||||||||||||||||||||||
20 | .destroy = file_free | - | ||||||||||||||||||||||||
21 | }; | - | ||||||||||||||||||||||||
22 | - | |||||||||||||||||||||||||
23 | BIO * | - | ||||||||||||||||||||||||
24 | BIO_new_file(const char *filename, const char *mode) | - | ||||||||||||||||||||||||
25 | { | - | ||||||||||||||||||||||||
26 | BIO *ret; | - | ||||||||||||||||||||||||
27 | FILE *file = | - | ||||||||||||||||||||||||
28 | ((void *)0) | - | ||||||||||||||||||||||||
29 | ; | - | ||||||||||||||||||||||||
30 | - | |||||||||||||||||||||||||
31 | file = fopen(filename, mode); | - | ||||||||||||||||||||||||
32 | - | |||||||||||||||||||||||||
33 | if (file ==
| 23-234 | ||||||||||||||||||||||||
34 | ((void *)0)
| 23-234 | ||||||||||||||||||||||||
35 | ) { | - | ||||||||||||||||||||||||
36 | ERR_put_error(2,(0xfff),( | - | ||||||||||||||||||||||||
37 | (*__errno_location ()) | - | ||||||||||||||||||||||||
38 | ),__FILE__,122); | - | ||||||||||||||||||||||||
39 | ERR_asprintf_error_data("fopen('%s', '%s')", filename, mode); | - | ||||||||||||||||||||||||
40 | if ( | - | ||||||||||||||||||||||||
41 | (*
| 0-234 | ||||||||||||||||||||||||
42 | ==
| 0-234 | ||||||||||||||||||||||||
43 | 2
| 0-234 | ||||||||||||||||||||||||
44 | ) | - | ||||||||||||||||||||||||
45 | ERR_put_error(32,(0xfff),(128),__FILE__,125); executed 234 times by 2 tests: ERR_put_error(32,(0xfff),(128),__FILE__,125); Executed by:
| 234 | ||||||||||||||||||||||||
46 | else | - | ||||||||||||||||||||||||
47 | ERR_put_error(32,(0xfff),(2),__FILE__,127); never executed: ERR_put_error(32,(0xfff),(2),__FILE__,127); | 0 | ||||||||||||||||||||||||
48 | return executed 234 times by 2 tests: (return ( ((void *)0) ); Executed by:
executed 234 times by 2 tests: return ( ((void *)0) ); Executed by:
| 234 | ||||||||||||||||||||||||
49 | ((void *)0) executed 234 times by 2 tests: return ( ((void *)0) ); Executed by:
| 234 | ||||||||||||||||||||||||
50 | ); executed 234 times by 2 tests: return ( ((void *)0) ); Executed by:
| 234 | ||||||||||||||||||||||||
51 | } | - | ||||||||||||||||||||||||
52 | if ((
| 0-23 | ||||||||||||||||||||||||
53 | ((void *)0)
| 0-23 | ||||||||||||||||||||||||
54 | ) { | - | ||||||||||||||||||||||||
55 | fclose(file); | - | ||||||||||||||||||||||||
56 | return never executed: (return ( ((void *)0) ); never executed: return ( ((void *)0) ); | 0 | ||||||||||||||||||||||||
57 | ((void *)0) never executed: return ( ((void *)0) ); | 0 | ||||||||||||||||||||||||
58 | ); never executed: return ( ((void *)0) ); | 0 | ||||||||||||||||||||||||
59 | } | - | ||||||||||||||||||||||||
60 | - | |||||||||||||||||||||||||
61 | BIO_ctrl(ret,106,0x01,(char *)file); | - | ||||||||||||||||||||||||
62 | return executed 23 times by 2 tests: (ret);return (ret); Executed by:
executed 23 times by 2 tests: return (ret); Executed by:
| 23 | ||||||||||||||||||||||||
63 | } | - | ||||||||||||||||||||||||
64 | - | |||||||||||||||||||||||||
65 | BIO * | - | ||||||||||||||||||||||||
66 | BIO_new_fp(FILE *stream, int close_flag) | - | ||||||||||||||||||||||||
67 | { | - | ||||||||||||||||||||||||
68 | BIO *ret; | - | ||||||||||||||||||||||||
69 | - | |||||||||||||||||||||||||
70 | if ((
| 0-322 | ||||||||||||||||||||||||
71 | ((void *)0)
| 0-322 | ||||||||||||||||||||||||
72 | ) | - | ||||||||||||||||||||||||
73 | return never executed: (return ( ((void *)0) ); never executed: return ( ((void *)0) ); | 0 | ||||||||||||||||||||||||
74 | ((void *)0) never executed: return ( ((void *)0) ); | 0 | ||||||||||||||||||||||||
75 | ); never executed: return ( ((void *)0) ); | 0 | ||||||||||||||||||||||||
76 | - | |||||||||||||||||||||||||
77 | BIO_ctrl(ret,106,close_flag,(char *)stream); | - | ||||||||||||||||||||||||
78 | return executed 322 times by 7 tests: (ret);return (ret); Executed by:
executed 322 times by 7 tests: return (ret); Executed by:
| 322 | ||||||||||||||||||||||||
79 | } | - | ||||||||||||||||||||||||
80 | - | |||||||||||||||||||||||||
81 | const BIO_METHOD * | - | ||||||||||||||||||||||||
82 | BIO_s_file(void) | - | ||||||||||||||||||||||||
83 | { | - | ||||||||||||||||||||||||
84 | return executed 948 times by 13 tests: (&methods_filep);return (&methods_filep); Executed by:
executed 948 times by 13 tests: return (&methods_filep); Executed by:
| 948 | ||||||||||||||||||||||||
85 | } | - | ||||||||||||||||||||||||
86 | - | |||||||||||||||||||||||||
87 | static int | - | ||||||||||||||||||||||||
88 | file_new(BIO *bi) | - | ||||||||||||||||||||||||
89 | { | - | ||||||||||||||||||||||||
90 | bi->init = 0; | - | ||||||||||||||||||||||||
91 | bi->num = 0; | - | ||||||||||||||||||||||||
92 | bi->ptr = | - | ||||||||||||||||||||||||
93 | ((void *)0) | - | ||||||||||||||||||||||||
94 | ; | - | ||||||||||||||||||||||||
95 | bi->flags=0; | - | ||||||||||||||||||||||||
96 | return executed 948 times by 13 tests: (1);return (1); Executed by:
executed 948 times by 13 tests: return (1); Executed by:
| 948 | ||||||||||||||||||||||||
97 | } | - | ||||||||||||||||||||||||
98 | - | |||||||||||||||||||||||||
99 | static int | - | ||||||||||||||||||||||||
100 | file_free(BIO *a) | - | ||||||||||||||||||||||||
101 | { | - | ||||||||||||||||||||||||
102 | if (a ==
| 0-1891 | ||||||||||||||||||||||||
103 | ((void *)0)
| 0-1891 | ||||||||||||||||||||||||
104 | ) | - | ||||||||||||||||||||||||
105 | return never executed: (0);return (0); never executed: return (0); | 0 | ||||||||||||||||||||||||
106 | if (a->shutdown
| 793-1098 | ||||||||||||||||||||||||
107 | if ((
| 0-948 | ||||||||||||||||||||||||
108 | ((void *)0)
| 0-150 | ||||||||||||||||||||||||
109 | )
| 0-150 | ||||||||||||||||||||||||
110 | fclose (a->ptr); | - | ||||||||||||||||||||||||
111 | a->ptr = | - | ||||||||||||||||||||||||
112 | ((void *)0) | - | ||||||||||||||||||||||||
113 | ; | - | ||||||||||||||||||||||||
114 | a->flags = 0; | - | ||||||||||||||||||||||||
115 | } executed 150 times by 3 tests: end of block Executed by:
| 150 | ||||||||||||||||||||||||
116 | a->init = 0; | - | ||||||||||||||||||||||||
117 | } executed 1098 times by 13 tests: end of block Executed by:
| 1098 | ||||||||||||||||||||||||
118 | return executed 1891 times by 13 tests: (1);return (1); Executed by:
executed 1891 times by 13 tests: return (1); Executed by:
| 1891 | ||||||||||||||||||||||||
119 | } | - | ||||||||||||||||||||||||
120 | - | |||||||||||||||||||||||||
121 | static int | - | ||||||||||||||||||||||||
122 | file_read(BIO *b, char *out, int outl) | - | ||||||||||||||||||||||||
123 | { | - | ||||||||||||||||||||||||
124 | int ret = 0; | - | ||||||||||||||||||||||||
125 | - | |||||||||||||||||||||||||
126 | if (b->init
| 0-548 | ||||||||||||||||||||||||
127 | ((void *)0)
| 0-548 | ||||||||||||||||||||||||
128 | ) { | - | ||||||||||||||||||||||||
129 | ret = fread(out, 1, outl, (FILE *)b->ptr); | - | ||||||||||||||||||||||||
130 | if (ret == 0
| 0-348 | ||||||||||||||||||||||||
131 | ERR_put_error(2,(0xfff),( | - | ||||||||||||||||||||||||
132 | (*__errno_location ()) | - | ||||||||||||||||||||||||
133 | ),__FILE__,191); | - | ||||||||||||||||||||||||
134 | ERR_put_error(32,(0xfff),(2),__FILE__,192); | - | ||||||||||||||||||||||||
135 | ret = -1; | - | ||||||||||||||||||||||||
136 | } never executed: end of block | 0 | ||||||||||||||||||||||||
137 | } executed 548 times by 1 test: end of block Executed by:
| 548 | ||||||||||||||||||||||||
138 | return executed 548 times by 1 test: (ret);return (ret); Executed by:
executed 548 times by 1 test: return (ret); Executed by:
| 548 | ||||||||||||||||||||||||
139 | } | - | ||||||||||||||||||||||||
140 | - | |||||||||||||||||||||||||
141 | static int | - | ||||||||||||||||||||||||
142 | file_write(BIO *b, const char *in, int inl) | - | ||||||||||||||||||||||||
143 | { | - | ||||||||||||||||||||||||
144 | int ret = 0; | - | ||||||||||||||||||||||||
145 | - | |||||||||||||||||||||||||
146 | if (b->init
| 0-805250 | ||||||||||||||||||||||||
147 | ((void *)0)
| 0-805250 | ||||||||||||||||||||||||
148 | ) | - | ||||||||||||||||||||||||
149 | ret = fwrite(in, 1, inl, (FILE *)b->ptr); executed 805250 times by 8 tests: ret = fwrite(in, 1, inl, (FILE *)b->ptr); Executed by:
| 805250 | ||||||||||||||||||||||||
150 | return executed 805250 times by 8 tests: (ret);return (ret); Executed by:
executed 805250 times by 8 tests: return (ret); Executed by:
| 805250 | ||||||||||||||||||||||||
151 | } | - | ||||||||||||||||||||||||
152 | - | |||||||||||||||||||||||||
153 | static long | - | ||||||||||||||||||||||||
154 | file_ctrl(BIO *b, int cmd, long num, void *ptr) | - | ||||||||||||||||||||||||
155 | { | - | ||||||||||||||||||||||||
156 | long ret = 1; | - | ||||||||||||||||||||||||
157 | FILE *fp = (FILE *)b->ptr; | - | ||||||||||||||||||||||||
158 | FILE **fpp; | - | ||||||||||||||||||||||||
159 | char p[4]; | - | ||||||||||||||||||||||||
160 | - | |||||||||||||||||||||||||
161 | switch (cmd) { | - | ||||||||||||||||||||||||
162 | case never executed: 128:case 128: never executed: case 128: | 0 | ||||||||||||||||||||||||
163 | case never executed: 1:case 1: never executed: case 1: | 0 | ||||||||||||||||||||||||
164 | ret = (long)fseek(fp, num, 0); | - | ||||||||||||||||||||||||
165 | break; never executed: break; | 0 | ||||||||||||||||||||||||
166 | case never executed: 2:case 2: never executed: case 2: | 0 | ||||||||||||||||||||||||
167 | ret = (long)feof(fp); | - | ||||||||||||||||||||||||
168 | break; never executed: break; | 0 | ||||||||||||||||||||||||
169 | case never executed: 133:case 133: never executed: case 133: | 0 | ||||||||||||||||||||||||
170 | case never executed: 3:case 3: never executed: case 3: | 0 | ||||||||||||||||||||||||
171 | ret = ftell(fp); | - | ||||||||||||||||||||||||
172 | break; never executed: break; | 0 | ||||||||||||||||||||||||
173 | case executed 820 times by 12 tests: 106:case 106: Executed by:
executed 820 times by 12 tests: case 106: Executed by:
| 820 | ||||||||||||||||||||||||
174 | file_free(b); | - | ||||||||||||||||||||||||
175 | b->shutdown = (int)num&0x01; | - | ||||||||||||||||||||||||
176 | b->ptr = ptr; | - | ||||||||||||||||||||||||
177 | b->init = 1; | - | ||||||||||||||||||||||||
178 | break; executed 820 times by 12 tests: break; Executed by:
| 820 | ||||||||||||||||||||||||
179 | case executed 127 times by 3 tests: 108:case 108: Executed by:
executed 127 times by 3 tests: case 108: Executed by:
| 127 | ||||||||||||||||||||||||
180 | file_free(b); | - | ||||||||||||||||||||||||
181 | b->shutdown = (int)num&0x01; | - | ||||||||||||||||||||||||
182 | if (num & 0x08
| 0-127 | ||||||||||||||||||||||||
183 | if (num & 0x02
| 0 | ||||||||||||||||||||||||
184 | strlcpy(p, "a+", sizeof p); never executed: strlcpy(p, "a+", sizeof p); | 0 | ||||||||||||||||||||||||
185 | else strlcpy(p, "a", sizeof p); never executed: strlcpy(p, "a", sizeof p); | 0 | ||||||||||||||||||||||||
186 | } else if ((
| 0-122 | ||||||||||||||||||||||||
187 | strlcpy(p, "r+", sizeof p); never executed: strlcpy(p, "r+", sizeof p); | 0 | ||||||||||||||||||||||||
188 | else if (num & 0x04
| 5-122 | ||||||||||||||||||||||||
189 | strlcpy(p, "w", sizeof p); executed 5 times by 1 test: strlcpy(p, "w", sizeof p); Executed by:
| 5 | ||||||||||||||||||||||||
190 | else if (num & 0x02
| 0-122 | ||||||||||||||||||||||||
191 | strlcpy(p, "r", sizeof p); executed 122 times by 3 tests: strlcpy(p, "r", sizeof p); Executed by:
| 122 | ||||||||||||||||||||||||
192 | else { | - | ||||||||||||||||||||||||
193 | ERR_put_error(32,(0xfff),(101),__FILE__,249); | - | ||||||||||||||||||||||||
194 | ret = 0; | - | ||||||||||||||||||||||||
195 | break; never executed: break; | 0 | ||||||||||||||||||||||||
196 | } | - | ||||||||||||||||||||||||
197 | fp = fopen(ptr, p); | - | ||||||||||||||||||||||||
198 | if (fp ==
| 0-127 | ||||||||||||||||||||||||
199 | ((void *)0)
| 0-127 | ||||||||||||||||||||||||
200 | ) { | - | ||||||||||||||||||||||||
201 | ERR_put_error(2,(0xfff),( | - | ||||||||||||||||||||||||
202 | (*__errno_location ()) | - | ||||||||||||||||||||||||
203 | ),__FILE__,255); | - | ||||||||||||||||||||||||
204 | ERR_asprintf_error_data("fopen('%s', '%s')", ptr, p); | - | ||||||||||||||||||||||||
205 | ERR_put_error(32,(0xfff),(2),__FILE__,257); | - | ||||||||||||||||||||||||
206 | ret = 0; | - | ||||||||||||||||||||||||
207 | break; never executed: break; | 0 | ||||||||||||||||||||||||
208 | } | - | ||||||||||||||||||||||||
209 | b->ptr = fp; | - | ||||||||||||||||||||||||
210 | b->init = 1; | - | ||||||||||||||||||||||||
211 | break; executed 127 times by 3 tests: break; Executed by:
| 127 | ||||||||||||||||||||||||
212 | case never executed: 107:case 107: never executed: case 107: | 0 | ||||||||||||||||||||||||
213 | - | |||||||||||||||||||||||||
214 | if (ptr !=
| 0 | ||||||||||||||||||||||||
215 | ((void *)0)
| 0 | ||||||||||||||||||||||||
216 | ) { | - | ||||||||||||||||||||||||
217 | fpp = (FILE **)ptr; | - | ||||||||||||||||||||||||
218 | *fpp = (FILE *)b->ptr; | - | ||||||||||||||||||||||||
219 | } never executed: end of block | 0 | ||||||||||||||||||||||||
220 | break; never executed: break; | 0 | ||||||||||||||||||||||||
221 | case never executed: 8:case 8: never executed: case 8: | 0 | ||||||||||||||||||||||||
222 | ret = (long)b->shutdown; | - | ||||||||||||||||||||||||
223 | break; never executed: break; | 0 | ||||||||||||||||||||||||
224 | case never executed: 9:case 9: never executed: case 9: | 0 | ||||||||||||||||||||||||
225 | b->shutdown = (int)num; | - | ||||||||||||||||||||||||
226 | break; never executed: break; | 0 | ||||||||||||||||||||||||
227 | case executed 1736 times by 7 tests: 11:case 11: Executed by:
executed 1736 times by 7 tests: case 11: Executed by:
| 1736 | ||||||||||||||||||||||||
228 | fflush((FILE *)b->ptr); | - | ||||||||||||||||||||||||
229 | break; executed 1736 times by 7 tests: break; Executed by:
| 1736 | ||||||||||||||||||||||||
230 | case never executed: 12:case 12: never executed: case 12: | 0 | ||||||||||||||||||||||||
231 | ret = 1; | - | ||||||||||||||||||||||||
232 | break; never executed: break; | 0 | ||||||||||||||||||||||||
233 | - | |||||||||||||||||||||||||
234 | case never executed: 13:case 13: never executed: case 13: | 0 | ||||||||||||||||||||||||
235 | case never executed: 10:case 10: never executed: case 10: | 0 | ||||||||||||||||||||||||
236 | case executed 296 times by 1 test: 6:case 6: Executed by:
executed 296 times by 1 test: case 6: Executed by:
| 296 | ||||||||||||||||||||||||
237 | case never executed: 7:case 7: never executed: case 7: | 0 | ||||||||||||||||||||||||
238 | default never executed: :default: never executed: default: | 0 | ||||||||||||||||||||||||
239 | ret = 0; | - | ||||||||||||||||||||||||
240 | break; executed 296 times by 1 test: break; Executed by:
| 296 | ||||||||||||||||||||||||
241 | } | - | ||||||||||||||||||||||||
242 | return executed 2979 times by 13 tests: (ret);return (ret); Executed by:
executed 2979 times by 13 tests: return (ret); Executed by:
| 2979 | ||||||||||||||||||||||||
243 | } | - | ||||||||||||||||||||||||
244 | - | |||||||||||||||||||||||||
245 | static int | - | ||||||||||||||||||||||||
246 | file_gets(BIO *bp, char *buf, int size) | - | ||||||||||||||||||||||||
247 | { | - | ||||||||||||||||||||||||
248 | int ret = 0; | - | ||||||||||||||||||||||||
249 | - | |||||||||||||||||||||||||
250 | buf[0] = '\0'; | - | ||||||||||||||||||||||||
251 | if (!fgets(buf, size,(FILE *)bp->ptr)
| 22-5473 | ||||||||||||||||||||||||
252 | goto executed 22 times by 2 tests: err;goto err; Executed by:
executed 22 times by 2 tests: goto err; Executed by:
| 22 | ||||||||||||||||||||||||
253 | if (buf[0] != '\0'
| 0-5473 | ||||||||||||||||||||||||
254 | ret = strlen(buf); executed 5473 times by 3 tests: ret = strlen(buf); Executed by:
| 5473 | ||||||||||||||||||||||||
255 | err: code before this statement executed 5473 times by 3 tests: err: Executed by:
| 5473 | ||||||||||||||||||||||||
256 | return executed 5495 times by 3 tests: (ret);return (ret); Executed by:
executed 5495 times by 3 tests: return (ret); Executed by:
| 5495 | ||||||||||||||||||||||||
257 | } | - | ||||||||||||||||||||||||
258 | - | |||||||||||||||||||||||||
259 | static int | - | ||||||||||||||||||||||||
260 | file_puts(BIO *bp, const char *str) | - | ||||||||||||||||||||||||
261 | { | - | ||||||||||||||||||||||||
262 | int n, ret; | - | ||||||||||||||||||||||||
263 | - | |||||||||||||||||||||||||
264 | n = strlen(str); | - | ||||||||||||||||||||||||
265 | ret = file_write(bp, str, n); | - | ||||||||||||||||||||||||
266 | return executed 9012 times by 5 tests: (ret);return (ret); Executed by:
executed 9012 times by 5 tests: return (ret); Executed by:
| 9012 | ||||||||||||||||||||||||
267 | } | - | ||||||||||||||||||||||||
Switch to Source code | Preprocessed file |