Skip to content

Commit 9749f04

Browse files
author
tb
committed
bio chain test: various minor readability tweaks
Align initialization in walk_backward() with walk_forward(), fix grammar in a comment and move initialization of oldhead_len in a place consistent with the other length initializations in that function
1 parent 57e60c8 commit 9749f04

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/regress/lib/libcrypto/bio/bio_chain.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: bio_chain.c,v 1.7 2022/12/08 18:34:00 tb Exp $ */
1+
/* $OpenBSD: bio_chain.c,v 1.8 2022/12/09 07:46:54 tb Exp $ */
22
/*
33
* Copyright (c) 2022 Theo Buehler <tb@openbsd.org>
44
*
@@ -243,8 +243,9 @@ walk_backward(BIO *start, BIO *end, size_t expected_len, size_t i, size_t j,
243243
if (start == NULL || end == NULL)
244244
goto done;
245245

246-
len = 0;
247246
prev = end;
247+
len = 0;
248+
248249
do {
249250
next = prev;
250251
prev = BIO_prev(prev);
@@ -277,6 +278,7 @@ check_chain(BIO *start, BIO *end, size_t expected_len, size_t i, size_t j,
277278
{
278279
if (!walk_forward(start, end, expected_len, i, j, fn, description))
279280
return 0;
281+
280282
if (!walk_backward(start, end, expected_len, i, j, fn, description))
281283
return 0;
282284

@@ -318,9 +320,9 @@ check_chain(BIO *start, BIO *end, size_t expected_len, size_t i, size_t j,
318320
* After creating a new link, the new chain has length i + 1 + nitems(B) - j,
319321
* oldtail has length nitems(A) - i - 1 and oldhead has length j.
320322
*
321-
* Prior to bio_lib.c r1.40, BIO_set_next(A[i], B[j]) results in both A[i] and
322-
* B[j - 1] pointing at B[j] while B[j] points back at A[i]. The result is
323-
* again double frees.
323+
* Prior to bio_lib.c r1.40, BIO_set_next(A[i], B[j]) would result in both A[i]
324+
* and B[j - 1] pointing at B[j] while B[j] would point back at A[i]. Calling
325+
* BIO_free_all(A[0]) and BIO_free_all(B[0]) results in a double free of B[j].
324326
*
325327
* XXX: Should check that the callback is called on BIO_push() as expected.
326328
*/
@@ -354,9 +356,9 @@ link_chains_at(size_t i, size_t j, int use_bio_push)
354356
new_start = A[0];
355357
new_end = B[nitems(B) - 1];
356358

357-
oldhead_len = j;
358359
oldhead_start = B[0];
359360
oldhead_end = BIO_prev(B[j]);
361+
oldhead_len = j;
360362

361363
/* If we push B[0] or set next to B[0], the oldhead chain is empty. */
362364
if (j == 0) {

0 commit comments

Comments
 (0)