[tor-commits] [tor/master] Use `tor_compress_supports_method()` before printing library versions.

nickm at torproject.org nickm at torproject.org
Tue Apr 25 12:18:24 UTC 2017


commit c2d1d949dec1db9fb413a02be422dfede3bb53aa
Author: Alexander Færøy <ahf at torproject.org>
Date:   Thu Apr 20 16:23:06 2017 +0200

    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
---
 src/or/config.c | 27 +++++++++++++++------------
 src/or/main.c   | 13 +++++++------
 2 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/src/or/config.c b/src/or/config.c
index 3549a1d..a73f397 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -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);
   }
diff --git a/src/or/main.c b/src/or/main.c
index f3a0d84..1ba6554 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -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 "





More information about the tor-commits mailing list