From 804335f9d296440bb708ca844f5d89b58b50b0c6 Mon Sep 17 00:00:00 2001 From: runge Date: Thu, 21 May 2009 10:32:18 -0400 Subject: Thread safety for zrle, zlib, tight. Proposed tight security type fix for debian bug 517422. --- libvncserver/zlib.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'libvncserver/zlib.c') diff --git a/libvncserver/zlib.c b/libvncserver/zlib.c index 7b20f74..ac20c9c 100644 --- a/libvncserver/zlib.c +++ b/libvncserver/zlib.c @@ -40,12 +40,24 @@ * raw encoding is used instead. */ -static int zlibBeforeBufSize = 0; -static char *zlibBeforeBuf = NULL; - -static int zlibAfterBufSize = 0; -static char *zlibAfterBuf = NULL; -static int zlibAfterBufLen; +/* + * Out of lazyiness, we use thread local storage for zlib as we did for + * tight. N.B. ZRLE does it the traditional way with per-client storage + * (and so at least ZRLE will work threaded on older systems.) + */ +#if LIBVNCSERVER_HAVE_LIBPTHREAD && LIBVNCSERVER_HAVE_TLS && !defined(TLS) && defined(__linux__) +#define TLS __thread +#endif +#ifndef TLS +#define TLS +#endif + +static TLS int zlibBeforeBufSize = 0; +static TLS char *zlibBeforeBuf = NULL; + +static TLS int zlibAfterBufSize = 0; +static TLS char *zlibAfterBuf = NULL; +static TLS int zlibAfterBufLen = 0; void rfbZlibCleanup(rfbScreenInfoPtr screen) { -- cgit v1.2.3