File libgcrypt-bsc932232-avoid-drbg-crash-with-fips.patch of Package libgcrypt.7109

Index: libgcrypt-1.6.1/random/drbg.c
===================================================================
--- libgcrypt-1.6.1.orig/random/drbg.c	2017-07-10 16:32:16.356963060 +0200
+++ libgcrypt-1.6.1/random/drbg.c	2017-07-12 11:02:07.659184231 +0200
@@ -1709,6 +1709,19 @@ _gcry_drbg_init (int full)
   gcry_drbg_unlock ();
 }
 
+void
+_gcry_drbg_uninit (void)
+{
+  gcry_drbg_lock ();
+  if (NULL != gcry_drbg)
+    {
+      gcry_drbg_uninstantiate (gcry_drbg);
+      xfree (gcry_drbg);
+      gcry_drbg = NULL;
+    }
+  gcry_drbg_unlock ();
+}
+
 /*
  * Backend handler function for GCRYCTL_DRBG_REINIT
  *
Index: libgcrypt-1.6.1/random/rand-internal.h
===================================================================
--- libgcrypt-1.6.1.orig/random/rand-internal.h	2017-07-10 16:32:16.172960043 +0200
+++ libgcrypt-1.6.1/random/rand-internal.h	2017-07-10 16:32:16.400963782 +0200
@@ -90,6 +90,7 @@ void _gcry_rngfips_deinit_external_test
 
 /* drbg-gcry.h */
 void _gcry_drbg_init(int full);
+void _gcry_drbg_uninit (void);
 void _gcry_drbg_close_fds(void);
 void _gcry_drbg_dump_stats(void);
 int _gcry_drbg_is_faked (void);
Index: libgcrypt-1.6.1/src/global.c
===================================================================
--- libgcrypt-1.6.1.orig/src/global.c	2017-07-10 16:32:16.264961552 +0200
+++ libgcrypt-1.6.1/src/global.c	2017-07-10 16:32:16.400963782 +0200
@@ -746,11 +746,15 @@ _gcry_set_allocation_handler (gcry_handl
       _gcry_inactivate_fips_mode ("custom allocation handler");
     }
 
+  _gcry_drbg_uninit ();
+
   alloc_func = new_alloc_func;
   alloc_secure_func = new_alloc_secure_func;
   is_secure_func = new_is_secure_func;
   realloc_func = new_realloc_func;
   free_func = new_free_func;
+
+  _gcry_drbg_init ();
 }