From 780b97aba6a2e931487539a2c4775edfa855a7be Mon Sep 17 00:00:00 2001 From: Andy Polyakov Date: Tue, 7 Jun 2005 10:49:35 +0000 Subject: [PATCH] Ad-hoc DSO_pathbyaddr for selected platforms from HEAD in FIPS context. --- crypto/dso/dso_dl.c | 28 ++++++++++++++++++++++++++++ crypto/dso/dso_dlfcn.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/crypto/dso/dso_dl.c b/crypto/dso/dso_dl.c index 79d2cb4d8c..15862cb0f7 100644 --- a/crypto/dso/dso_dl.c +++ b/crypto/dso/dso_dl.c @@ -281,4 +281,32 @@ static char *dl_name_converter(DSO *dso, const char *filename) return(translated); } +#ifdef OPENSSL_FIPS +static void dl_ref_point(){} + +int DSO_pathbyaddr(void *addr,char *path,int sz) + { + struct shl_descriptor inf; + int i,len; + + if (addr == NULL) addr = dl_ref_porint; + + for (i=-1;shl_get_r(i,&inf)==0;i++) + { + if (((size_t)addr >= inf.tstart && (size_t)addr < inf.tend) || + ((size_t)addr >= inf.dstart && (size_t)addr < inf.dend)) + { + len = (int)strlen(inf.filename); + if (sz <= 0) return len+1; + if (len >= sz) len=sz-1; + memcpy(path,inf.filename,len); + path[len++] = 0; + return len; + } + } + + return -1; + } +#endif + #endif /* DSO_DL */ diff --git a/crypto/dso/dso_dlfcn.c b/crypto/dso/dso_dlfcn.c index 1a40695dad..1f32245eea 100644 --- a/crypto/dso/dso_dlfcn.c +++ b/crypto/dso/dso_dlfcn.c @@ -56,6 +56,10 @@ * */ +#ifdef __linux +#define _GNU_SOURCE +#endif + #include #include "cryptlib.h" #include @@ -290,4 +294,28 @@ static char *dlfcn_name_converter(DSO *dso, const char *filename) return(translated); } +#ifdef OPENSSL_FIPS +static void dlfcn_ref_point(){} + +int DSO_pathbyaddr(void *addr,char *path,int sz) + { + Dl_info dli; + int len; + + if (addr == NULL) addr = dlfcn_ref_point; + + if (dladdr(addr,&dli)) + { + len = (int)strlen(dli.dli_fname); + if (sz <= 0) return len+1; + if (len >= sz) len=sz-1; + memcpy(path,dli.dli_fname,len); + path[len++]=0; + return len; + } + + ERR_add_error_data(4, "dlfcn_pathbyaddr(): ", dlerror()); + return -1; + } +#endif #endif /* DSO_DLFCN */ -- 2.25.1