Fix -DZLIB build for opaque COMP types
Reviewed-by: Richard Levitte <levitte@openssl.org>
This commit is contained in:
parent
7768e116dc
commit
121ee399c9
@ -109,9 +109,7 @@ static COMP_METHOD zlib_stateful_method = {
|
|||||||
zlib_stateful_init,
|
zlib_stateful_init,
|
||||||
zlib_stateful_finish,
|
zlib_stateful_finish,
|
||||||
zlib_stateful_compress_block,
|
zlib_stateful_compress_block,
|
||||||
zlib_stateful_expand_block,
|
zlib_stateful_expand_block
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -167,8 +165,6 @@ struct zlib_state {
|
|||||||
z_stream ostream;
|
z_stream ostream;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int zlib_stateful_ex_idx = -1;
|
|
||||||
|
|
||||||
static int zlib_stateful_init(COMP_CTX *ctx)
|
static int zlib_stateful_init(COMP_CTX *ctx)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
@ -200,8 +196,7 @@ static int zlib_stateful_init(COMP_CTX *ctx)
|
|||||||
if (err != Z_OK)
|
if (err != Z_OK)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
CRYPTO_new_ex_data(CRYPTO_EX_INDEX_COMP, ctx, &ctx->ex_data);
|
ctx->data = state;
|
||||||
CRYPTO_set_ex_data(&ctx->ex_data, zlib_stateful_ex_idx, state);
|
|
||||||
return 1;
|
return 1;
|
||||||
err:
|
err:
|
||||||
OPENSSL_free(state);
|
OPENSSL_free(state);
|
||||||
@ -210,13 +205,10 @@ static int zlib_stateful_init(COMP_CTX *ctx)
|
|||||||
|
|
||||||
static void zlib_stateful_finish(COMP_CTX *ctx)
|
static void zlib_stateful_finish(COMP_CTX *ctx)
|
||||||
{
|
{
|
||||||
struct zlib_state *state =
|
struct zlib_state *state = ctx->data;
|
||||||
(struct zlib_state *)CRYPTO_get_ex_data(&ctx->ex_data,
|
|
||||||
zlib_stateful_ex_idx);
|
|
||||||
inflateEnd(&state->istream);
|
inflateEnd(&state->istream);
|
||||||
deflateEnd(&state->ostream);
|
deflateEnd(&state->ostream);
|
||||||
OPENSSL_free(state);
|
OPENSSL_free(state);
|
||||||
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_COMP, ctx, &ctx->ex_data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int zlib_stateful_compress_block(COMP_CTX *ctx, unsigned char *out,
|
static int zlib_stateful_compress_block(COMP_CTX *ctx, unsigned char *out,
|
||||||
@ -224,9 +216,7 @@ static int zlib_stateful_compress_block(COMP_CTX *ctx, unsigned char *out,
|
|||||||
unsigned int ilen)
|
unsigned int ilen)
|
||||||
{
|
{
|
||||||
int err = Z_OK;
|
int err = Z_OK;
|
||||||
struct zlib_state *state =
|
struct zlib_state *state = ctx->data;
|
||||||
(struct zlib_state *)CRYPTO_get_ex_data(&ctx->ex_data,
|
|
||||||
zlib_stateful_ex_idx);
|
|
||||||
|
|
||||||
if (state == NULL)
|
if (state == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
@ -252,10 +242,7 @@ static int zlib_stateful_expand_block(COMP_CTX *ctx, unsigned char *out,
|
|||||||
unsigned int ilen)
|
unsigned int ilen)
|
||||||
{
|
{
|
||||||
int err = Z_OK;
|
int err = Z_OK;
|
||||||
|
struct zlib_state *state = ctx->data;
|
||||||
struct zlib_state *state =
|
|
||||||
(struct zlib_state *)CRYPTO_get_ex_data(&ctx->ex_data,
|
|
||||||
zlib_stateful_ex_idx);
|
|
||||||
|
|
||||||
if (state == NULL)
|
if (state == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
@ -307,33 +294,13 @@ COMP_METHOD *COMP_zlib(void)
|
|||||||
&& p_inflateInit_ && p_deflateEnd
|
&& p_inflateInit_ && p_deflateEnd
|
||||||
&& p_deflate && p_deflateInit_ && p_zError)
|
&& p_deflate && p_deflateInit_ && p_zError)
|
||||||
zlib_loaded++;
|
zlib_loaded++;
|
||||||
|
if (zlib_loaded)
|
||||||
|
meth = &zlib_stateful_method;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef ZLIB_SHARED
|
#if defined(ZLIB)
|
||||||
if (zlib_loaded)
|
meth = &zlib_stateful_method;
|
||||||
#endif
|
|
||||||
#if defined(ZLIB) || defined(ZLIB_SHARED)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* init zlib_stateful_ex_idx here so that in a multi-process
|
|
||||||
* application it's enough to intialize openssl before forking (idx
|
|
||||||
* will be inherited in all the children)
|
|
||||||
*/
|
|
||||||
if (zlib_stateful_ex_idx == -1) {
|
|
||||||
CRYPTO_w_lock(CRYPTO_LOCK_COMP);
|
|
||||||
if (zlib_stateful_ex_idx == -1)
|
|
||||||
zlib_stateful_ex_idx =
|
|
||||||
CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_COMP,
|
|
||||||
0, NULL, NULL, NULL, NULL);
|
|
||||||
CRYPTO_w_unlock(CRYPTO_LOCK_COMP);
|
|
||||||
if (zlib_stateful_ex_idx == -1)
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
meth = &zlib_stateful_method;
|
|
||||||
}
|
|
||||||
err:
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return (meth);
|
return (meth);
|
||||||
|
@ -71,4 +71,5 @@ struct comp_ctx_st {
|
|||||||
unsigned long compress_out;
|
unsigned long compress_out;
|
||||||
unsigned long expand_in;
|
unsigned long expand_in;
|
||||||
unsigned long expand_out;
|
unsigned long expand_out;
|
||||||
|
void* data;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user