Fix the zlib config option

The zlib config option was broken by the BIO opacity changes.

Reviewed-by: Rich Salz <rsalz@openssl.org>
This commit is contained in:
Matt Caswell 2016-03-29 23:20:32 +01:00
parent 6be630b9c5
commit 222e620baf

View file

@ -58,7 +58,8 @@
#include <openssl/objects.h> #include <openssl/objects.h>
#include <openssl/comp.h> #include <openssl/comp.h>
#include <openssl/err.h> #include <openssl/err.h>
#include <internal/cryptlib_int.h> #include "internal/cryptlib_int.h"
#include "internal/bio.h"
#include "comp_lcl.h" #include "comp_lcl.h"
COMP_METHOD *COMP_zlib(void); COMP_METHOD *COMP_zlib(void);
@ -371,9 +372,9 @@ static int bio_zlib_new(BIO *bi)
ctx->zout.zalloc = Z_NULL; ctx->zout.zalloc = Z_NULL;
ctx->zout.zfree = Z_NULL; ctx->zout.zfree = Z_NULL;
ctx->comp_level = Z_DEFAULT_COMPRESSION; ctx->comp_level = Z_DEFAULT_COMPRESSION;
bi->init = 1; BIO_set_init(bi, 1);
bi->ptr = (char *)ctx; BIO_set_data(bi, ctx);
bi->flags = 0;
return 1; return 1;
} }
@ -382,7 +383,7 @@ static int bio_zlib_free(BIO *bi)
BIO_ZLIB_CTX *ctx; BIO_ZLIB_CTX *ctx;
if (!bi) if (!bi)
return 0; return 0;
ctx = (BIO_ZLIB_CTX *) bi->ptr; ctx = BIO_get_data(bi);
if (ctx->ibuf) { if (ctx->ibuf) {
/* Destroy decompress context */ /* Destroy decompress context */
inflateEnd(&ctx->zin); inflateEnd(&ctx->zin);
@ -394,9 +395,9 @@ static int bio_zlib_free(BIO *bi)
OPENSSL_free(ctx->obuf); OPENSSL_free(ctx->obuf);
} }
OPENSSL_free(ctx); OPENSSL_free(ctx);
bi->ptr = NULL; BIO_set_data(bi, NULL);
bi->init = 0; BIO_set_init(bi, 0);
bi->flags = 0;
return 1; return 1;
} }
@ -405,9 +406,11 @@ static int bio_zlib_read(BIO *b, char *out, int outl)
BIO_ZLIB_CTX *ctx; BIO_ZLIB_CTX *ctx;
int ret; int ret;
z_stream *zin; z_stream *zin;
BIO *next = BIO_next(b);
if (!out || !outl) if (!out || !outl)
return 0; return 0;
ctx = (BIO_ZLIB_CTX *) b->ptr; ctx = BIO_get_data(b);
zin = &ctx->zin; zin = &ctx->zin;
BIO_clear_retry_flags(b); BIO_clear_retry_flags(b);
if (!ctx->ibuf) { if (!ctx->ibuf) {
@ -442,7 +445,7 @@ static int bio_zlib_read(BIO *b, char *out, int outl)
* No data in input buffer try to read some in, if an error then * No data in input buffer try to read some in, if an error then
* return the total data read. * return the total data read.
*/ */
ret = BIO_read(b->next_bio, ctx->ibuf, ctx->ibufsize); ret = BIO_read(next, ctx->ibuf, ctx->ibufsize);
if (ret <= 0) { if (ret <= 0) {
/* Total data read */ /* Total data read */
int tot = outl - zin->avail_out; int tot = outl - zin->avail_out;
@ -461,9 +464,11 @@ static int bio_zlib_write(BIO *b, const char *in, int inl)
BIO_ZLIB_CTX *ctx; BIO_ZLIB_CTX *ctx;
int ret; int ret;
z_stream *zout; z_stream *zout;
BIO *next = BIO_next(b);
if (!in || !inl) if (!in || !inl)
return 0; return 0;
ctx = (BIO_ZLIB_CTX *) b->ptr; ctx = BIO_get_data(b);
if (ctx->odone) if (ctx->odone)
return 0; return 0;
zout = &ctx->zout; zout = &ctx->zout;
@ -487,7 +492,7 @@ static int bio_zlib_write(BIO *b, const char *in, int inl)
for (;;) { for (;;) {
/* If data in output buffer write it first */ /* If data in output buffer write it first */
while (ctx->ocount) { while (ctx->ocount) {
ret = BIO_write(b->next_bio, ctx->optr, ctx->ocount); ret = BIO_write(next, ctx->optr, ctx->ocount);
if (ret <= 0) { if (ret <= 0) {
/* Total data written */ /* Total data written */
int tot = inl - zout->avail_in; int tot = inl - zout->avail_in;
@ -526,7 +531,9 @@ static int bio_zlib_flush(BIO *b)
BIO_ZLIB_CTX *ctx; BIO_ZLIB_CTX *ctx;
int ret; int ret;
z_stream *zout; z_stream *zout;
ctx = (BIO_ZLIB_CTX *) b->ptr; BIO *next = BIO_next(b);
ctx = BIO_get_data(b);
/* If no data written or already flush show success */ /* If no data written or already flush show success */
if (!ctx->obuf || (ctx->odone && !ctx->ocount)) if (!ctx->obuf || (ctx->odone && !ctx->ocount))
return 1; return 1;
@ -538,7 +545,7 @@ static int bio_zlib_flush(BIO *b)
for (;;) { for (;;) {
/* If data in output buffer write it first */ /* If data in output buffer write it first */
while (ctx->ocount) { while (ctx->ocount) {
ret = BIO_write(b->next_bio, ctx->optr, ctx->ocount); ret = BIO_write(next, ctx->optr, ctx->ocount);
if (ret <= 0) { if (ret <= 0) {
BIO_copy_next_retry(b); BIO_copy_next_retry(b);
return ret; return ret;
@ -573,9 +580,11 @@ static long bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr)
BIO_ZLIB_CTX *ctx; BIO_ZLIB_CTX *ctx;
int ret, *ip; int ret, *ip;
int ibs, obs; int ibs, obs;
if (!b->next_bio) BIO *next = BIO_next(b);
if (next == NULL)
return 0; return 0;
ctx = (BIO_ZLIB_CTX *) b->ptr; ctx = BIO_get_data(b);
switch (cmd) { switch (cmd) {
case BIO_CTRL_RESET: case BIO_CTRL_RESET:
@ -587,7 +596,7 @@ static long bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr)
case BIO_CTRL_FLUSH: case BIO_CTRL_FLUSH:
ret = bio_zlib_flush(b); ret = bio_zlib_flush(b);
if (ret > 0) if (ret > 0)
ret = BIO_flush(b->next_bio); ret = BIO_flush(next);
break; break;
case BIO_C_SET_BUFF_SIZE: case BIO_C_SET_BUFF_SIZE:
@ -620,12 +629,12 @@ static long bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr)
case BIO_C_DO_STATE_MACHINE: case BIO_C_DO_STATE_MACHINE:
BIO_clear_retry_flags(b); BIO_clear_retry_flags(b);
ret = BIO_ctrl(b->next_bio, cmd, num, ptr); ret = BIO_ctrl(next, cmd, num, ptr);
BIO_copy_next_retry(b); BIO_copy_next_retry(b);
break; break;
default: default:
ret = BIO_ctrl(b->next_bio, cmd, num, ptr); ret = BIO_ctrl(next, cmd, num, ptr);
break; break;
} }
@ -635,9 +644,10 @@ static long bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr)
static long bio_zlib_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) static long bio_zlib_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
{ {
if (!b->next_bio) BIO *next = BIO_next(b);
if (next == NULL)
return 0; return 0;
return BIO_callback_ctrl(b->next_bio, cmd, fp); return BIO_callback_ctrl(next, cmd, fp);
} }
#endif #endif