Browse Source

Convert ZLIB defines to OPENSSL_NO_ZLIB

Use the normal OPENSSL_NO_ prefix to enable/disable ZLIB
Make `BIO_f_zlib()` always available.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18186)
Todd Short 1 year ago
parent
commit
59d21298df
11 changed files with 26 additions and 24 deletions
  1. 1 1
      Configure
  2. 7 7
      apps/enc.c
  3. 1 1
      apps/list.c
  4. 1 3
      apps/progs.pl
  5. 1 1
      crypto/cms/cms_cd.c
  6. 1 1
      crypto/cms/cms_lib.c
  7. 1 1
      crypto/cms/cms_smime.c
  8. 10 4
      crypto/comp/c_zlib.c
  9. 0 2
      include/openssl/comp.h
  10. 2 2
      test/bio_comp_test.c
  11. 1 1
      util/libcrypto.num

+ 1 - 1
Configure

@@ -1845,7 +1845,7 @@ foreach my $what (sort keys %disabled) {
 
     if (!grep { $what eq $_ } ( 'buildtest-c++', 'fips', 'threads', 'shared',
                                 'module', 'pic', 'dynamic-engine', 'makedepend',
-                                'zlib-dynamic', 'zlib', 'sse2', 'legacy' )) {
+                                'sse2', 'legacy' )) {
         (my $WHAT = uc $what) =~ s|-|_|g;
         my $skipdir = $what;
 

+ 7 - 7
apps/enc.c

@@ -91,7 +91,7 @@ const OPTIONS enc_options[] = {
     {"iter", OPT_ITER, 'p', "Specify the iteration count and force use of PBKDF2"},
     {"pbkdf2", OPT_PBKDF2, '-', "Use password-based key derivation function 2"},
     {"none", OPT_NONE, '-', "Don't encrypt"},
-#ifdef ZLIB
+#ifndef OPENSSL_NO_ZLIB
     {"z", OPT_Z, '-', "Compress or decompress encrypted data using zlib"},
 #endif
     {"", OPT_CIPHER, '-', "Any supported cipher"},
@@ -130,7 +130,7 @@ int enc_main(int argc, char **argv)
     int streamable = 1;
     int wrap = 0;
     struct doall_enc_ciphers dec;
-#ifdef ZLIB
+#ifndef OPENSSL_NO_ZLIB
     int do_zlib = 0;
     BIO *bzl = NULL;
 #endif
@@ -142,7 +142,7 @@ int enc_main(int argc, char **argv)
     /* first check the command name */
     if (strcmp(argv[0], "base64") == 0)
         base64 = 1;
-#ifdef ZLIB
+#ifndef OPENSSL_NO_ZLIB
     else if (strcmp(argv[0], "zlib") == 0)
         do_zlib = 1;
 #endif
@@ -225,7 +225,7 @@ int enc_main(int argc, char **argv)
             base64 = 1;
             break;
         case OPT_Z:
-#ifdef ZLIB
+#ifndef OPENSSL_NO_ZLIB
             do_zlib = 1;
 #endif
             break;
@@ -332,7 +332,7 @@ int enc_main(int argc, char **argv)
     if (verbose)
         BIO_printf(bio_err, "bufsize=%d\n", bsize);
 
-#ifdef ZLIB
+#ifndef OPENSSL_NO_ZLIB
     if (do_zlib)
         base64 = 0;
 #endif
@@ -417,7 +417,7 @@ int enc_main(int argc, char **argv)
     wbio = out;
 
 #ifndef OPENSSL_NO_COMP
-# ifdef ZLIB
+# ifndef OPENSSL_NO_ZLIB
     if (do_zlib) {
         if ((bzl = BIO_new(BIO_f_zlib())) == NULL)
             goto end;
@@ -699,7 +699,7 @@ int enc_main(int argc, char **argv)
     BIO_free(b64);
     EVP_MD_free(dgst);
     EVP_CIPHER_free(cipher);
-#ifdef ZLIB
+#ifndef OPENSSL_NO_ZLIB
     BIO_free(bzl);
 #endif
     BIO_free(bbrot);

+ 1 - 1
apps/list.c

@@ -1421,7 +1421,7 @@ static void list_disabled(void)
 #ifdef OPENSSL_NO_WHIRLPOOL
     BIO_puts(bio_out, "WHIRLPOOL\n");
 #endif
-#ifndef ZLIB
+#ifdef OPENSSL_NO_ZLIB
     BIO_puts(bio_out, "ZLIB\n");
 #endif
 #ifdef OPENSSL_NO_BROTLI

+ 1 - 3
apps/progs.pl

@@ -205,9 +205,7 @@ EOF
     ) {
         my $str = "    {FT_cipher, \"$cmd\", enc_main, enc_options, NULL},\n";
         (my $algo = $cmd) =~ s/-.*//g;
-        if ($cmd eq "zlib") {
-            print "#ifdef ZLIB\n${str}#endif\n";
-        } elsif (grep { $algo eq $_ } @disablables) {
+        if (grep { $algo eq $_ } @disablables) {
             print "#ifndef OPENSSL_NO_" . uc($algo) . "\n${str}#endif\n";
         } elsif (my $disabler = $cipher_disabler{$algo}) {
             print "#ifndef OPENSSL_NO_" . uc($disabler) . "\n${str}#endif\n";

+ 1 - 1
crypto/cms/cms_cd.c

@@ -17,7 +17,7 @@
 #include <openssl/comp.h>
 #include "cms_local.h"
 
-#ifdef ZLIB
+#ifndef OPENSSL_NO_ZLIB
 
 /* CMS CompressedData Utilities */
 

+ 1 - 1
crypto/cms/cms_lib.c

@@ -174,7 +174,7 @@ BIO *CMS_dataInit(CMS_ContentInfo *cms, BIO *icont)
     case NID_pkcs7_digest:
         cmsbio = ossl_cms_DigestedData_init_bio(cms);
         break;
-#ifdef ZLIB
+#ifndef OPENSSL_NO_ZLIB
     case NID_id_smime_ct_compressedData:
         cmsbio = ossl_cms_CompressedData_init_bio(cms);
         break;

+ 1 - 1
crypto/cms/cms_smime.c

@@ -930,7 +930,7 @@ err:
     return ret;
 }
 
-#ifdef ZLIB
+#ifndef OPENSSL_NO_ZLIB
 
 int CMS_uncompress(CMS_ContentInfo *cms, BIO *dcont, BIO *out,
                    unsigned int flags)

+ 10 - 4
crypto/comp/c_zlib.c

@@ -29,7 +29,7 @@ static COMP_METHOD zlib_method_nozlib = {
     NULL,
 };
 
-#ifndef ZLIB
+#ifdef OPENSSL_NO_ZLIB
 # undef ZLIB_SHARED
 #else
 
@@ -247,7 +247,7 @@ COMP_METHOD *COMP_zlib(void)
 {
     COMP_METHOD *meth = &zlib_method_nozlib;
 
-#ifdef ZLIB
+#ifndef OPENSSL_NO_ZLIB
     if (RUN_ONCE(&zlib_once, ossl_comp_zlib_init))
         meth = &zlib_stateful_method;
 #endif
@@ -264,7 +264,7 @@ void ossl_comp_zlib_cleanup(void)
 #endif
 }
 
-#ifdef ZLIB
+#ifndef OPENSSL_NO_ZLIB
 
 /* Zlib based compression/decompression filter BIO */
 
@@ -304,12 +304,18 @@ static const BIO_METHOD bio_meth_zlib = {
     bio_zlib_free,
     bio_zlib_callback_ctrl
 };
+#endif
 
 const BIO_METHOD *BIO_f_zlib(void)
 {
-    return &bio_meth_zlib;
+#ifndef OPENSSL_NO_ZLIB
+    if (RUN_ONCE(&zlib_once, ossl_comp_zlib_init))
+        return &bio_meth_zlib;
+#endif
+    return NULL;
 }
 
+#ifndef OPENSSL_NO_ZLIB
 static int bio_zlib_new(BIO *bi)
 {
     BIO_ZLIB_CTX *ctx;

+ 0 - 2
include/openssl/comp.h

@@ -50,9 +50,7 @@ COMP_METHOD *COMP_zstd_oneshot(void);
 #endif
 
 # ifdef OPENSSL_BIO_H
-#  ifdef ZLIB
 const BIO_METHOD *BIO_f_zlib(void);
-#  endif
 const BIO_METHOD *BIO_f_brotli(void);
 const BIO_METHOD *BIO_f_zstd(void);
 # endif

+ 2 - 2
test/bio_comp_test.c

@@ -129,7 +129,7 @@ static int test_brotli(int n)
     return do_bio_comp(BIO_f_brotli(), n);
 }
 #endif
-#ifdef ZLIB
+#ifndef OPENSSL_NO_ZLIB
 static int test_zlib(int n)
 {
     return do_bio_comp(BIO_f_zlib(), n);
@@ -138,7 +138,7 @@ static int test_zlib(int n)
 
 int setup_tests(void)
 {
-#ifdef ZLIB
+#ifndef OPENSSL_NO_ZLIB
     ADD_ALL_TESTS(test_zlib, NUM_SIZES * 4);
 #endif
 #ifndef OPENSSL_NO_BROTLI

+ 1 - 1
util/libcrypto.num

@@ -2443,7 +2443,7 @@ ASN1_STRING_type_new                    2494	3_0_0	EXIST::FUNCTION:
 TS_STATUS_INFO_free                     2495	3_0_0	EXIST::FUNCTION:TS
 BN_mod_mul                              2496	3_0_0	EXIST::FUNCTION:
 CMS_add0_recipient_key                  2497	3_0_0	EXIST::FUNCTION:CMS
-BIO_f_zlib                              2498	3_0_0	EXIST::FUNCTION:COMP,ZLIB
+BIO_f_zlib                              2498	3_0_0	EXIST::FUNCTION:COMP
 AES_cfb128_encrypt                      2499	3_0_0	EXIST::FUNCTION:DEPRECATEDIN_3_0
 ENGINE_set_EC                           2500	3_0_0	EXIST::FUNCTION:DEPRECATEDIN_3_0,ENGINE
 d2i_ECPKParameters                      2501	3_0_0	EXIST::FUNCTION:EC