Commit e2565184 authored by Alexander Færøy's avatar Alexander Færøy
Browse files

Check if external compression libraries are available at run-time.

This patch ensures that Tor checks if our compression backend libraries
are actually available at run-time. This problem happens if Tor is
compiled with weak linking where the lack of the external library
provided functions will lead to a NULL dereference first time they are
called.

See: https://bugs.torproject.org/22926
parent b5a8fd15
Pipeline #17129490 failed with stage
in 3 minutes and 26 seconds
/* Copyright (c) 2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
* Copyright (c) 2007-2017, The Tor Project, Inc. */
* Copyright (c) 2007-2018, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
......@@ -29,6 +29,10 @@
static atomic_counter_t total_lzma_allocation;
#ifdef HAVE_LZMA
/** Run-time check to see if external LZMA functions are available.
* See bug #22926. */
static int external_lzma_functions_available;
/** Given <b>level</b> return the memory level. */
static int
memory_level(compression_level_t level)
......@@ -82,7 +86,7 @@ int
tor_lzma_method_supported(void)
{
#ifdef HAVE_LZMA
return 1;
return external_lzma_functions_available;
#else
return 0;
#endif
......@@ -94,10 +98,11 @@ const char *
tor_lzma_get_version_str(void)
{
#ifdef HAVE_LZMA
return lzma_version_string();
#else
return NULL;
if (PREDICT_LIKELY(tor_lzma_method_supported()))
return lzma_version_string();
#endif
return NULL;
}
/** Return a string representation of the version of liblzma used at
......@@ -357,5 +362,15 @@ void
tor_lzma_init(void)
{
atomic_counter_init(&total_lzma_allocation);
#ifdef HAVE_LZMA
if (PREDICT_UNLIKELY(&lzma_code == NULL)) {
log_warn(LD_GENERAL, "It looks like your version of Tor was compiled "
"with LZMA support, but the external functions "
"are unavailable. See bug #22926 for more "
"information. Disabling LZMA support.");
} else
external_lzma_functions_available = 1;
#endif // HAVE_LZMA.
}
/* Copyright (c) 2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
* Copyright (c) 2007-2017, The Tor Project, Inc. */
* Copyright (c) 2007-2018, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
......@@ -50,6 +50,10 @@ static size_t tor_zlib_state_size_precalc(int inflate,
/** Total number of bytes allocated for zlib state */
static atomic_counter_t total_zlib_allocation;
/** Run-time check to see if external Zlib functions are available.
* See bug #22926. */
static int external_zlib_functions_available;
/** Given <b>level</b> return the memory level. */
static int
memory_level(compression_level_t level)
......@@ -85,7 +89,7 @@ tor_zlib_method_supported(void)
/* We currently always support zlib/gzip, but we keep this function around in
* case we some day decide to deprecate zlib/gzip support.
*/
return 1;
return external_zlib_functions_available;
}
/** Return a string representation of the version of the currently running
......@@ -300,5 +304,13 @@ void
tor_zlib_init(void)
{
atomic_counter_init(&total_zlib_allocation);
if (PREDICT_UNLIKELY(&deflateInit2_ == NULL)) {
log_warn(LD_GENERAL, "It looks like your version of Tor was compiled "
"with Zlib support, but the external functions "
"are unavailable. See bug #22926 for more "
"information. Disabling Zlib support.");
} else
external_zlib_functions_available = 1;
}
/* Copyright (c) 2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
* Copyright (c) 2007-2017, The Tor Project, Inc. */
* Copyright (c) 2007-2018, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
......@@ -26,6 +26,10 @@
static atomic_counter_t total_zstd_allocation;
#ifdef HAVE_ZSTD
/** Run-time check to see if external Zstd functions are available.
* See bug #22926. */
static int external_zstd_functions_available;
/** Given <b>level</b> return the memory level. */
static int
memory_level(compression_level_t level)
......@@ -45,7 +49,7 @@ int
tor_zstd_method_supported(void)
{
#ifdef HAVE_ZSTD
return 1;
return external_zstd_functions_available;
#else
return 0;
#endif
......@@ -57,6 +61,9 @@ const char *
tor_zstd_get_version_str(void)
{
#ifdef HAVE_ZSTD
if (PREDICT_UNLIKELY(! tor_zstd_method_supported()))
return NULL;
static char version_str[16];
size_t version_number;
......@@ -438,5 +445,15 @@ void
tor_zstd_init(void)
{
atomic_counter_init(&total_zstd_allocation);
#ifdef HAVE_ZSTD
if (PREDICT_UNLIKELY(&ZSTD_compressStream == NULL)) {
log_warn(LD_GENERAL, "It looks like your version of Tor was compiled "
"with Zstd support, but the external functions "
"are unavailable. See bug #22926 for more "
"information. Disabling Zstd support.");
} else
external_zstd_functions_available = 1;
#endif // HAVE_ZSTD.
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment