Use tor_compress_supports_method() before printing library versions.

This patch ensures that Tor checks if a given compression method is
supported before printing the version string when calling `tor
--library-versions`.

Additionally, we use the `tor_compress_supports_method()` to check if a
given version is supported for Tor's start-up version string, but here
we print "N/A" if a given compression method is unavailable.

See: https://bugs.torproject.org/21662
This commit is contained in:
Alexander Færøy 2017-04-20 16:23:06 +02:00 committed by Nick Mathewson
parent 6b905b38bb
commit c2d1d949de
2 changed files with 22 additions and 18 deletions

View File

@ -70,9 +70,6 @@
#include "circuitmux_ewma.h"
#include "circuitstats.h"
#include "compress.h"
#include "compress_lzma.h"
#include "compress_zlib.h"
#include "compress_zstd.h"
#include "config.h"
#include "connection.h"
#include "connection_edge.h"
@ -4952,15 +4949,21 @@ options_init_from_torrc(int argc, char **argv)
printf("OpenSSL \t\t%-15s\t\t%s\n",
crypto_openssl_get_header_version_str(),
crypto_openssl_get_version_str());
printf("Zlib \t\t%-15s\t\t%s\n",
tor_zlib_get_header_version_str(),
tor_zlib_get_version_str());
printf("Liblzma \t\t%-15s\t\t%s\n",
tor_lzma_get_header_version_str(),
tor_lzma_get_version_str());
printf("Libzstd \t\t%-15s\t\t%s\n",
tor_zstd_get_header_version_str(),
tor_zstd_get_version_str());
if (tor_compress_supports_method(ZLIB_METHOD)) {
printf("Zlib \t\t%-15s\t\t%s\n",
tor_compress_version_str(ZLIB_METHOD),
tor_compress_header_version_str(ZLIB_METHOD));
}
if (tor_compress_supports_method(LZMA_METHOD)) {
printf("Liblzma \t\t%-15s\t\t%s\n",
tor_compress_version_str(LZMA_METHOD),
tor_compress_header_version_str(LZMA_METHOD));
}
if (tor_compress_supports_method(ZSTD_METHOD)) {
printf("Libzstd \t\t%-15s\t\t%s\n",
tor_compress_version_str(ZSTD_METHOD),
tor_compress_header_version_str(ZSTD_METHOD));
}
//TODO: Hex versions?
exit(0);
}

View File

@ -58,9 +58,7 @@
#include "circuitlist.h"
#include "circuituse.h"
#include "command.h"
#include "compress_lzma.h"
#include "compress_zlib.h"
#include "compress_zstd.h"
#include "compress.h"
#include "config.h"
#include "confparse.h"
#include "connection.h"
@ -3005,9 +3003,12 @@ tor_init(int argc, char *argv[])
get_uname(),
tor_libevent_get_version_str(),
crypto_openssl_get_version_str(),
tor_zlib_get_version_str(),
tor_lzma_get_version_str(),
tor_zstd_get_version_str());
tor_compress_supports_method(ZLIB_METHOD) ?
tor_compress_version_str(ZLIB_METHOD) : "N/A",
tor_compress_supports_method(LZMA_METHOD) ?
tor_compress_version_str(LZMA_METHOD) : "N/A",
tor_compress_supports_method(ZSTD_METHOD) ?
tor_compress_version_str(ZSTD_METHOD) : "N/A");
log_notice(LD_GENERAL, "Tor can't help you if you use it wrong! "
"Learn how to be safe at "