summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bio/bio_lib.c
diff options
context:
space:
mode:
authorschwarze <>2022-12-07 23:08:47 +0000
committerschwarze <>2022-12-07 23:08:47 +0000
commit2b85b069ff24153ddd491689b70f49f463f7ec09 (patch)
tree7178fce139a8fda53f64f545e4defa1639910a6e /src/lib/libcrypto/bio/bio_lib.c
parent73183671d4b543adc49a79ea1adaa69bcb91c859 (diff)
downloadopenbsd-2b85b069ff24153ddd491689b70f49f463f7ec09.tar.gz
openbsd-2b85b069ff24153ddd491689b70f49f463f7ec09.tar.bz2
openbsd-2b85b069ff24153ddd491689b70f49f463f7ec09.zip
Improve the implementation of BIO_push(3) such that it changes nothing
and reports failure if a call would result in a cycle. The algorithm used was originally suggested by jsing@. Feedback and OK tb@.
Diffstat (limited to 'src/lib/libcrypto/bio/bio_lib.c')
-rw-r--r--src/lib/libcrypto/bio/bio_lib.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/lib/libcrypto/bio/bio_lib.c b/src/lib/libcrypto/bio/bio_lib.c
index 4c3d7ed5f5..3eb0869ca9 100644
--- a/src/lib/libcrypto/bio/bio_lib.c
+++ b/src/lib/libcrypto/bio/bio_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bio_lib.c,v 1.41 2022/12/06 17:59:21 schwarze Exp $ */ 1/* $OpenBSD: bio_lib.c,v 1.42 2022/12/07 23:08:47 schwarze Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -637,6 +637,12 @@ BIO_push(BIO *b, BIO *bio)
637 637
638 if (b == NULL) 638 if (b == NULL)
639 return (bio); 639 return (bio);
640
641 /* If this would create a cycle, change nothing and fail. */
642 for (lb = bio; lb != NULL; lb = lb->next_bio)
643 if (lb == b)
644 return NULL;
645
640 lb = b; 646 lb = b;
641 while (lb->next_bio != NULL) 647 while (lb->next_bio != NULL)
642 lb = lb->next_bio; 648 lb = lb->next_bio;