From 13cb50cbe2d4a686dc5185ebe222a895fff2515a Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Mon, 3 Nov 2014 16:58:29 +0000 Subject: minor cleanup of zlib code. DSO is gone. ok jsing. --- lib/libssl/src/crypto/comp/c_rle.c | 5 +- lib/libssl/src/crypto/comp/c_zlib.c | 201 +--------------------------------- lib/libssl/src/crypto/comp/comp.h | 6 +- lib/libssl/src/crypto/comp/comp_err.c | 7 +- lib/libssl/src/crypto/comp/comp_lib.c | 5 +- 5 files changed, 7 insertions(+), 217 deletions(-) diff --git a/lib/libssl/src/crypto/comp/c_rle.c b/lib/libssl/src/crypto/comp/c_rle.c index 214efe01b2a..7004c350299 100644 --- a/lib/libssl/src/crypto/comp/c_rle.c +++ b/lib/libssl/src/crypto/comp/c_rle.c @@ -1,4 +1,4 @@ -/* $OpenBSD: c_rle.c,v 1.7 2014/06/12 15:49:28 deraadt Exp $ */ +/* $OpenBSD: c_rle.c,v 1.8 2014/11/03 16:58:28 tedu Exp $ */ #include #include #include @@ -27,10 +27,8 @@ static int rle_compress_block(COMP_CTX *ctx, unsigned char *out, unsigned int olen, unsigned char *in, unsigned int ilen) { - /* int i; */ if (ilen == 0 || olen < (ilen - 1)) { - /* ZZZZZZZZZZZZZZZZZZZZZZ */ return (-1); } @@ -46,7 +44,6 @@ rle_expand_block(COMP_CTX *ctx, unsigned char *out, unsigned int olen, int i; if (olen < (ilen - 1)) { - /* ZZZZZZZZZZZZZZZZZZZZZZ */ return (-1); } diff --git a/lib/libssl/src/crypto/comp/c_zlib.c b/lib/libssl/src/crypto/comp/c_zlib.c index 11b95fb7993..4951ade8103 100644 --- a/lib/libssl/src/crypto/comp/c_zlib.c +++ b/lib/libssl/src/crypto/comp/c_zlib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: c_zlib.c,v 1.16 2014/06/12 15:49:28 deraadt Exp $ */ +/* $OpenBSD: c_zlib.c,v 1.17 2014/11/03 16:58:28 tedu Exp $ */ #include #include #include @@ -13,9 +13,7 @@ static COMP_METHOD zlib_method_nozlib = { .name = "(undef)" }; -#ifndef ZLIB -#undef ZLIB_SHARED -#else +#ifdef ZLIB #include @@ -40,23 +38,6 @@ zlib_zfree(void* opaque, void* address) free(address); } -#if 0 -static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out, - unsigned int olen, unsigned char *in, unsigned int ilen); -static int zlib_expand_block(COMP_CTX *ctx, unsigned char *out, - unsigned int olen, unsigned char *in, unsigned int ilen); - -static int zz_uncompress(Bytef *dest, uLongf *destLen, const Bytef *source, - uLong sourceLen); - -static COMP_METHOD zlib_stateless_method = { - .type = NID_zlib_compression, - .name = LN_zlib_compression, - .compress = zlib_compress_block, - .expand = zlib_expand_block -}; -#endif - static COMP_METHOD zlib_stateful_method = { .type = NID_zlib_compression, .name = LN_zlib_compression, @@ -66,43 +47,6 @@ static COMP_METHOD zlib_stateful_method = { .expand = zlib_stateful_expand_block }; -#ifdef ZLIB_SHARED -#include - -/* Function pointers */ -typedef int (*compress_ft)(Bytef *dest, uLongf *destLen, const Bytef *source, - uLong sourceLen); -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 (*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); -typedef const char * (*zError__ft)(int err); -static compress_ft p_compress = NULL; -static inflateEnd_ft p_inflateEnd = NULL; -static inflate_ft p_inflate = NULL; -static inflateInit__ft p_inflateInit_ = NULL; -static deflateEnd_ft p_deflateEnd = NULL; -static deflate_ft p_deflate = NULL; -static deflateInit__ft p_deflateInit_ = NULL; -static zError__ft p_zError = NULL; - -static int zlib_loaded = 0; /* only attempt to init func pts once */ -static DSO *zlib_dso = NULL; - -#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_ -#define zError p_zError -#endif /* ZLIB_SHARED */ - struct zlib_state { z_stream istream; z_stream ostream; @@ -225,102 +169,6 @@ zlib_stateful_expand_block(COMP_CTX *ctx, unsigned char *out, return olen - state->istream.avail_out; } -#if 0 -static int -zlib_compress_block(COMP_CTX *ctx, unsigned char *out, - unsigned int olen, unsigned char *in, unsigned int ilen) -{ - unsigned long l; - int i; - int clear = 1; - - if (ilen > 128) { - out[0] = 1; - l = olen - 1; - i = compress(&(out[1]), &l, in, (unsigned long)ilen); - if (i != Z_OK) - return (-1); - if (ilen > l) { - clear = 0; - l++; - } - } - if (clear) { - out[0] = 0; - memcpy(&(out[1]), in, ilen); - l = ilen + 1; - } - -#ifdef DEBUG_ZLIB - fprintf(stderr, "compress(%4d)->%4d %s\n", - ilen,(int)l, (clear)?"clear":"zlib"); -#endif - - return ((int)l); -} - -static int -zlib_expand_block(COMP_CTX *ctx, unsigned char *out, unsigned int olen, - unsigned char *in, unsigned int ilen) -{ - unsigned long l; - int i; - - if (in[0]) { - l = olen; - i = zz_uncompress(out, &l, &(in[1]), (unsigned long)ilen - 1); - if (i != Z_OK) - return (-1); - } else { - memcpy(out, &(in[1]), ilen - 1); - l = ilen - 1; - } - -#ifdef DEBUG_ZLIB - fprintf(stderr, "expand (%4d)->%4d %s\n", - ilen,(int)l, in[0]?"zlib":"clear"); -#endif - - return ((int)l); -} - -static int -zz_uncompress(Bytef *dest, uLongf *destLen, const Bytef *source, - uLong sourceLen) -{ - z_stream stream; - int err; - - stream.next_in = (Bytef*)source; - stream.avail_in = (uInt)sourceLen; - /* Check for source > 64K on 16-bit machine: */ - if ((uLong)stream.avail_in != sourceLen) - return Z_BUF_ERROR; - - stream.next_out = dest; - stream.avail_out = (uInt)*destLen; - if ((uLong)stream.avail_out != *destLen) - return Z_BUF_ERROR; - - stream.zalloc = (alloc_func)0; - stream.zfree = (free_func)0; - - err = inflateInit_(&stream, ZLIB_VERSION, sizeof(z_stream)); - if (err != Z_OK) - return err; - - err = inflate(&stream, Z_FINISH); - if (err != Z_STREAM_END) { - inflateEnd(&stream); - return err; - } - *destLen = stream.total_out; - - err = inflateEnd(&stream); - return err; -} -#endif - #endif COMP_METHOD * @@ -328,39 +176,7 @@ COMP_zlib(void) { COMP_METHOD *meth = &zlib_method_nozlib; -#ifdef ZLIB_SHARED - if (!zlib_loaded) { - zlib_dso = DSO_load(NULL, "z", NULL, 0); - if (zlib_dso != NULL) { - p_compress = (compress_ft)DSO_bind_func( - zlib_dso, "compress"); - p_inflateEnd = (inflateEnd_ft)DSO_bind_func( - zlib_dso, "inflateEnd"); - p_inflate = (inflate_ft)DSO_bind_func( - zlib_dso, "inflate"); - p_inflateInit_ = (inflateInit__ft)DSO_bind_func( - zlib_dso, "inflateInit_"); - p_deflateEnd = (deflateEnd_ft)DSO_bind_func( - zlib_dso, "deflateEnd"); - p_deflate = (deflate_ft)DSO_bind_func( - zlib_dso, "deflate"); - p_deflateInit_ = (deflateInit__ft)DSO_bind_func( - zlib_dso, "deflateInit_"); - p_zError = (zError__ft)DSO_bind_func( - zlib_dso, "zError"); - - if (p_compress && p_inflateEnd && p_inflate && - p_inflateInit_ && p_deflateEnd && p_deflate && - p_deflateInit_ && p_zError) - zlib_loaded++; - } - } - -#endif -#ifdef ZLIB_SHARED - if (zlib_loaded) -#endif -#if defined(ZLIB) || defined(ZLIB_SHARED) +#ifdef ZLIB { /* init zlib_stateful_ex_idx here so that in a multi-process * application it's enough to intialize openssl before forking @@ -388,10 +204,6 @@ err: void COMP_zlib_cleanup(void) { -#ifdef ZLIB_SHARED - if (zlib_dso) - DSO_free(zlib_dso); -#endif } #ifdef ZLIB @@ -443,13 +255,6 @@ bio_zlib_new(BIO *bi) { BIO_ZLIB_CTX *ctx; -#ifdef ZLIB_SHARED - (void)COMP_zlib(); - if (!zlib_loaded) { - COMPerr(COMP_F_BIO_ZLIB_NEW, COMP_R_ZLIB_NOT_SUPPORTED); - return 0; - } -#endif ctx = malloc(sizeof(BIO_ZLIB_CTX)); if (!ctx) { COMPerr(COMP_F_BIO_ZLIB_NEW, ERR_R_MALLOC_FAILURE); diff --git a/lib/libssl/src/crypto/comp/comp.h b/lib/libssl/src/crypto/comp/comp.h index d1e252988b3..fe7397f8ea4 100644 --- a/lib/libssl/src/crypto/comp/comp.h +++ b/lib/libssl/src/crypto/comp/comp.h @@ -1,4 +1,4 @@ -/* $OpenBSD: comp.h,v 1.7 2014/06/12 15:49:28 deraadt Exp $ */ +/* $OpenBSD: comp.h,v 1.8 2014/11/03 16:58:28 tedu Exp $ */ #ifndef HEADER_COMP_H #define HEADER_COMP_H @@ -52,10 +52,6 @@ BIO_METHOD *BIO_f_zlib(void); #endif #endif -/* BEGIN ERROR CODES */ -/* The following lines are auto generated by the script mkerr.pl. Any changes - * made after this point may be overwritten when the script is next run. - */ void ERR_load_COMP_strings(void); /* Error codes for the COMP functions. */ diff --git a/lib/libssl/src/crypto/comp/comp_err.c b/lib/libssl/src/crypto/comp/comp_err.c index 1174df430fa..3f796d4069b 100644 --- a/lib/libssl/src/crypto/comp/comp_err.c +++ b/lib/libssl/src/crypto/comp/comp_err.c @@ -1,4 +1,4 @@ -/* $OpenBSD: comp_err.c,v 1.8 2014/07/10 22:45:56 jsing Exp $ */ +/* $OpenBSD: comp_err.c,v 1.9 2014/11/03 16:58:28 tedu Exp $ */ /* ==================================================================== * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved. * @@ -53,11 +53,6 @@ * */ -/* NOTE: this file was auto generated by the mkerr.pl script: any changes - * made to it will be overwritten when the script next updates this file, - * only reason strings will be preserved. - */ - #include #include diff --git a/lib/libssl/src/crypto/comp/comp_lib.c b/lib/libssl/src/crypto/comp/comp_lib.c index 78a01a698cc..dde238ef728 100644 --- a/lib/libssl/src/crypto/comp/comp_lib.c +++ b/lib/libssl/src/crypto/comp/comp_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: comp_lib.c,v 1.7 2014/06/12 15:49:28 deraadt Exp $ */ +/* $OpenBSD: comp_lib.c,v 1.8 2014/11/03 16:58:28 tedu Exp $ */ #include #include #include @@ -11,7 +11,6 @@ COMP_CTX_new(COMP_METHOD *meth) COMP_CTX *ret; if ((ret = calloc(1, sizeof(COMP_CTX))) == NULL) { - /* ZZZZZZZZZZZZZZZZ */ return (NULL); } ret->meth = meth; @@ -41,7 +40,6 @@ COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen, int ret; if (ctx->meth->compress == NULL) { - /* ZZZZZZZZZZZZZZZZZ */ return (-1); } ret = ctx->meth->compress(ctx, out, olen, in, ilen); @@ -59,7 +57,6 @@ COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen, int ret; if (ctx->meth->expand == NULL) { - /* ZZZZZZZZZZZZZZZZZ */ return (-1); } ret = ctx->meth->expand(ctx, out, olen, in, ilen); -- cgit v1.2.3