summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/dso/dso_dl.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/dso/dso_dl.c')
-rw-r--r--src/lib/libcrypto/dso/dso_dl.c102
1 files changed, 69 insertions, 33 deletions
diff --git a/src/lib/libcrypto/dso/dso_dl.c b/src/lib/libcrypto/dso/dso_dl.c
index f7b4dfc0c3..417abb6ea9 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 */ 1/* dso_dl.c -*- mode:C; c-file-style: "eay" -*- */
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,6 +84,7 @@ static int dl_finish(DSO *dso);
84static int dl_ctrl(DSO *dso, int cmd, long larg, void *parg); 84static int dl_ctrl(DSO *dso, int cmd, long larg, void *parg);
85#endif 85#endif
86static char *dl_name_converter(DSO *dso, const char *filename); 86static char *dl_name_converter(DSO *dso, const char *filename);
87static char *dl_merger(DSO *dso, const char *filespec1, const char *filespec2);
87 88
88static DSO_METHOD dso_meth_dl = { 89static DSO_METHOD dso_meth_dl = {
89 "OpenSSL 'dl' shared library method", 90 "OpenSSL 'dl' shared library method",
@@ -98,6 +99,7 @@ static DSO_METHOD dso_meth_dl = {
98#endif 99#endif
99 NULL, /* ctrl */ 100 NULL, /* ctrl */
100 dl_name_converter, 101 dl_name_converter,
102 dl_merger,
101 NULL, /* init */ 103 NULL, /* init */
102 NULL /* finish */ 104 NULL /* finish */
103 }; 105 };
@@ -239,6 +241,72 @@ static DSO_FUNC_TYPE dl_bind_func(DSO *dso, const char *symname)
239 return((DSO_FUNC_TYPE)sym); 241 return((DSO_FUNC_TYPE)sym);
240 } 242 }
241 243
244static 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
242/* This function is identical to the one in dso_dlfcn.c, but as it is highly 310/* This function is identical to the one in dso_dlfcn.c, but as it is highly
243 * unlikely that both the "dl" *and* "dlfcn" variants are being compiled at the 311 * unlikely that both the "dl" *and* "dlfcn" variants are being compiled at the
244 * same time, there's no great duplicating the code. Figuring out an elegant 312 * same time, there's no great duplicating the code. Figuring out an elegant
@@ -282,36 +350,4 @@ static char *dl_name_converter(DSO *dso, const char *filename)
282 return(translated); 350 return(translated);
283 } 351 }
284 352
285#ifdef OPENSSL_FIPS
286static void dl_ref_point(){}
287
288int 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
317#endif /* DSO_DL */ 353#endif /* DSO_DL */