File libgcrypt-fips-use_dlopen_to_get_hmac_path.patch of Package libgcrypt.7109

Index: libgcrypt-1.6.1/src/fips.c
===================================================================
--- libgcrypt-1.6.1.orig/src/fips.c	2017-07-03 15:57:38.957782290 +0200
+++ libgcrypt-1.6.1/src/fips.c	2017-07-04 14:43:36.907741349 +0200
@@ -590,13 +590,18 @@ run_random_selftests (void)
 }
 
 static int
-get_library_path(const char *symbolname, char *path, size_t pathlen)
+get_library_path(const char *libname, const char *symbolname, char *path, size_t pathlen)
 {
     Dl_info info;
-    void *sym;
+    void *dl, *sym;
     int rv = -1;
 
-    sym = dlsym(RTLD_DEFAULT, symbolname);
+    dl = dlopen(libname, RTLD_LAZY);
+    if (dl == NULL) {
+        return -1;
+    }
+
+    sym = dlsym(dl, symbolname);
 
     if (sym != NULL && dladdr(sym, &info)) {
 	strncpy(path, info.dli_fname, pathlen-1);
@@ -613,7 +618,7 @@ get_hmac_path(char **fname)
   char libpath[4096];
   gpg_error_t err;
 
-  if (get_library_path ("gcry_check_version", libpath, sizeof(libpath)))
+  if (get_library_path ("libgcrypt.so.20", "gcry_check_version", libpath, sizeof(libpath)))
     err = gpg_error_from_syserror ();
   else
     {
@@ -652,7 +657,7 @@ check_binary_integrity (void)
   char *fname = NULL;
   const char key[] = "orboDeJITITejsirpADONivirpUkvarP";
 
-  if (get_library_path ("gcry_check_version", libpath, sizeof(libpath)))
+  if (get_library_path ("libgcrypt.so.20", "gcry_check_version", libpath, sizeof(libpath)))
     err = gpg_error_from_syserror ();
   else
     {