Ad-hoc DSO_pathbyaddr for selected platforms from HEAD in FIPS context.
authorAndy Polyakov <appro@openssl.org>
Tue, 7 Jun 2005 10:49:35 +0000 (10:49 +0000)
committerAndy Polyakov <appro@openssl.org>
Tue, 7 Jun 2005 10:49:35 +0000 (10:49 +0000)
crypto/dso/dso_dl.c
crypto/dso/dso_dlfcn.c

index 79d2cb4d8c8dae3d7e404b517286fbf5cbdcbcb7..15862cb0f7754ac2e0dfc0746c85a39094a8e193 100644 (file)
@@ -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 */
index 1a40695dad8fc5233a424a3168258f1e63391d53..1f32245eea07473e6beef688fa1cdcfe8ef8460b 100644 (file)
  *
  */
 
+#ifdef __linux
+#define _GNU_SOURCE
+#endif
+
 #include <stdio.h>
 #include "cryptlib.h"
 #include <openssl/dso.h>
@@ -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 */