diff options
Diffstat (limited to 'src/lib/libcrypto/dso/dso_dl.c')
-rw-r--r-- | src/lib/libcrypto/dso/dso_dl.c | 102 |
1 files changed, 33 insertions, 69 deletions
diff --git a/src/lib/libcrypto/dso/dso_dl.c b/src/lib/libcrypto/dso/dso_dl.c index 417abb6ea9..f7b4dfc0c3 100644 --- a/src/lib/libcrypto/dso/dso_dl.c +++ b/src/lib/libcrypto/dso/dso_dl.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* dso_dl.c -*- mode:C; c-file-style: "eay" -*- */ | 1 | /* dso_dl.c */ |
2 | /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL | 2 | /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL |
3 | * project 2000. | 3 | * project 2000. |
4 | */ | 4 | */ |
@@ -84,7 +84,6 @@ static int dl_finish(DSO *dso); | |||
84 | static int dl_ctrl(DSO *dso, int cmd, long larg, void *parg); | 84 | static int dl_ctrl(DSO *dso, int cmd, long larg, void *parg); |
85 | #endif | 85 | #endif |
86 | static char *dl_name_converter(DSO *dso, const char *filename); | 86 | static char *dl_name_converter(DSO *dso, const char *filename); |
87 | static char *dl_merger(DSO *dso, const char *filespec1, const char *filespec2); | ||
88 | 87 | ||
89 | static DSO_METHOD dso_meth_dl = { | 88 | static DSO_METHOD dso_meth_dl = { |
90 | "OpenSSL 'dl' shared library method", | 89 | "OpenSSL 'dl' shared library method", |
@@ -99,7 +98,6 @@ static DSO_METHOD dso_meth_dl = { | |||
99 | #endif | 98 | #endif |
100 | NULL, /* ctrl */ | 99 | NULL, /* ctrl */ |
101 | dl_name_converter, | 100 | dl_name_converter, |
102 | dl_merger, | ||
103 | NULL, /* init */ | 101 | NULL, /* init */ |
104 | NULL /* finish */ | 102 | NULL /* finish */ |
105 | }; | 103 | }; |
@@ -241,72 +239,6 @@ static DSO_FUNC_TYPE dl_bind_func(DSO *dso, const char *symname) | |||
241 | return((DSO_FUNC_TYPE)sym); | 239 | return((DSO_FUNC_TYPE)sym); |
242 | } | 240 | } |
243 | 241 | ||
244 | static char *dl_merger(DSO *dso, const char *filespec1, const char *filespec2) | ||
245 | { | ||
246 | char *merged; | ||
247 | |||
248 | if(!filespec1 && !filespec2) | ||
249 | { | ||
250 | DSOerr(DSO_F_DL_MERGER, | ||
251 | ERR_R_PASSED_NULL_PARAMETER); | ||
252 | return(NULL); | ||
253 | } | ||
254 | /* If the first file specification is a rooted path, it rules. | ||
255 | same goes if the second file specification is missing. */ | ||
256 | if (!filespec2 || filespec1[0] == '/') | ||
257 | { | ||
258 | merged = OPENSSL_malloc(strlen(filespec1) + 1); | ||
259 | if(!merged) | ||
260 | { | ||
261 | DSOerr(DSO_F_DL_MERGER, | ||
262 | ERR_R_MALLOC_FAILURE); | ||
263 | return(NULL); | ||
264 | } | ||
265 | strcpy(merged, filespec1); | ||
266 | } | ||
267 | /* If the first file specification is missing, the second one rules. */ | ||
268 | else if (!filespec1) | ||
269 | { | ||
270 | merged = OPENSSL_malloc(strlen(filespec2) + 1); | ||
271 | if(!merged) | ||
272 | { | ||
273 | DSOerr(DSO_F_DL_MERGER, | ||
274 | ERR_R_MALLOC_FAILURE); | ||
275 | return(NULL); | ||
276 | } | ||
277 | strcpy(merged, filespec2); | ||
278 | } | ||
279 | else | ||
280 | /* This part isn't as trivial as it looks. It assumes that | ||
281 | the second file specification really is a directory, and | ||
282 | makes no checks whatsoever. Therefore, the result becomes | ||
283 | the concatenation of filespec2 followed by a slash followed | ||
284 | by filespec1. */ | ||
285 | { | ||
286 | int spec2len, len; | ||
287 | |||
288 | spec2len = (filespec2 ? strlen(filespec2) : 0); | ||
289 | len = spec2len + (filespec1 ? strlen(filespec1) : 0); | ||
290 | |||
291 | if(filespec2 && filespec2[spec2len - 1] == '/') | ||
292 | { | ||
293 | spec2len--; | ||
294 | len--; | ||
295 | } | ||
296 | merged = OPENSSL_malloc(len + 2); | ||
297 | if(!merged) | ||
298 | { | ||
299 | DSOerr(DSO_F_DL_MERGER, | ||
300 | ERR_R_MALLOC_FAILURE); | ||
301 | return(NULL); | ||
302 | } | ||
303 | strcpy(merged, filespec2); | ||
304 | merged[spec2len] = '/'; | ||
305 | strcpy(&merged[spec2len + 1], filespec1); | ||
306 | } | ||
307 | return(merged); | ||
308 | } | ||
309 | |||
310 | /* This function is identical to the one in dso_dlfcn.c, but as it is highly | 242 | /* This function is identical to the one in dso_dlfcn.c, but as it is highly |
311 | * unlikely that both the "dl" *and* "dlfcn" variants are being compiled at the | 243 | * unlikely that both the "dl" *and* "dlfcn" variants are being compiled at the |
312 | * same time, there's no great duplicating the code. Figuring out an elegant | 244 | * same time, there's no great duplicating the code. Figuring out an elegant |
@@ -350,4 +282,36 @@ static char *dl_name_converter(DSO *dso, const char *filename) | |||
350 | return(translated); | 282 | return(translated); |
351 | } | 283 | } |
352 | 284 | ||
285 | #ifdef OPENSSL_FIPS | ||
286 | static void dl_ref_point(){} | ||
287 | |||
288 | int DSO_pathbyaddr(void *addr,char *path,int sz) | ||
289 | { | ||
290 | struct shl_descriptor inf; | ||
291 | int i,len; | ||
292 | |||
293 | if (addr == NULL) | ||
294 | { | ||
295 | union { void(*f)(); void *p; } t = { dl_ref_point }; | ||
296 | addr = t.p; | ||
297 | } | ||
298 | |||
299 | for (i=-1;shl_get_r(i,&inf)==0;i++) | ||
300 | { | ||
301 | if (((size_t)addr >= inf.tstart && (size_t)addr < inf.tend) || | ||
302 | ((size_t)addr >= inf.dstart && (size_t)addr < inf.dend)) | ||
303 | { | ||
304 | len = (int)strlen(inf.filename); | ||
305 | if (sz <= 0) return len+1; | ||
306 | if (len >= sz) len=sz-1; | ||
307 | memcpy(path,inf.filename,len); | ||
308 | path[len++] = 0; | ||
309 | return len; | ||
310 | } | ||
311 | } | ||
312 | |||
313 | return -1; | ||
314 | } | ||
315 | #endif | ||
316 | |||
353 | #endif /* DSO_DL */ | 317 | #endif /* DSO_DL */ |