From 7614f0e55e7e71f4089f1e15d76aa7dcce49599e Mon Sep 17 00:00:00 2001 From: "Dr. Stephen Henson" Date: Mon, 5 Dec 2005 13:34:56 +0000 Subject: [PATCH] Various zlib related fixes and enhancements. --- CHANGES | 10 ++++ Configure | 6 ++ Makefile.org | 4 ++ crypto/comp/c_zlib.c | 130 +++++-------------------------------------- util/mk1mf.pl | 21 +++++-- util/pl/VC-32.pl | 4 +- 6 files changed, 55 insertions(+), 120 deletions(-) diff --git a/CHANGES b/CHANGES index 19ffb2bbdb..4a314be6a9 100644 --- a/CHANGES +++ b/CHANGES @@ -4,6 +4,16 @@ Changes between 0.9.8a and 0.9.8b [XX xxx XXXX] + *) Fixes and enhancements to zlib compression code. We now only use + "zlib1.dll" and use the default __cdecl calling convention on Win32 + to conform with the standards mentioned here: + http://www.zlib.net/DLL_FAQ.txt + Static zlib linking now works on Windows and the new --with-zlib-include + --with-zlib-lib options to Configure can be used to supply the location + of the headers and library. Gracefully handle case where zlib library + can't be loaded. + [Steve Henson] + *) Several fixes and enhancements to the OID generation code. The old code sometimes allowed invalid OIDs (1.X for X >= 40 for example), couldn't handle numbers larger than ULONG_MAX, truncated printing and had a diff --git a/Configure b/Configure index 855ad1522d..6b4727cffa 100755 --- a/Configure +++ b/Configure @@ -748,6 +748,10 @@ PROCESS_ARGS: { $withargs{"krb5-".$1}=$2; } + elsif (/^--with-zlib-(lib|include)=(.*)$/) + { + $withargs{"zlib-".$1}=$2; + } else { print STDERR $usage; @@ -1302,6 +1306,8 @@ while () s/^PERL=.*/PERL= $perl/; s/^KRB5_INCLUDES=.*/KRB5_INCLUDES=$withargs{"krb5-include"}/; s/^LIBKRB5=.*/LIBKRB5=$withargs{"krb5-lib"}/; + s/^LIBZLIB=.*/LIBZLIB=$withargs{"zlib-lib"}/; + s/^ZLIB_INCLUDE=.*/ZLIB_INCLUDE=$withargs{"zlib-include"}/; s/^SHLIB_TARGET=.*/SHLIB_TARGET=$shared_target/; s/^SHLIB_MARK=.*/SHLIB_MARK=$shared_mark/; s/^SHARED_LIBS=.*/SHARED_LIBS=\$(SHARED_CRYPTO) \$(SHARED_SSL)/ if (!$no_shared); diff --git a/Makefile.org b/Makefile.org index a28b469eaa..e65779cdd2 100644 --- a/Makefile.org +++ b/Makefile.org @@ -100,6 +100,10 @@ RMD160_ASM_OBJ= KRB5_INCLUDES= LIBKRB5= +# Zlib stuff +ZLIB_INCLUDE= +LIBZLIB= + DIRS= crypto ssl engines apps test tools SHLIBDIRS= crypto ssl diff --git a/crypto/comp/c_zlib.c b/crypto/comp/c_zlib.c index 1cd1a296af..941b807eb3 100644 --- a/crypto/comp/c_zlib.c +++ b/crypto/comp/c_zlib.c @@ -67,46 +67,25 @@ static COMP_METHOD zlib_stateful_method={ * When OpenSSL is built on Windows, we do not want to require that * the ZLIB.DLL be available in order for the OpenSSL DLLs to * work. Therefore, all ZLIB routines are loaded at run time - * and we do not link to a .LIB file. + * and we do not link to a .LIB file when ZLIB_SHARED is set. */ #if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32) # include - -# define Z_CALLCONV _stdcall -# ifndef ZLIB_SHARED -# define ZLIB_SHARED -# endif -#else -# define Z_CALLCONV #endif /* !(OPENSSL_SYS_WINDOWS || OPENSSL_SYS_WIN32) */ #ifdef ZLIB_SHARED #include -/* Prototypes for built in stubs */ -#if 0 -static int stub_compress(Bytef *dest,uLongf *destLen, - const Bytef *source, uLong sourceLen); -#endif -static int stub_inflateEnd(z_streamp strm); -static int stub_inflate(z_streamp strm, int flush); -static int stub_inflateInit_(z_streamp strm, const char * version, - int stream_size); -static int stub_deflateEnd(z_streamp strm); -static int stub_deflate(z_streamp strm, int flush); -static int stub_deflateInit_(z_streamp strm, int level, - const char * version, int stream_size); - /* Function pointers */ -typedef int (Z_CALLCONV *compress_ft)(Bytef *dest,uLongf *destLen, +typedef int (*compress_ft)(Bytef *dest,uLongf *destLen, const Bytef *source, uLong sourceLen); -typedef int (Z_CALLCONV *inflateEnd_ft)(z_streamp strm); -typedef int (Z_CALLCONV *inflate_ft)(z_streamp strm, int flush); -typedef int (Z_CALLCONV *inflateInit__ft)(z_streamp strm, +typedef int (*inflateEnd_ft)(z_streamp strm); +typedef int (*inflate_ft)(z_streamp strm, int flush); +typedef int (*inflateInit__ft)(z_streamp strm, const char * version, int stream_size); -typedef int (Z_CALLCONV *deflateEnd_ft)(z_streamp strm); -typedef int (Z_CALLCONV *deflate_ft)(z_streamp strm, int flush); -typedef int (Z_CALLCONV *deflateInit__ft)(z_streamp strm, int level, +typedef int (*deflateEnd_ft)(z_streamp strm); +typedef int (*deflate_ft)(z_streamp strm, int flush); +typedef int (*deflateInit__ft)(z_streamp strm, int level, const char * version, int stream_size); static compress_ft p_compress=NULL; static inflateEnd_ft p_inflateEnd=NULL; @@ -119,13 +98,13 @@ static deflateInit__ft p_deflateInit_=NULL; static int zlib_loaded = 0; /* only attempt to init func pts once */ static DSO *zlib_dso = NULL; -#define compress stub_compress -#define inflateEnd stub_inflateEnd -#define inflate stub_inflate -#define inflateInit_ stub_inflateInit_ -#define deflateEnd stub_deflateEnd -#define deflate stub_deflate -#define deflateInit_ stub_deflateInit_ +#define compress p_compress +#define inflateEnd p_inflateEnd +#define inflate p_inflate +#define inflateInit_ p_inflateInit_ +#define deflateEnd p_deflateEnd +#define deflate p_deflate +#define deflateInit_ p_deflateInit_ #endif /* ZLIB_SHARED */ struct zlib_state @@ -361,16 +340,6 @@ COMP_METHOD *COMP_zlib(void) { #if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32) zlib_dso = DSO_load(NULL, "ZLIB1", NULL, 0); - if (!zlib_dso) - { - zlib_dso = DSO_load(NULL, "ZLIB", NULL, 0); - if (zlib_dso) - { - /* Clear the errors from the first failed - DSO_load() */ - ERR_clear_error(); - } - } #else zlib_dso = DSO_load(NULL, "z", NULL, 0); #endif @@ -416,72 +385,3 @@ COMP_METHOD *COMP_zlib(void) return(meth); } -#ifdef ZLIB_SHARED -#if 0 -/* Stubs for each function to be dynamicly loaded */ -static int -stub_compress(Bytef *dest,uLongf *destLen,const Bytef *source, uLong sourceLen) - { - if (p_compress) - return(p_compress(dest,destLen,source,sourceLen)); - else - return(Z_MEM_ERROR); - } -#endif - -static int -stub_inflateEnd(z_streamp strm) - { - if ( p_inflateEnd ) - return(p_inflateEnd(strm)); - else - return(Z_MEM_ERROR); - } - -static int -stub_inflate(z_streamp strm, int flush) - { - if ( p_inflate ) - return(p_inflate(strm,flush)); - else - return(Z_MEM_ERROR); - } - -static int -stub_inflateInit_(z_streamp strm, const char * version, int stream_size) - { - if ( p_inflateInit_ ) - return(p_inflateInit_(strm,version,stream_size)); - else - return(Z_MEM_ERROR); - } - -static int -stub_deflateEnd(z_streamp strm) - { - if ( p_deflateEnd ) - return(p_deflateEnd(strm)); - else - return(Z_MEM_ERROR); - } - -static int -stub_deflate(z_streamp strm, int flush) - { - if ( p_deflate ) - return(p_deflate(strm,flush)); - else - return(Z_MEM_ERROR); - } - -static int -stub_deflateInit_(z_streamp strm, int level, - const char * version, int stream_size) - { - if ( p_deflateInit_ ) - return(p_deflateInit_(strm,level,version,stream_size)); - else - return(Z_MEM_ERROR); - } - -#endif /* ZLIB_SHARED */ diff --git a/util/mk1mf.pl b/util/mk1mf.pl index 2404aee299..bf4f89f48c 100755 --- a/util/mk1mf.pl +++ b/util/mk1mf.pl @@ -12,6 +12,8 @@ $banner="\t\@echo Building OpenSSL"; my $no_static_engine = 0; my $engines = ""; +local $zlib_opt = 0; # 0 = no zlib, 1 = static, 2 = dynamic +local $zlib_lib = ""; open(IN," " -DOPENSSL_BUILD_SHLIBSSL", "CRYPTO" => " -DOPENSSL_BUILD_SHLIBCRYPTO"); @@ -284,8 +290,14 @@ for (;;) if ($key eq "KRB5_INCLUDES") { $cflags .= " $val";} + if ($key eq "ZLIB_INCLUDE") + { $cflags .= " -I$val";} + + if ($key eq "LIBZLIB") + { $zlib_lib = "$val" if $val ne "";} + if ($key eq "LIBKRB5") - { $ex_libs .= " $val";} + { $ex_libs .= " $val" if $val ne "";} if ($key eq "TEST") { $test.=&var_add($dir,$val, 0); } @@ -337,6 +349,7 @@ else \$(CP) \$(O_SSL) \$(INSTALLTOP)${o}lib \$(CP) \$(O_CRYPTO) \$(INSTALLTOP)${o}lib EOF + $ex_libs .= " $zlib_lib" if $zlib_opt == 1; } $defs= <<"EOF"; @@ -831,7 +844,7 @@ sub do_defs $ret.=$t; } # hack to add version info on MSVC - if ($shlib && ($platform eq "VC-WIN32") || ($platform eq "VC-NT")) + if ($shlib && (($platform eq "VC-WIN32") || ($platform eq "VC-NT"))) { if ($var eq "CRYPTOOBJ") { $ret.="\$(OBJ_D)\\\$(CRYPTO).res "; } @@ -1016,10 +1029,10 @@ sub read_options } } elsif (/^no-comp$/) { $xcflags = "-DOPENSSL_NO_COMP $xcflags"; } - elsif (/^enable-zlib$/) { $xcflags = "-DZLIB $xcflags"; } + elsif (/^enable-zlib$/) { $zlib_opt = 1 if $zlib_opt == 0 } elsif (/^enable-zlib-dynamic$/) { - $xcflags = "-DZLIB_SHARED -DZLIB $xcflags"; + $zlib_opt = 2; } elsif (/^no-static-engine/) { diff --git a/util/pl/VC-32.pl b/util/pl/VC-32.pl index 90bcd4207c..d946ce4a3a 100644 --- a/util/pl/VC-32.pl +++ b/util/pl/VC-32.pl @@ -11,6 +11,8 @@ $cp='$(PERL) util/copy.pl'; $mkdir='$(PERL) util/mkdir-p.pl'; $rm='del'; +$zlib_lib="zlib1.lib"; + # C compiler stuff $cc='cl'; if ($FLAVOR =~ /WIN64/) @@ -143,7 +145,6 @@ if ($FLAVOR =~ /NT/) $cflags.=" -DOPENSSL_SYSNAME_WINNT -DUNICODE -D_UNICODE"; $ex_libs="unicows.lib $ex_libs"; } - # static library stuff $mklib='lib'; $ranlib=''; @@ -272,6 +273,7 @@ sub do_lib_rule $ex.=' wsock32.lib gdi32.lib advapi32.lib user32.lib'; $ex.=' bufferoverflowu.lib' if ($FLAVOR =~ /WIN64/); } + $ex.=" $zlib_lib" if $zlib_opt == 1 && $target =~ /O_CRYPTO/; $ret.="\t\$(LINK) \$(MLFLAGS) $efile$target $name @<<\n \$(SHLIB_EX_OBJ) $objs $ex\n<<\n"; } $ret.="\n"; -- 2.25.1