diff options
author | Todd Short <tshort@akamai.com> | 2022-08-29 14:58:57 -0400 |
---|---|---|
committer | Todd Short <todd.short@me.com> | 2022-10-18 09:30:22 -0400 |
commit | 7e3cacac943d298348d97c8f7f980ca0916378c5 (patch) | |
tree | 23add0038a61ce3ee2a0c6ec6f5c04c96a74f948 /crypto/comp/c_zlib.c | |
parent | b540aae97d6b80f9040874b9c56259a85ba46f36 (diff) |
Update COMP_METHOD
size_t-ify the COMP_METHOD structure and functions.
Get rid of the non-functional COMP_METHODS and return NULL instead.
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18186)
Diffstat (limited to 'crypto/comp/c_zlib.c')
-rw-r--r-- | crypto/comp/c_zlib.c | 43 |
1 files changed, 19 insertions, 24 deletions
diff --git a/crypto/comp/c_zlib.c b/crypto/comp/c_zlib.c index 426b8b0b74..ba5a8d9ce4 100644 --- a/crypto/comp/c_zlib.c +++ b/crypto/comp/c_zlib.c @@ -20,15 +20,6 @@ COMP_METHOD *COMP_zlib(void); -static COMP_METHOD zlib_method_nozlib = { - NID_undef, - "(undef)", - NULL, - NULL, - NULL, - NULL, -}; - #ifdef OPENSSL_NO_ZLIB # undef ZLIB_SHARED #else @@ -37,12 +28,12 @@ static COMP_METHOD zlib_method_nozlib = { static int zlib_stateful_init(COMP_CTX *ctx); static void zlib_stateful_finish(COMP_CTX *ctx); -static int zlib_stateful_compress_block(COMP_CTX *ctx, unsigned char *out, - unsigned int olen, unsigned char *in, - unsigned int ilen); -static int zlib_stateful_expand_block(COMP_CTX *ctx, unsigned char *out, - unsigned int olen, unsigned char *in, - unsigned int ilen); +static ossl_ssize_t zlib_stateful_compress_block(COMP_CTX *ctx, unsigned char *out, + size_t olen, unsigned char *in, + size_t ilen); +static ossl_ssize_t zlib_stateful_expand_block(COMP_CTX *ctx, unsigned char *out, + size_t olen, unsigned char *in, + size_t ilen); /* memory allocations functions for zlib initialisation */ static void *zlib_zalloc(void *opaque, unsigned int no, unsigned int size) @@ -162,9 +153,9 @@ static void zlib_stateful_finish(COMP_CTX *ctx) OPENSSL_free(state); } -static int zlib_stateful_compress_block(COMP_CTX *ctx, unsigned char *out, - unsigned int olen, unsigned char *in, - unsigned int ilen) +static ossl_ssize_t zlib_stateful_compress_block(COMP_CTX *ctx, unsigned char *out, + size_t olen, unsigned char *in, + size_t ilen) { int err = Z_OK; struct zlib_state *state = ctx->data; @@ -180,12 +171,14 @@ static int zlib_stateful_compress_block(COMP_CTX *ctx, unsigned char *out, err = deflate(&state->ostream, Z_SYNC_FLUSH); if (err != Z_OK) return -1; - return olen - state->ostream.avail_out; + if (state->ostream.avail_out > olen) + return -1; + return (ossl_ssize_t)(olen - state->ostream.avail_out); } -static int zlib_stateful_expand_block(COMP_CTX *ctx, unsigned char *out, - unsigned int olen, unsigned char *in, - unsigned int ilen) +static ossl_ssize_t zlib_stateful_expand_block(COMP_CTX *ctx, unsigned char *out, + size_t olen, unsigned char *in, + size_t ilen) { int err = Z_OK; struct zlib_state *state = ctx->data; @@ -201,7 +194,9 @@ static int zlib_stateful_expand_block(COMP_CTX *ctx, unsigned char *out, err = inflate(&state->istream, Z_SYNC_FLUSH); if (err != Z_OK) return -1; - return olen - state->istream.avail_out; + if (state->istream.avail_out > olen) + return -1; + return (ossl_ssize_t)(olen - state->istream.avail_out); } static CRYPTO_ONCE zlib_once = CRYPTO_ONCE_STATIC_INIT; @@ -245,7 +240,7 @@ DEFINE_RUN_ONCE_STATIC(ossl_comp_zlib_init) COMP_METHOD *COMP_zlib(void) { - COMP_METHOD *meth = &zlib_method_nozlib; + COMP_METHOD *meth = NULL; #ifndef OPENSSL_NO_ZLIB if (RUN_ONCE(&zlib_once, ossl_comp_zlib_init)) |