summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2022-12-03 09:53:47 +0000
committertb <>2022-12-03 09:53:47 +0000
commit67d9ae3e900cc6190fd2ba523b6868ac8ff8868e (patch)
tree9f492c5fa4026a08bd17280d8bb902af82be1fe9 /src
parentebb8a55a47df51220646df1254717da269937f03 (diff)
downloadopenbsd-67d9ae3e900cc6190fd2ba523b6868ac8ff8868e.tar.gz
openbsd-67d9ae3e900cc6190fd2ba523b6868ac8ff8868e.tar.bz2
openbsd-67d9ae3e900cc6190fd2ba523b6868ac8ff8868e.zip
Test BIO_{push,pop}() along a linear chain
Diffstat (limited to 'src')
-rw-r--r--src/regress/lib/libcrypto/bio/biotest.c136
1 files changed, 135 insertions, 1 deletions
diff --git a/src/regress/lib/libcrypto/bio/biotest.c b/src/regress/lib/libcrypto/bio/biotest.c
index 531913461a..55daea78fc 100644
--- a/src/regress/lib/libcrypto/bio/biotest.c
+++ b/src/regress/lib/libcrypto/bio/biotest.c
@@ -1,6 +1,7 @@
1/* $OpenBSD: biotest.c,v 1.9 2022/09/05 21:06:31 tb Exp $ */ 1/* $OpenBSD: biotest.c,v 1.10 2022/12/03 09:53:47 tb Exp $ */
2/* 2/*
3 * Copyright (c) 2014, 2022 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2014, 2022 Joel Sing <jsing@openbsd.org>
4 * Copyright (c) 2022 Theo Buehler <tb@openbsd.org>
4 * 5 *
5 * Permission to use, copy, modify, and distribute this software for any 6 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above 7 * purpose with or without fee is hereby granted, provided that the above
@@ -28,6 +29,8 @@
28#include <openssl/buffer.h> 29#include <openssl/buffer.h>
29#include <openssl/err.h> 30#include <openssl/err.h>
30 31
32#include "bio_local.h"
33
31struct bio_get_host_ip_test { 34struct bio_get_host_ip_test {
32 char *input; 35 char *input;
33 uint32_t ip; 36 uint32_t ip;
@@ -465,6 +468,136 @@ do_bio_mem_tests(void)
465 return failed; 468 return failed;
466} 469}
467 470
471#define N_CHAIN_BIOS 5
472
473static BIO *
474BIO_prev(BIO *bio)
475{
476 if (bio == NULL)
477 return NULL;
478
479 return bio->prev_bio;
480}
481
482static int
483do_bio_chain_pop_test(void)
484{
485 BIO *bio[N_CHAIN_BIOS];
486 BIO *prev, *next;
487 size_t i, j;
488 int failed = 1;
489
490 for (i = 0; i < N_CHAIN_BIOS; i++) {
491 memset(bio, 0, sizeof(bio));
492 prev = NULL;
493
494 /* Create a linear chain of BIOs. */
495 for (j = 0; j < N_CHAIN_BIOS; j++) {
496 if ((bio[j] = BIO_new(BIO_s_null())) == NULL)
497 errx(1, "BIO_new");
498 if ((prev = BIO_push(prev, bio[j])) == NULL)
499 errx(1, "BIO_push");
500 }
501
502 /* Check that the doubly-linked list was set up as expected. */
503 if (BIO_prev(bio[0]) != NULL) {
504 fprintf(stderr,
505 "i = %zu: first BIO has predecessor\n", i);
506 goto err;
507 }
508 if (BIO_next(bio[N_CHAIN_BIOS - 1]) != NULL) {
509 fprintf(stderr, "i = %zu: last BIO has successor\n", i);
510 goto err;
511 }
512 for (j = 0; j < N_CHAIN_BIOS; j++) {
513 if (j > 0) {
514 if (BIO_prev(bio[j]) != bio[j - 1]) {
515 fprintf(stderr, "i = %zu: "
516 "BIO_prev(bio[%zu]) != bio[%zu]\n",
517 i, j, j - 1);
518 goto err;
519 }
520 }
521 if (j < N_CHAIN_BIOS - 1) {
522 if (BIO_next(bio[j]) != bio[j + 1]) {
523 fprintf(stderr, "i = %zu: "
524 "BIO_next(bio[%zu]) != bio[%zu]\n",
525 i, j, j + 1);
526 goto err;
527 }
528 }
529 }
530
531 /* Drop the ith bio from the chain. */
532 next = BIO_pop(bio[i]);
533
534 if (BIO_prev(bio[i]) != NULL || BIO_next(bio[i]) != NULL) {
535 fprintf(stderr,
536 "BIO_pop() didn't isolate bio[%zu]\n", i);
537 goto err;
538 }
539
540 if (i < N_CHAIN_BIOS - 1) {
541 if (next != bio[i + 1]) {
542 fprintf(stderr, "BIO_pop(bio[%zu]) did not "
543 "return bio[%zu]\n", i, i + 1);
544 goto err;
545 }
546 } else {
547 if (next != NULL) {
548 fprintf(stderr, "i = %zu: "
549 "BIO_pop(last) != NULL\n", i);
550 goto err;
551 }
552 }
553
554 /*
555 * Walk the remainder of the chain and see if the doubly linked
556 * list checks out.
557 */
558 if (i == 0) {
559 prev = bio[1];
560 j = 2;
561 } else {
562 prev = bio[0];
563 j = 1;
564 }
565
566 for (; j < N_CHAIN_BIOS; j++) {
567 if (j == i)
568 continue;
569 if (BIO_next(prev) != bio[j]) {
570 fprintf(stderr, "i = %zu, j = %zu: "
571 "BIO_next(prev) != bio[%zu]\n", i, j, j);
572 goto err;
573 }
574 if (BIO_prev(bio[j]) != prev) {
575 fprintf(stderr, "i = %zu, j = %zu: "
576 "BIO_prev(bio[%zu]) != prev\n", i, j, j);
577 goto err;
578 }
579 prev = bio[j];
580 }
581
582 if (BIO_next(prev) != NULL) {
583 fprintf(stderr, "i = %zu: BIO_next(prev) != NULL\n", i);
584 goto err;
585 }
586
587 for (j = 0; j < N_CHAIN_BIOS; j++)
588 BIO_free(bio[j]);
589 memset(bio, 0, sizeof(bio));
590 }
591
592 failed = 0;
593
594 err:
595 for (i = 0; i < N_CHAIN_BIOS; i++)
596 BIO_free(bio[i]);
597
598 return failed;
599}
600
468int 601int
469main(int argc, char **argv) 602main(int argc, char **argv)
470{ 603{
@@ -473,6 +606,7 @@ main(int argc, char **argv)
473 ret |= do_bio_get_host_ip_tests(); 606 ret |= do_bio_get_host_ip_tests();
474 ret |= do_bio_get_port_tests(); 607 ret |= do_bio_get_port_tests();
475 ret |= do_bio_mem_tests(); 608 ret |= do_bio_mem_tests();
609 ret |= do_bio_chain_pop_test();
476 610
477 return (ret); 611 return (ret);
478} 612}