Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/dso/dso_lib.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* $OpenBSD: dso_lib.c,v 1.20 2018/08/24 19:27:01 tb Exp $ */ | - | ||||||||||||||||||||||||
2 | /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL | - | ||||||||||||||||||||||||
3 | * project 2000. | - | ||||||||||||||||||||||||
4 | */ | - | ||||||||||||||||||||||||
5 | /* ==================================================================== | - | ||||||||||||||||||||||||
6 | * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | - | ||||||||||||||||||||||||
7 | * | - | ||||||||||||||||||||||||
8 | * Redistribution and use in source and binary forms, with or without | - | ||||||||||||||||||||||||
9 | * modification, are permitted provided that the following conditions | - | ||||||||||||||||||||||||
10 | * are met: | - | ||||||||||||||||||||||||
11 | * | - | ||||||||||||||||||||||||
12 | * 1. Redistributions of source code must retain the above copyright | - | ||||||||||||||||||||||||
13 | * notice, this list of conditions and the following disclaimer. | - | ||||||||||||||||||||||||
14 | * | - | ||||||||||||||||||||||||
15 | * 2. Redistributions in binary form must reproduce the above copyright | - | ||||||||||||||||||||||||
16 | * notice, this list of conditions and the following disclaimer in | - | ||||||||||||||||||||||||
17 | * the documentation and/or other materials provided with the | - | ||||||||||||||||||||||||
18 | * distribution. | - | ||||||||||||||||||||||||
19 | * | - | ||||||||||||||||||||||||
20 | * 3. All advertising materials mentioning features or use of this | - | ||||||||||||||||||||||||
21 | * software must display the following acknowledgment: | - | ||||||||||||||||||||||||
22 | * "This product includes software developed by the OpenSSL Project | - | ||||||||||||||||||||||||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | - | ||||||||||||||||||||||||
24 | * | - | ||||||||||||||||||||||||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | - | ||||||||||||||||||||||||
26 | * endorse or promote products derived from this software without | - | ||||||||||||||||||||||||
27 | * prior written permission. For written permission, please contact | - | ||||||||||||||||||||||||
28 | * licensing@OpenSSL.org. | - | ||||||||||||||||||||||||
29 | * | - | ||||||||||||||||||||||||
30 | * 5. Products derived from this software may not be called "OpenSSL" | - | ||||||||||||||||||||||||
31 | * nor may "OpenSSL" appear in their names without prior written | - | ||||||||||||||||||||||||
32 | * permission of the OpenSSL Project. | - | ||||||||||||||||||||||||
33 | * | - | ||||||||||||||||||||||||
34 | * 6. Redistributions of any form whatsoever must retain the following | - | ||||||||||||||||||||||||
35 | * acknowledgment: | - | ||||||||||||||||||||||||
36 | * "This product includes software developed by the OpenSSL Project | - | ||||||||||||||||||||||||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | - | ||||||||||||||||||||||||
38 | * | - | ||||||||||||||||||||||||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | - | ||||||||||||||||||||||||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | - | ||||||||||||||||||||||||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | - | ||||||||||||||||||||||||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | - | ||||||||||||||||||||||||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | - | ||||||||||||||||||||||||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | - | ||||||||||||||||||||||||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | - | ||||||||||||||||||||||||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | - | ||||||||||||||||||||||||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | - | ||||||||||||||||||||||||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | - | ||||||||||||||||||||||||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | - | ||||||||||||||||||||||||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | - | ||||||||||||||||||||||||
51 | * ==================================================================== | - | ||||||||||||||||||||||||
52 | * | - | ||||||||||||||||||||||||
53 | * This product includes cryptographic software written by Eric Young | - | ||||||||||||||||||||||||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | - | ||||||||||||||||||||||||
55 | * Hudson (tjh@cryptsoft.com). | - | ||||||||||||||||||||||||
56 | * | - | ||||||||||||||||||||||||
57 | */ | - | ||||||||||||||||||||||||
58 | - | |||||||||||||||||||||||||
59 | #include <stdio.h> | - | ||||||||||||||||||||||||
60 | #include <string.h> | - | ||||||||||||||||||||||||
61 | - | |||||||||||||||||||||||||
62 | #include <openssl/crypto.h> | - | ||||||||||||||||||||||||
63 | #include <openssl/dso.h> | - | ||||||||||||||||||||||||
64 | #include <openssl/err.h> | - | ||||||||||||||||||||||||
65 | - | |||||||||||||||||||||||||
66 | static DSO_METHOD *default_DSO_meth = NULL; | - | ||||||||||||||||||||||||
67 | - | |||||||||||||||||||||||||
68 | DSO * | - | ||||||||||||||||||||||||
69 | DSO_new(void) | - | ||||||||||||||||||||||||
70 | { | - | ||||||||||||||||||||||||
71 | return (DSO_new_method(NULL)); never executed: return (DSO_new_method( ((void *)0) )); | 0 | ||||||||||||||||||||||||
72 | } | - | ||||||||||||||||||||||||
73 | - | |||||||||||||||||||||||||
74 | void | - | ||||||||||||||||||||||||
75 | DSO_set_default_method(DSO_METHOD *meth) | - | ||||||||||||||||||||||||
76 | { | - | ||||||||||||||||||||||||
77 | default_DSO_meth = meth; | - | ||||||||||||||||||||||||
78 | } never executed: end of block | 0 | ||||||||||||||||||||||||
79 | - | |||||||||||||||||||||||||
80 | DSO_METHOD * | - | ||||||||||||||||||||||||
81 | DSO_get_default_method(void) | - | ||||||||||||||||||||||||
82 | { | - | ||||||||||||||||||||||||
83 | return (default_DSO_meth); never executed: return (default_DSO_meth); | 0 | ||||||||||||||||||||||||
84 | } | - | ||||||||||||||||||||||||
85 | - | |||||||||||||||||||||||||
86 | DSO_METHOD * | - | ||||||||||||||||||||||||
87 | DSO_get_method(DSO *dso) | - | ||||||||||||||||||||||||
88 | { | - | ||||||||||||||||||||||||
89 | return (dso->meth); never executed: return (dso->meth); | 0 | ||||||||||||||||||||||||
90 | } | - | ||||||||||||||||||||||||
91 | - | |||||||||||||||||||||||||
92 | DSO_METHOD * | - | ||||||||||||||||||||||||
93 | DSO_set_method(DSO *dso, DSO_METHOD *meth) | - | ||||||||||||||||||||||||
94 | { | - | ||||||||||||||||||||||||
95 | DSO_METHOD *mtmp; | - | ||||||||||||||||||||||||
96 | - | |||||||||||||||||||||||||
97 | mtmp = dso->meth; | - | ||||||||||||||||||||||||
98 | dso->meth = meth; | - | ||||||||||||||||||||||||
99 | return (mtmp); never executed: return (mtmp); | 0 | ||||||||||||||||||||||||
100 | } | - | ||||||||||||||||||||||||
101 | - | |||||||||||||||||||||||||
102 | DSO * | - | ||||||||||||||||||||||||
103 | DSO_new_method(DSO_METHOD *meth) | - | ||||||||||||||||||||||||
104 | { | - | ||||||||||||||||||||||||
105 | DSO *ret; | - | ||||||||||||||||||||||||
106 | - | |||||||||||||||||||||||||
107 | if (default_DSO_meth == NULL)
| 0 | ||||||||||||||||||||||||
108 | /* We default to DSO_METH_openssl() which in turn defaults | - | ||||||||||||||||||||||||
109 | * to stealing the "best available" method. Will fallback | - | ||||||||||||||||||||||||
110 | * to DSO_METH_null() in the worst case. */ | - | ||||||||||||||||||||||||
111 | default_DSO_meth = DSO_METHOD_openssl(); never executed: default_DSO_meth = DSO_METHOD_openssl(); | 0 | ||||||||||||||||||||||||
112 | ret = calloc(1, sizeof(DSO)); | - | ||||||||||||||||||||||||
113 | if (ret == NULL) {
| 0 | ||||||||||||||||||||||||
114 | DSOerror(ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
115 | return (NULL); never executed: return ( ((void *)0) ); | 0 | ||||||||||||||||||||||||
116 | } | - | ||||||||||||||||||||||||
117 | ret->meth_data = sk_void_new_null(); | - | ||||||||||||||||||||||||
118 | if (ret->meth_data == NULL) {
| 0 | ||||||||||||||||||||||||
119 | /* sk_new doesn't generate any errors so we do */ | - | ||||||||||||||||||||||||
120 | DSOerror(ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
121 | free(ret); | - | ||||||||||||||||||||||||
122 | return (NULL); never executed: return ( ((void *)0) ); | 0 | ||||||||||||||||||||||||
123 | } | - | ||||||||||||||||||||||||
124 | if (meth == NULL)
| 0 | ||||||||||||||||||||||||
125 | ret->meth = default_DSO_meth; never executed: ret->meth = default_DSO_meth; | 0 | ||||||||||||||||||||||||
126 | else | - | ||||||||||||||||||||||||
127 | ret->meth = meth; never executed: ret->meth = meth; | 0 | ||||||||||||||||||||||||
128 | ret->references = 1; | - | ||||||||||||||||||||||||
129 | if ((ret->meth->init != NULL) && !ret->meth->init(ret)) {
| 0 | ||||||||||||||||||||||||
130 | free(ret); | - | ||||||||||||||||||||||||
131 | ret = NULL; | - | ||||||||||||||||||||||||
132 | } never executed: end of block | 0 | ||||||||||||||||||||||||
133 | return (ret); never executed: return (ret); | 0 | ||||||||||||||||||||||||
134 | } | - | ||||||||||||||||||||||||
135 | - | |||||||||||||||||||||||||
136 | int | - | ||||||||||||||||||||||||
137 | DSO_free(DSO *dso) | - | ||||||||||||||||||||||||
138 | { | - | ||||||||||||||||||||||||
139 | int i; | - | ||||||||||||||||||||||||
140 | - | |||||||||||||||||||||||||
141 | if (dso == NULL) {
| 0-1 | ||||||||||||||||||||||||
142 | DSOerror(ERR_R_PASSED_NULL_PARAMETER); | - | ||||||||||||||||||||||||
143 | return (0); executed 1 time by 1 test: return (0); Executed by:
| 1 | ||||||||||||||||||||||||
144 | } | - | ||||||||||||||||||||||||
145 | - | |||||||||||||||||||||||||
146 | i = CRYPTO_add(&dso->references, -1, CRYPTO_LOCK_DSO); | - | ||||||||||||||||||||||||
147 | if (i > 0)
| 0 | ||||||||||||||||||||||||
148 | return (1); never executed: return (1); | 0 | ||||||||||||||||||||||||
149 | - | |||||||||||||||||||||||||
150 | if ((dso->meth->dso_unload != NULL) && !dso->meth->dso_unload(dso)) {
| 0 | ||||||||||||||||||||||||
151 | DSOerror(DSO_R_UNLOAD_FAILED); | - | ||||||||||||||||||||||||
152 | return (0); never executed: return (0); | 0 | ||||||||||||||||||||||||
153 | } | - | ||||||||||||||||||||||||
154 | - | |||||||||||||||||||||||||
155 | if ((dso->meth->finish != NULL) && !dso->meth->finish(dso)) {
| 0 | ||||||||||||||||||||||||
156 | DSOerror(DSO_R_FINISH_FAILED); | - | ||||||||||||||||||||||||
157 | return (0); never executed: return (0); | 0 | ||||||||||||||||||||||||
158 | } | - | ||||||||||||||||||||||||
159 | - | |||||||||||||||||||||||||
160 | sk_void_free(dso->meth_data); | - | ||||||||||||||||||||||||
161 | free(dso->filename); | - | ||||||||||||||||||||||||
162 | free(dso->loaded_filename); | - | ||||||||||||||||||||||||
163 | free(dso); | - | ||||||||||||||||||||||||
164 | return (1); never executed: return (1); | 0 | ||||||||||||||||||||||||
165 | } | - | ||||||||||||||||||||||||
166 | - | |||||||||||||||||||||||||
167 | int | - | ||||||||||||||||||||||||
168 | DSO_flags(DSO *dso) | - | ||||||||||||||||||||||||
169 | { | - | ||||||||||||||||||||||||
170 | return ((dso == NULL) ? 0 : dso->flags); never executed: return ((dso == ((void *)0) ) ? 0 : dso->flags);
| 0 | ||||||||||||||||||||||||
171 | } | - | ||||||||||||||||||||||||
172 | - | |||||||||||||||||||||||||
173 | - | |||||||||||||||||||||||||
174 | int | - | ||||||||||||||||||||||||
175 | DSO_up_ref(DSO *dso) | - | ||||||||||||||||||||||||
176 | { | - | ||||||||||||||||||||||||
177 | int refs; | - | ||||||||||||||||||||||||
178 | - | |||||||||||||||||||||||||
179 | if (dso == NULL) {
| 0 | ||||||||||||||||||||||||
180 | DSOerror(ERR_R_PASSED_NULL_PARAMETER); | - | ||||||||||||||||||||||||
181 | return (0); never executed: return (0); | 0 | ||||||||||||||||||||||||
182 | } | - | ||||||||||||||||||||||||
183 | - | |||||||||||||||||||||||||
184 | refs = CRYPTO_add(&dso->references, 1, CRYPTO_LOCK_DSO); | - | ||||||||||||||||||||||||
185 | return ((refs > 1) ? 1 : 0); never executed: return ((refs > 1) ? 1 : 0);
| 0 | ||||||||||||||||||||||||
186 | } | - | ||||||||||||||||||||||||
187 | - | |||||||||||||||||||||||||
188 | DSO * | - | ||||||||||||||||||||||||
189 | DSO_load(DSO *dso, const char *filename, DSO_METHOD *meth, int flags) | - | ||||||||||||||||||||||||
190 | { | - | ||||||||||||||||||||||||
191 | DSO *ret; | - | ||||||||||||||||||||||||
192 | int allocated = 0; | - | ||||||||||||||||||||||||
193 | - | |||||||||||||||||||||||||
194 | if (dso == NULL) {
| 0 | ||||||||||||||||||||||||
195 | ret = DSO_new_method(meth); | - | ||||||||||||||||||||||||
196 | if (ret == NULL) {
| 0 | ||||||||||||||||||||||||
197 | DSOerror(ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
198 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
199 | } | - | ||||||||||||||||||||||||
200 | allocated = 1; | - | ||||||||||||||||||||||||
201 | /* Pass the provided flags to the new DSO object */ | - | ||||||||||||||||||||||||
202 | if (DSO_ctrl(ret, DSO_CTRL_SET_FLAGS, flags, NULL) < 0) {
| 0 | ||||||||||||||||||||||||
203 | DSOerror(DSO_R_CTRL_FAILED); | - | ||||||||||||||||||||||||
204 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
205 | } | - | ||||||||||||||||||||||||
206 | } else never executed: end of block | 0 | ||||||||||||||||||||||||
207 | ret = dso; never executed: ret = dso; | 0 | ||||||||||||||||||||||||
208 | /* Don't load if we're currently already loaded */ | - | ||||||||||||||||||||||||
209 | if (ret->filename != NULL) {
| 0 | ||||||||||||||||||||||||
210 | DSOerror(DSO_R_DSO_ALREADY_LOADED); | - | ||||||||||||||||||||||||
211 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
212 | } | - | ||||||||||||||||||||||||
213 | /* filename can only be NULL if we were passed a dso that already has | - | ||||||||||||||||||||||||
214 | * one set. */ | - | ||||||||||||||||||||||||
215 | if (filename != NULL)
| 0 | ||||||||||||||||||||||||
216 | if (!DSO_set_filename(ret, filename)) {
| 0 | ||||||||||||||||||||||||
217 | DSOerror(DSO_R_SET_FILENAME_FAILED); | - | ||||||||||||||||||||||||
218 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
219 | } | - | ||||||||||||||||||||||||
220 | filename = ret->filename; | - | ||||||||||||||||||||||||
221 | if (filename == NULL) {
| 0 | ||||||||||||||||||||||||
222 | DSOerror(DSO_R_NO_FILENAME); | - | ||||||||||||||||||||||||
223 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
224 | } | - | ||||||||||||||||||||||||
225 | if (ret->meth->dso_load == NULL) {
| 0 | ||||||||||||||||||||||||
226 | DSOerror(DSO_R_UNSUPPORTED); | - | ||||||||||||||||||||||||
227 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
228 | } | - | ||||||||||||||||||||||||
229 | if (!ret->meth->dso_load(ret)) {
| 0 | ||||||||||||||||||||||||
230 | DSOerror(DSO_R_LOAD_FAILED); | - | ||||||||||||||||||||||||
231 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
232 | } | - | ||||||||||||||||||||||||
233 | /* Load succeeded */ | - | ||||||||||||||||||||||||
234 | return (ret); never executed: return (ret); | 0 | ||||||||||||||||||||||||
235 | - | |||||||||||||||||||||||||
236 | err: | - | ||||||||||||||||||||||||
237 | if (allocated)
| 0 | ||||||||||||||||||||||||
238 | DSO_free(ret); never executed: DSO_free(ret); | 0 | ||||||||||||||||||||||||
239 | return (NULL); never executed: return ( ((void *)0) ); | 0 | ||||||||||||||||||||||||
240 | } | - | ||||||||||||||||||||||||
241 | - | |||||||||||||||||||||||||
242 | void * | - | ||||||||||||||||||||||||
243 | DSO_bind_var(DSO *dso, const char *symname) | - | ||||||||||||||||||||||||
244 | { | - | ||||||||||||||||||||||||
245 | void *ret = NULL; | - | ||||||||||||||||||||||||
246 | - | |||||||||||||||||||||||||
247 | if ((dso == NULL) || (symname == NULL)) {
| 0 | ||||||||||||||||||||||||
248 | DSOerror(ERR_R_PASSED_NULL_PARAMETER); | - | ||||||||||||||||||||||||
249 | return (NULL); never executed: return ( ((void *)0) ); | 0 | ||||||||||||||||||||||||
250 | } | - | ||||||||||||||||||||||||
251 | if (dso->meth->dso_bind_var == NULL) {
| 0 | ||||||||||||||||||||||||
252 | DSOerror(DSO_R_UNSUPPORTED); | - | ||||||||||||||||||||||||
253 | return (NULL); never executed: return ( ((void *)0) ); | 0 | ||||||||||||||||||||||||
254 | } | - | ||||||||||||||||||||||||
255 | if ((ret = dso->meth->dso_bind_var(dso, symname)) == NULL) {
| 0 | ||||||||||||||||||||||||
256 | DSOerror(DSO_R_SYM_FAILURE); | - | ||||||||||||||||||||||||
257 | return (NULL); never executed: return ( ((void *)0) ); | 0 | ||||||||||||||||||||||||
258 | } | - | ||||||||||||||||||||||||
259 | /* Success */ | - | ||||||||||||||||||||||||
260 | return (ret); never executed: return (ret); | 0 | ||||||||||||||||||||||||
261 | } | - | ||||||||||||||||||||||||
262 | - | |||||||||||||||||||||||||
263 | DSO_FUNC_TYPE | - | ||||||||||||||||||||||||
264 | DSO_bind_func(DSO *dso, const char *symname) | - | ||||||||||||||||||||||||
265 | { | - | ||||||||||||||||||||||||
266 | DSO_FUNC_TYPE ret = NULL; | - | ||||||||||||||||||||||||
267 | - | |||||||||||||||||||||||||
268 | if ((dso == NULL) || (symname == NULL)) {
| 0 | ||||||||||||||||||||||||
269 | DSOerror(ERR_R_PASSED_NULL_PARAMETER); | - | ||||||||||||||||||||||||
270 | return (NULL); never executed: return ( ((void *)0) ); | 0 | ||||||||||||||||||||||||
271 | } | - | ||||||||||||||||||||||||
272 | if (dso->meth->dso_bind_func == NULL) {
| 0 | ||||||||||||||||||||||||
273 | DSOerror(DSO_R_UNSUPPORTED); | - | ||||||||||||||||||||||||
274 | return (NULL); never executed: return ( ((void *)0) ); | 0 | ||||||||||||||||||||||||
275 | } | - | ||||||||||||||||||||||||
276 | if ((ret = dso->meth->dso_bind_func(dso, symname)) == NULL) {
| 0 | ||||||||||||||||||||||||
277 | DSOerror(DSO_R_SYM_FAILURE); | - | ||||||||||||||||||||||||
278 | return (NULL); never executed: return ( ((void *)0) ); | 0 | ||||||||||||||||||||||||
279 | } | - | ||||||||||||||||||||||||
280 | /* Success */ | - | ||||||||||||||||||||||||
281 | return (ret); never executed: return (ret); | 0 | ||||||||||||||||||||||||
282 | } | - | ||||||||||||||||||||||||
283 | - | |||||||||||||||||||||||||
284 | /* I don't really like these *_ctrl functions very much to be perfectly | - | ||||||||||||||||||||||||
285 | * honest. For one thing, I think I have to return a negative value for | - | ||||||||||||||||||||||||
286 | * any error because possible DSO_ctrl() commands may return values | - | ||||||||||||||||||||||||
287 | * such as "size"s that can legitimately be zero (making the standard | - | ||||||||||||||||||||||||
288 | * "if(DSO_cmd(...))" form that works almost everywhere else fail at | - | ||||||||||||||||||||||||
289 | * odd times. I'd prefer "output" values to be passed by reference and | - | ||||||||||||||||||||||||
290 | * the return value as success/failure like usual ... but we conform | - | ||||||||||||||||||||||||
291 | * when we must... :-) */ | - | ||||||||||||||||||||||||
292 | long | - | ||||||||||||||||||||||||
293 | DSO_ctrl(DSO *dso, int cmd, long larg, void *parg) | - | ||||||||||||||||||||||||
294 | { | - | ||||||||||||||||||||||||
295 | if (dso == NULL) {
| 0 | ||||||||||||||||||||||||
296 | DSOerror(ERR_R_PASSED_NULL_PARAMETER); | - | ||||||||||||||||||||||||
297 | return (-1); never executed: return (-1); | 0 | ||||||||||||||||||||||||
298 | } | - | ||||||||||||||||||||||||
299 | /* We should intercept certain generic commands and only pass control | - | ||||||||||||||||||||||||
300 | * to the method-specific ctrl() function if it's something we don't | - | ||||||||||||||||||||||||
301 | * handle. */ | - | ||||||||||||||||||||||||
302 | switch (cmd) { | - | ||||||||||||||||||||||||
303 | case DSO_CTRL_GET_FLAGS: never executed: case 1: | 0 | ||||||||||||||||||||||||
304 | return dso->flags; never executed: return dso->flags; | 0 | ||||||||||||||||||||||||
305 | case DSO_CTRL_SET_FLAGS: never executed: case 2: | 0 | ||||||||||||||||||||||||
306 | dso->flags = (int)larg; | - | ||||||||||||||||||||||||
307 | return (0); never executed: return (0); | 0 | ||||||||||||||||||||||||
308 | case DSO_CTRL_OR_FLAGS: never executed: case 3: | 0 | ||||||||||||||||||||||||
309 | dso->flags |= (int)larg; | - | ||||||||||||||||||||||||
310 | return (0); never executed: return (0); | 0 | ||||||||||||||||||||||||
311 | default: never executed: default: | 0 | ||||||||||||||||||||||||
312 | break; never executed: break; | 0 | ||||||||||||||||||||||||
313 | } | - | ||||||||||||||||||||||||
314 | if ((dso->meth == NULL) || (dso->meth->dso_ctrl == NULL)) {
| 0 | ||||||||||||||||||||||||
315 | DSOerror(DSO_R_UNSUPPORTED); | - | ||||||||||||||||||||||||
316 | return (-1); never executed: return (-1); | 0 | ||||||||||||||||||||||||
317 | } | - | ||||||||||||||||||||||||
318 | return (dso->meth->dso_ctrl(dso, cmd, larg, parg)); never executed: return (dso->meth->dso_ctrl(dso, cmd, larg, parg)); | 0 | ||||||||||||||||||||||||
319 | } | - | ||||||||||||||||||||||||
320 | - | |||||||||||||||||||||||||
321 | int | - | ||||||||||||||||||||||||
322 | DSO_set_name_converter(DSO *dso, DSO_NAME_CONVERTER_FUNC cb, | - | ||||||||||||||||||||||||
323 | DSO_NAME_CONVERTER_FUNC *oldcb) | - | ||||||||||||||||||||||||
324 | { | - | ||||||||||||||||||||||||
325 | if (dso == NULL) {
| 0 | ||||||||||||||||||||||||
326 | DSOerror(ERR_R_PASSED_NULL_PARAMETER); | - | ||||||||||||||||||||||||
327 | return (0); never executed: return (0); | 0 | ||||||||||||||||||||||||
328 | } | - | ||||||||||||||||||||||||
329 | if (oldcb)
| 0 | ||||||||||||||||||||||||
330 | *oldcb = dso->name_converter; never executed: *oldcb = dso->name_converter; | 0 | ||||||||||||||||||||||||
331 | dso->name_converter = cb; | - | ||||||||||||||||||||||||
332 | return (1); never executed: return (1); | 0 | ||||||||||||||||||||||||
333 | } | - | ||||||||||||||||||||||||
334 | - | |||||||||||||||||||||||||
335 | const char * | - | ||||||||||||||||||||||||
336 | DSO_get_filename(DSO *dso) | - | ||||||||||||||||||||||||
337 | { | - | ||||||||||||||||||||||||
338 | if (dso == NULL) {
| 0 | ||||||||||||||||||||||||
339 | DSOerror(ERR_R_PASSED_NULL_PARAMETER); | - | ||||||||||||||||||||||||
340 | return (NULL); never executed: return ( ((void *)0) ); | 0 | ||||||||||||||||||||||||
341 | } | - | ||||||||||||||||||||||||
342 | return (dso->filename); never executed: return (dso->filename); | 0 | ||||||||||||||||||||||||
343 | } | - | ||||||||||||||||||||||||
344 | - | |||||||||||||||||||||||||
345 | int | - | ||||||||||||||||||||||||
346 | DSO_set_filename(DSO *dso, const char *filename) | - | ||||||||||||||||||||||||
347 | { | - | ||||||||||||||||||||||||
348 | char *copied; | - | ||||||||||||||||||||||||
349 | - | |||||||||||||||||||||||||
350 | if ((dso == NULL) || (filename == NULL)) {
| 0 | ||||||||||||||||||||||||
351 | DSOerror(ERR_R_PASSED_NULL_PARAMETER); | - | ||||||||||||||||||||||||
352 | return (0); never executed: return (0); | 0 | ||||||||||||||||||||||||
353 | } | - | ||||||||||||||||||||||||
354 | if (dso->loaded_filename) {
| 0 | ||||||||||||||||||||||||
355 | DSOerror(DSO_R_DSO_ALREADY_LOADED); | - | ||||||||||||||||||||||||
356 | return (0); never executed: return (0); | 0 | ||||||||||||||||||||||||
357 | } | - | ||||||||||||||||||||||||
358 | /* We'll duplicate filename */ | - | ||||||||||||||||||||||||
359 | copied = strdup(filename); never executed: __retval = (char *) memcpy (__retval, filename , __len);
| 0 | ||||||||||||||||||||||||
360 | if (copied == NULL) {
| 0 | ||||||||||||||||||||||||
361 | DSOerror(ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
362 | return (0); never executed: return (0); | 0 | ||||||||||||||||||||||||
363 | } | - | ||||||||||||||||||||||||
364 | free(dso->filename); | - | ||||||||||||||||||||||||
365 | dso->filename = copied; | - | ||||||||||||||||||||||||
366 | return (1); never executed: return (1); | 0 | ||||||||||||||||||||||||
367 | } | - | ||||||||||||||||||||||||
368 | - | |||||||||||||||||||||||||
369 | char * | - | ||||||||||||||||||||||||
370 | DSO_merge(DSO *dso, const char *filespec1, const char *filespec2) | - | ||||||||||||||||||||||||
371 | { | - | ||||||||||||||||||||||||
372 | char *result = NULL; | - | ||||||||||||||||||||||||
373 | - | |||||||||||||||||||||||||
374 | if (dso == NULL || filespec1 == NULL) {
| 0 | ||||||||||||||||||||||||
375 | DSOerror(ERR_R_PASSED_NULL_PARAMETER); | - | ||||||||||||||||||||||||
376 | return (NULL); never executed: return ( ((void *)0) ); | 0 | ||||||||||||||||||||||||
377 | } | - | ||||||||||||||||||||||||
378 | if ((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0) {
| 0 | ||||||||||||||||||||||||
379 | if (dso->merger != NULL)
| 0 | ||||||||||||||||||||||||
380 | result = dso->merger(dso, filespec1, filespec2); never executed: result = dso->merger(dso, filespec1, filespec2); | 0 | ||||||||||||||||||||||||
381 | else if (dso->meth->dso_merger != NULL)
| 0 | ||||||||||||||||||||||||
382 | result = dso->meth->dso_merger(dso, never executed: result = dso->meth->dso_merger(dso, filespec1, filespec2); | 0 | ||||||||||||||||||||||||
383 | filespec1, filespec2); never executed: result = dso->meth->dso_merger(dso, filespec1, filespec2); | 0 | ||||||||||||||||||||||||
384 | } never executed: end of block | 0 | ||||||||||||||||||||||||
385 | return (result); never executed: return (result); | 0 | ||||||||||||||||||||||||
386 | } | - | ||||||||||||||||||||||||
387 | - | |||||||||||||||||||||||||
388 | char * | - | ||||||||||||||||||||||||
389 | DSO_convert_filename(DSO *dso, const char *filename) | - | ||||||||||||||||||||||||
390 | { | - | ||||||||||||||||||||||||
391 | char *result = NULL; | - | ||||||||||||||||||||||||
392 | - | |||||||||||||||||||||||||
393 | if (dso == NULL) {
| 0 | ||||||||||||||||||||||||
394 | DSOerror(ERR_R_PASSED_NULL_PARAMETER); | - | ||||||||||||||||||||||||
395 | return (NULL); never executed: return ( ((void *)0) ); | 0 | ||||||||||||||||||||||||
396 | } | - | ||||||||||||||||||||||||
397 | if (filename == NULL)
| 0 | ||||||||||||||||||||||||
398 | filename = dso->filename; never executed: filename = dso->filename; | 0 | ||||||||||||||||||||||||
399 | if (filename == NULL) {
| 0 | ||||||||||||||||||||||||
400 | DSOerror(DSO_R_NO_FILENAME); | - | ||||||||||||||||||||||||
401 | return (NULL); never executed: return ( ((void *)0) ); | 0 | ||||||||||||||||||||||||
402 | } | - | ||||||||||||||||||||||||
403 | if ((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0) {
| 0 | ||||||||||||||||||||||||
404 | if (dso->name_converter != NULL)
| 0 | ||||||||||||||||||||||||
405 | result = dso->name_converter(dso, filename); never executed: result = dso->name_converter(dso, filename); | 0 | ||||||||||||||||||||||||
406 | else if (dso->meth->dso_name_converter != NULL)
| 0 | ||||||||||||||||||||||||
407 | result = dso->meth->dso_name_converter(dso, filename); never executed: result = dso->meth->dso_name_converter(dso, filename); | 0 | ||||||||||||||||||||||||
408 | } never executed: end of block | 0 | ||||||||||||||||||||||||
409 | if (result == NULL) {
| 0 | ||||||||||||||||||||||||
410 | result = strdup(filename); never executed: __retval = (char *) memcpy (__retval, filename , __len);
| 0 | ||||||||||||||||||||||||
411 | if (result == NULL) {
| 0 | ||||||||||||||||||||||||
412 | DSOerror(ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
413 | return (NULL); never executed: return ( ((void *)0) ); | 0 | ||||||||||||||||||||||||
414 | } | - | ||||||||||||||||||||||||
415 | } never executed: end of block | 0 | ||||||||||||||||||||||||
416 | return (result); never executed: return (result); | 0 | ||||||||||||||||||||||||
417 | } | - | ||||||||||||||||||||||||
418 | - | |||||||||||||||||||||||||
419 | const char * | - | ||||||||||||||||||||||||
420 | DSO_get_loaded_filename(DSO *dso) | - | ||||||||||||||||||||||||
421 | { | - | ||||||||||||||||||||||||
422 | if (dso == NULL) {
| 0 | ||||||||||||||||||||||||
423 | DSOerror(ERR_R_PASSED_NULL_PARAMETER); | - | ||||||||||||||||||||||||
424 | return (NULL); never executed: return ( ((void *)0) ); | 0 | ||||||||||||||||||||||||
425 | } | - | ||||||||||||||||||||||||
426 | return (dso->loaded_filename); never executed: return (dso->loaded_filename); | 0 | ||||||||||||||||||||||||
427 | } | - | ||||||||||||||||||||||||
428 | - | |||||||||||||||||||||||||
429 | int | - | ||||||||||||||||||||||||
430 | DSO_pathbyaddr(void *addr, char *path, int sz) | - | ||||||||||||||||||||||||
431 | { | - | ||||||||||||||||||||||||
432 | DSO_METHOD *meth = default_DSO_meth; | - | ||||||||||||||||||||||||
433 | if (meth == NULL)
| 0 | ||||||||||||||||||||||||
434 | meth = DSO_METHOD_openssl(); never executed: meth = DSO_METHOD_openssl(); | 0 | ||||||||||||||||||||||||
435 | if (meth->pathbyaddr == NULL) {
| 0 | ||||||||||||||||||||||||
436 | DSOerror(DSO_R_UNSUPPORTED); | - | ||||||||||||||||||||||||
437 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
438 | } | - | ||||||||||||||||||||||||
439 | return (*meth->pathbyaddr)(addr, path, sz); never executed: return (*meth->pathbyaddr)(addr, path, sz); | 0 | ||||||||||||||||||||||||
440 | } | - | ||||||||||||||||||||||||
441 | - | |||||||||||||||||||||||||
442 | void * | - | ||||||||||||||||||||||||
443 | DSO_global_lookup(const char *name) | - | ||||||||||||||||||||||||
444 | { | - | ||||||||||||||||||||||||
445 | DSO_METHOD *meth = default_DSO_meth; | - | ||||||||||||||||||||||||
446 | if (meth == NULL)
| 0 | ||||||||||||||||||||||||
447 | meth = DSO_METHOD_openssl(); never executed: meth = DSO_METHOD_openssl(); | 0 | ||||||||||||||||||||||||
448 | if (meth->globallookup == NULL) {
| 0 | ||||||||||||||||||||||||
449 | DSOerror(DSO_R_UNSUPPORTED); | - | ||||||||||||||||||||||||
450 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
451 | } | - | ||||||||||||||||||||||||
452 | return (*meth->globallookup)(name); never executed: return (*meth->globallookup)(name); | 0 | ||||||||||||||||||||||||
453 | } | - | ||||||||||||||||||||||||
Source code | Switch to Preprocessed file |