Jelajahi Sumber

spnego: Work around libtasn1 not being re-entrant

Fix #74
Hugo Beauzée-Luyssen 6 tahun lalu
induk
melakukan
7322a9f427
1 mengubah file dengan 5 tambahan dan 0 penghapusan
  1. 5 0
      src/smb_spnego.c

+ 5 - 0
src/smb_spnego.c

@@ -37,6 +37,7 @@
 #include <stdio.h>
 #include <assert.h>
 #include <inttypes.h>
+#include <pthread.h>
 
 #include "bdsm_debug.h"
 #include "smb_session.h"
@@ -57,6 +58,8 @@ static void     asn1_display_error(const char *where, int errcode)
     BDSM_dbg("%s error: %s\n", where, asn1_strerror(errcode));
 }
 
+static pthread_mutex_t s_tasn1_mutex = PTHREAD_MUTEX_INITIALIZER;
+
 static int      init_asn1(smb_session *s)
 {
     int           res;
@@ -66,7 +69,9 @@ static int      init_asn1(smb_session *s)
     if (s->spnego_asn1 != NULL)
         return DSM_ERROR_GENERIC;
 
+    pthread_mutex_lock( &s_tasn1_mutex );
     res = asn1_array2tree(spnego_asn1_conf, &s->spnego_asn1, NULL);
+    pthread_mutex_unlock( &s_tasn1_mutex );
     if (res != ASN1_SUCCESS)
     {
         asn1_display_error("init_asn1", res);