From 66c1519237e7fe37e27141f1d62a444f29ae65bf Mon Sep 17 00:00:00 2001 From: tb Date: Fri, 2 Dec 2022 19:44:04 +0000 Subject: [PATCH] Revert bio_prev removal As schwarze points out, you can pop any BIO in a chain, not just the first one (bonus points for a great name for this API). The internal doubly linked was used to fix up the BIO chain bio was part of when you BIO_pop() a bio that wasn't in the first position, which is explicitly allowed in our documentation and implied by OpenSSL's. --- lib/libcrypto/bio/bio_lib.c | 11 ++++++++++- lib/libcrypto/bio/bio_local.h | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/libcrypto/bio/bio_lib.c b/lib/libcrypto/bio/bio_lib.c index b33ebe167bf..c09ad8fe8e2 100644 --- a/lib/libcrypto/bio/bio_lib.c +++ b/lib/libcrypto/bio/bio_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bio_lib.c,v 1.38 2022/11/30 01:56:18 jsing Exp $ */ +/* $OpenBSD: bio_lib.c,v 1.39 2022/12/02 19:44:04 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -161,6 +161,7 @@ BIO_set(BIO *bio, const BIO_METHOD *method) bio->retry_reason = 0; bio->num = 0; bio->ptr = NULL; + bio->prev_bio = NULL; bio->next_bio = NULL; bio->references = 1; bio->num_read = 0L; @@ -636,6 +637,8 @@ BIO_push(BIO *b, BIO *bio) while (lb->next_bio != NULL) lb = lb->next_bio; lb->next_bio = bio; + if (bio != NULL) + bio->prev_bio = lb; /* called to do internal processing */ BIO_ctrl(b, BIO_CTRL_PUSH, 0, lb); return (b); @@ -653,7 +656,13 @@ BIO_pop(BIO *b) BIO_ctrl(b, BIO_CTRL_POP, 0, b); + if (b->prev_bio != NULL) + b->prev_bio->next_bio = b->next_bio; + if (b->next_bio != NULL) + b->next_bio->prev_bio = b->prev_bio; + b->next_bio = NULL; + b->prev_bio = NULL; return (ret); } diff --git a/lib/libcrypto/bio/bio_local.h b/lib/libcrypto/bio/bio_local.h index 94dd460bc5f..4eecf7e04a2 100644 --- a/lib/libcrypto/bio/bio_local.h +++ b/lib/libcrypto/bio/bio_local.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bio_local.h,v 1.4 2022/11/28 07:50:00 tb Exp $ */ +/* $OpenBSD: bio_local.h,v 1.5 2022/12/02 19:44:04 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -87,6 +87,7 @@ struct bio_st { int num; void *ptr; struct bio_st *next_bio; /* used by filter BIOs */ + struct bio_st *prev_bio; /* used by filter BIOs */ int references; unsigned long num_read; unsigned long num_write; -- 2.20.1