BIO_CTRL_RESET zeroed compress.bufsize and did not reinitialize the ZSTD
streams or buffer positions. After a reset, the next write could try to use
a 0 byte buffer and stall or behave unpredictably.
Signed-off-by: Joshua Rogers <MegaManSec@users.noreply.github.com>
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/28844)
switch (cmd) {
case BIO_CTRL_RESET:
+ /* reset decompressor */
+ ctx->decompress.inbuf.size = 0;
+ ctx->decompress.inbuf.pos = 0;
+ if (ctx->decompress.state != NULL)
+ ZSTD_initDStream(ctx->decompress.state);
+
+ /* reset compressor */
ctx->compress.write_pos = 0;
- ctx->compress.bufsize = 0;
+ ctx->compress.outbuf.pos = 0;
+ if (ctx->compress.state != NULL)
+ ZSTD_initCStream(ctx->compress.state, ZSTD_CLEVEL_DEFAULT);
+
+ /* keep existing bufsize, do not set it to 0 */
ret = 1;
break;