From dc10560eba147b1b6484153b424d8f715c055e2f Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Fri, 18 Nov 2016 18:18:37 +0100 Subject: Make it possible to peek at BIO data through BIO_f_buffer() This is needed for the upcoming "file" scheme STORE loader. Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/3542) --- crypto/bio/bf_buff.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'crypto/bio') diff --git a/crypto/bio/bf_buff.c b/crypto/bio/bf_buff.c index 7a73095488..255a4d476e 100644 --- a/crypto/bio/bf_buff.c +++ b/crypto/bio/bf_buff.c @@ -255,6 +255,11 @@ static long buffer_ctrl(BIO *b, int cmd, long num, void *ptr) return (0); ret = BIO_ctrl(b->next_bio, cmd, num, ptr); break; + case BIO_CTRL_EOF: + if (ctx->ibuf_len > 0) + return 0; + ret = BIO_ctrl(b->next_bio, cmd, num, ptr); + break; case BIO_CTRL_INFO: ret = (long)ctx->obuf_len; break; @@ -380,6 +385,17 @@ static long buffer_ctrl(BIO *b, int cmd, long num, void *ptr) !BIO_set_write_buffer_size(dbio, ctx->obuf_size)) ret = 0; break; + case BIO_CTRL_PEEK: + /* Ensure there's stuff in the input buffer */ + { + char fake_buf[1]; + (void)buffer_read(b, fake_buf, 0); + } + if (num > ctx->ibuf_len) + num = ctx->ibuf_len; + memcpy(ptr, &(ctx->ibuf[ctx->ibuf_off]), num); + ret = num; + break; default: if (b->next_bio == NULL) return (0); -- cgit v1.2.3