[rtmpdump] [PATCH] OPENSSL crypto: SSL_load_error_strings and SSL_library_init are not reentrant
Rafaël Carré
funman at videolan.org
Wed Jun 4 20:29:51 CEST 2014
---
librtmp/Makefile | 2 +-
librtmp/rtmp.c | 20 ++++++++++++++------
2 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/librtmp/Makefile b/librtmp/Makefile
index 2c1c790..861933d 100644
--- a/librtmp/Makefile
+++ b/librtmp/Makefile
@@ -30,7 +30,7 @@ LIBS_posix=
LIBS_darwin=
LIBS_mingw=-lws2_32 -lwinmm -lgdi32
LIB_GNUTLS=-lgnutls -lhogweed -lnettle -lgmp $(LIBZ)
-LIB_OPENSSL=-lssl -lcrypto $(LIBZ)
+LIB_OPENSSL=-lssl -lcrypto $(LIBZ) -lpthread
LIB_POLARSSL=-lpolarssl $(LIBZ)
PRIVATE_LIBS=$(LIBS_$(SYS))
CRYPTO_LIB=$(LIB_$(CRYPTO)) $(PRIVATE_LIBS)
diff --git a/librtmp/rtmp.c b/librtmp/rtmp.c
index 6e788bb..9f74b19 100644
--- a/librtmp/rtmp.c
+++ b/librtmp/rtmp.c
@@ -28,6 +28,7 @@
#include <string.h>
#include <assert.h>
#include <time.h>
+#include <pthread.h>
#include "rtmp_sys.h"
#include "log.h"
@@ -240,12 +241,19 @@ RTMP_TLS_Init()
"ca.pem", GNUTLS_X509_FMT_PEM);
#elif !defined(NO_SSL) /* USE_OPENSSL */
/* libcrypto doesn't need anything special */
- SSL_load_error_strings();
- SSL_library_init();
- OpenSSL_add_all_digests();
- RTMP_TLS_ctx = SSL_CTX_new(SSLv23_method());
- SSL_CTX_set_options(RTMP_TLS_ctx, SSL_OP_ALL);
- SSL_CTX_set_default_verify_paths(RTMP_TLS_ctx);
+ static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
+ static int initialized = 0;
+ pthread_mutex_lock(&lock);
+ if (!initialized) {
+ SSL_load_error_strings();
+ SSL_library_init();
+ OpenSSL_add_all_digests();
+ RTMP_TLS_ctx = SSL_CTX_new(SSLv23_method());
+ SSL_CTX_set_options(RTMP_TLS_ctx, SSL_OP_ALL);
+ SSL_CTX_set_default_verify_paths(RTMP_TLS_ctx);
+ initialized = 1;
+ }
+ pthread_mutex_unlock(&lock);
#endif
#endif
}
--
2.0.0
More information about the rtmpdump
mailing list