Browse Source

Bitmask out the compression methods that we do not support

Nick Mathewson 7 years ago
parent
commit
65ff0f8267
1 changed files with 17 additions and 0 deletions
  1. 17 0
      src/or/directory.c

+ 17 - 0
src/or/directory.c

@@ -2814,6 +2814,20 @@ parse_accept_encoding_header(const char *h)
   return result;
   return result;
 }
 }
 
 
+/** Bitmask of supported compression types, to use in a bitwise "and"
+ * with the results of parse_accept_encoding_header */
+static const unsigned SUPPORTED_COMPRESSION_MASK =
+    (1u << NO_METHOD)
+  | (1u << ZLIB_METHOD)
+  | (1u << GZIP_METHOD)
+#ifdef HAVE_ZSTD
+  | (1u << ZSTD_METHOD)
+#endif
+#ifdef HAVE_LZMA
+  | (1u << LZMA_METHOD)
+#endif
+  ;
+
 /** Decide whether a client would accept the consensus we have.
 /** Decide whether a client would accept the consensus we have.
  *
  *
  * Clients can say they only want a consensus if it's signed by more
  * Clients can say they only want a consensus if it's signed by more
@@ -3013,6 +3027,9 @@ directory_handle_command_get,(dir_connection_t *conn, const char *headers,
       compression_methods_supported |= (1u << ZLIB_METHOD);
       compression_methods_supported |= (1u << ZLIB_METHOD);
   }
   }
 
 
+  /* Remove all methods that we don't both support. */
+  compression_methods_supported &= SUPPORTED_COMPRESSION_MASK;
+
   get_handler_args_t args;
   get_handler_args_t args;
   args.url = url;
   args.url = url;
   args.headers = headers;
   args.headers = headers;