Skip to content

Commit 90e277b

Browse files
author
tb
committed
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.
1 parent bfffc10 commit 90e277b

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/lib/libcrypto/bio/bio_lib.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: bio_lib.c,v 1.38 2022/11/30 01:56:18 jsing Exp $ */
1+
/* $OpenBSD: bio_lib.c,v 1.39 2022/12/02 19:44:04 tb Exp $ */
22
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
33
* All rights reserved.
44
*
@@ -161,6 +161,7 @@ BIO_set(BIO *bio, const BIO_METHOD *method)
161161
bio->retry_reason = 0;
162162
bio->num = 0;
163163
bio->ptr = NULL;
164+
bio->prev_bio = NULL;
164165
bio->next_bio = NULL;
165166
bio->references = 1;
166167
bio->num_read = 0L;
@@ -636,6 +637,8 @@ BIO_push(BIO *b, BIO *bio)
636637
while (lb->next_bio != NULL)
637638
lb = lb->next_bio;
638639
lb->next_bio = bio;
640+
if (bio != NULL)
641+
bio->prev_bio = lb;
639642
/* called to do internal processing */
640643
BIO_ctrl(b, BIO_CTRL_PUSH, 0, lb);
641644
return (b);
@@ -653,7 +656,13 @@ BIO_pop(BIO *b)
653656

654657
BIO_ctrl(b, BIO_CTRL_POP, 0, b);
655658

659+
if (b->prev_bio != NULL)
660+
b->prev_bio->next_bio = b->next_bio;
661+
if (b->next_bio != NULL)
662+
b->next_bio->prev_bio = b->prev_bio;
663+
656664
b->next_bio = NULL;
665+
b->prev_bio = NULL;
657666
return (ret);
658667
}
659668

src/lib/libcrypto/bio/bio_local.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: bio_local.h,v 1.4 2022/11/28 07:50:00 tb Exp $ */
1+
/* $OpenBSD: bio_local.h,v 1.5 2022/12/02 19:44:04 tb Exp $ */
22
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
33
* All rights reserved.
44
*
@@ -87,6 +87,7 @@ struct bio_st {
8787
int num;
8888
void *ptr;
8989
struct bio_st *next_bio; /* used by filter BIOs */
90+
struct bio_st *prev_bio; /* used by filter BIOs */
9091
int references;
9192
unsigned long num_read;
9293
unsigned long num_write;

0 commit comments

Comments
 (0)