Backport of zlib fixes to 0.9.7.
authorDr. Stephen Henson <steve@openssl.org>
Sat, 10 Dec 2005 13:36:13 +0000 (13:36 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Sat, 10 Dec 2005 13:36:13 +0000 (13:36 +0000)
Configure
crypto/comp/c_zlib.c
util/mk1mf.pl
util/pl/VC-32.pl

index 71180d8d2dd8c9203d9c9f205d0ea5a722125cbd..2a1366d37a187106044b5a84221758a9dbf72602 100755 (executable)
--- a/Configure
+++ b/Configure
@@ -865,6 +865,14 @@ PROCESS_ARGS:
                                {
                                $withargs{"krb5-".$1}=$2;
                                }
+                       elsif (/^--with-zlib-lib=(.*)$/)
+                               {
+                               $withargs{"zlib-lib"}=$1;
+                               }
+                       elsif (/^--with-zlib-include=(.*)$/)
+                               {
+                               $withargs{"zlib-include"}="-I$1";
+                               }
                        else
                                {
                                print STDERR $usage;
@@ -1308,6 +1316,8 @@ while (<IN>)
        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);
index a896bdebd99f6f5a6fcf5ca7fec36d992c2c45ce..5fcb521ffb4766cf58d05749b03f08ddd8916c4f 100644 (file)
@@ -51,32 +51,17 @@ static COMP_METHOD zlib_method={
  */
 #if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)
 # include <windows.h>
-
-# 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 <openssl/dso.h>
 
-/* Prototypes for built in stubs */
-static int stub_compress(Bytef *dest,uLongf *destLen,
-       const Bytef *source, uLong sourceLen);
-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);
-
 /* 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);
 static compress_ft     p_compress=NULL;
 static inflateEnd_ft   p_inflateEnd=NULL;
@@ -86,10 +71,10 @@ static inflateInit__ft      p_inflateInit_=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 compress                p_compress
+#define inflateEnd              p_inflateEnd
+#define inflate                 p_inflate
+#define inflateInit_            p_inflateInit_
 #endif /* ZLIB_SHARED */
 
 static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out,
@@ -193,16 +178,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
@@ -220,54 +195,21 @@ COMP_METHOD *COMP_zlib(void)
                        p_inflateInit_
                                = (inflateInit__ft) DSO_bind_func(zlib_dso,
                                        "inflateInit_");
-                       zlib_loaded++;
+
+                       if (p_compress && p_inflateEnd && p_inflate
+                               && p_inflateInit_)
+                               zlib_loaded++;
                        }
                }
 
 #endif
+#ifdef ZLIB_SHARED
+       if (zlib_loaded)
+#endif
 #if defined(ZLIB) || defined(ZLIB_SHARED)
-       meth = &zlib_method;
+               meth = &zlib_method;
 #endif
 
        return(meth);
        }
 
-#ifdef ZLIB_SHARED
-/* 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);
-       }
-
-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);
-       }
-
-#endif /* ZLIB_SHARED */
index 20691546a54859d76691e30ee0ee754dcc18856e..0e1c180273c88c8634542c373bda034c21bbba74 100755 (executable)
@@ -10,6 +10,9 @@ $OPTIONS="";
 $ssl_version="";
 $banner="\t\@echo Building OpenSSL";
 
+local $zlib_opt = 0;   # 0 = no zlib, 1 = static, 2 = dynamic
+local $zlib_lib = "";
+
 open(IN,"<Makefile") || die "unable to open Makefile!\n";
 while(<IN>) {
     $ssl_version=$1 if (/^VERSION=(.*)$/);
@@ -242,6 +245,9 @@ $cflags.=" -DOPENSSL_NO_HW"   if $no_hw;
 $cflags.=" -DOPENSSL_FIPS"    if $fips;
 #$cflags.=" -DRSAref"  if $rsaref ne "";
 
+$cflags.= " -DZLIB" if $zlib_opt;
+$cflags.= " -DZLIB_SHARED" if $zlib_opt == 2;
+
 ## if ($unix)
 ##     { $cflags="$c_flags" if ($c_flags ne ""); }
 ##else
@@ -249,6 +255,7 @@ $cflags.=" -DOPENSSL_FIPS"    if $fips;
 
 $ex_libs="$l_flags$ex_libs" if ($l_flags ne "");
 
+
 %shlib_ex_cflags=("SSL" => " -DOPENSSL_BUILD_SHLIBSSL",
                  "CRYPTO" => " -DOPENSSL_BUILD_SHLIBCRYPTO");
 
@@ -293,8 +300,14 @@ for (;;)
        if ($key eq "KRB5_INCLUDES")
                { $cflags .= " $val";}
 
+       if ($key eq "ZLIB_INCLUDE")
+               { $cflags .= " $val" if $val ne "";}
+
+       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); }
@@ -346,6 +359,7 @@ if ($platform eq "VC-CE")
 !INCLUDE <\$(WCECOMPAT)/wcedefs.mak>
 
 EOF
+       $ex_libs .= " $zlib_lib" if $zlib_opt == 1;
        }
 
 $defs.= <<"EOF";
@@ -944,8 +958,8 @@ sub read_options
        elsif (/^shlib$/)       { $shlib=1; }
        elsif (/^dll$/)         { $shlib=1; }
        elsif (/^shared$/)      { } # We just need to ignore it for now...
-       elsif (/^zlib$/)        { $xcflags = "-DZLIB $xcflags"; }
-       elsif (/^zlib-dynamic$/){ $xcflags = "-DZLIB_SHARED -DZLIB $xcflags"; }
+       elsif (/^zlib$/) { $zlib_opt = 1 if $zlib_opt == 0 }
+       elsif (/^zlib-dynamic$/){ $zlib_opt = 2; }
        elsif (/^--with-krb5-flavor=(.*)$/)
                {
                my $krb5_flavor = $1;
index 453d23595977b05dcba585b782f2aa4288adcd6c..ca9514f13512200215f2e841e1af5064a9ad3947 100644 (file)
@@ -9,6 +9,8 @@ $o='\\';
 $cp='copy nul+';       # Timestamps get stuffed otherwise
 $rm='del';
 
+$zlib_lib="zlib1.lib";
+
 # C compiler stuff
 $cc='cl';
 $cflags=' /MD /W3 /WX /G5 /Ox /O2 /Ob2 /Gs0 /GF /Gy /nologo -DOPENSSL_SYSNAME_WIN32 -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -DDSO_WIN32';
@@ -119,6 +121,7 @@ sub do_lib_rule
                {
                local($ex)=($target =~ /O_SSL/)?' $(L_CRYPTO)':'';
                $ex.=' wsock32.lib gdi32.lib advapi32.lib user32.lib';
+               $ex.=" $zlib_lib" if $zlib_opt == 1 && $target =~ /O_CRYPTO/;
                $ret.="\t\$(LINK) \$(MLFLAGS) $efile$target /def:ms/${Name}.def @<<\n  \$(SHLIB_EX_OBJ) $objs $ex\n<<\n";
                }
        $ret.="\n";