Add a DSO_dsobyaddr() function
authorMatt Caswell <matt@openssl.org>
Sat, 15 Oct 2016 15:01:40 +0000 (16:01 +0100)
committerMatt Caswell <matt@openssl.org>
Wed, 2 Nov 2016 23:37:26 +0000 (23:37 +0000)
This works the same way as DSO_pathbyaddr() but instead returns a ptr to
the DSO that contains the provided symbol.

Reviewed-by: Tim Hudson <tjh@openssl.org>
(cherry picked from commit b39eda7ee69a9277c722f8789736e00dc680cda6)

crypto/dso/dso_lib.c
include/internal/dso.h
util/libcrypto.num

index 2dac20082ceecdddacc8fd89567166917156014e..52816dfb9d9812b618677acfe856f86346e1a8d3 100644 (file)
@@ -73,9 +73,11 @@ int DSO_free(DSO *dso)
         return 1;
     REF_ASSERT_ISNT(i < 0);
 
-    if ((dso->meth->dso_unload != NULL) && !dso->meth->dso_unload(dso)) {
-        DSOerr(DSO_F_DSO_FREE, DSO_R_UNLOAD_FAILED);
-        return 0;
+    if ((dso->flags & DSO_FLAG_NO_UNLOAD_ON_FREE) == 0) {
+        if ((dso->meth->dso_unload != NULL) && !dso->meth->dso_unload(dso)) {
+            DSOerr(DSO_F_DSO_FREE, DSO_R_UNLOAD_FAILED);
+            return 0;
+        }
     }
 
     if ((dso->meth->finish != NULL) && !dso->meth->finish(dso)) {
@@ -316,6 +318,21 @@ int DSO_pathbyaddr(void *addr, char *path, int sz)
     return (*meth->pathbyaddr) (addr, path, sz);
 }
 
+DSO *DSO_dsobyaddr(void *addr, int flags)
+{
+    DSO *ret = NULL;
+    char *filename = NULL;
+    int len = DSO_pathbyaddr(addr, NULL, 0);
+
+    filename = OPENSSL_malloc(len);
+    if (filename != NULL
+            && DSO_pathbyaddr(addr, filename, len) == len)
+        ret = DSO_load(NULL, filename, NULL, flags);
+
+    OPENSSL_free(filename);
+    return ret;
+}
+
 void *DSO_global_lookup(const char *name)
 {
     DSO_METHOD *meth = default_DSO_meth;
index f513cad3b77afef760824a075a98fd9ae4f1f9d7..f5de8a284a9523dbecafbe09f0e6fb3166d4d338 100644 (file)
@@ -42,6 +42,10 @@ extern "C" {
  */
 # define DSO_FLAG_NAME_TRANSLATION_EXT_ONLY      0x02
 
+/*
+ * Don't unload the DSO when we call DSO_free()
+ */
+# define DSO_FLAG_NO_UNLOAD_ON_FREE              0x04
 /*
  * The following flag controls the translation of symbol names to upper case.
  * This is currently only being implemented for OpenVMS.
@@ -147,6 +151,12 @@ DSO_METHOD *DSO_METHOD_openssl(void);
  */
 int DSO_pathbyaddr(void *addr, char *path, int sz);
 
+/*
+ * Like DSO_pathbyaddr() but instead returns a handle to the DSO for the symbol
+ * or NULL on error.
+ */
+DSO *DSO_dsobyaddr(void *addr, int flags);
+
 /*
  * This function should be used with caution! It looks up symbols in *all*
  * loaded modules and if module gets unloaded by somebody else attempt to
index 2e439e8b11a297b812e778b6353aa6ef619eb4ca..a16cc9f659fb1b673d4cdbc68962e5c86f626571 100644 (file)
@@ -4207,3 +4207,4 @@ OCSP_RESPID_set_by_name                 4157      1_1_0a  EXIST::FUNCTION:OCSP
 OCSP_RESPID_set_by_key                  4158   1_1_0a  EXIST::FUNCTION:OCSP
 OCSP_RESPID_match                       4159   1_1_0a  EXIST::FUNCTION:OCSP
 DSO_pathbyaddr                          4170   1_1_0c  EXIST::FUNCTION:
+DSO_dsobyaddr                           4171   1_1_0c  EXIST::FUNCTION: