summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/regress/lib/libcrypto/bio/bio_chain.c42
1 files changed, 15 insertions, 27 deletions
diff --git a/src/regress/lib/libcrypto/bio/bio_chain.c b/src/regress/lib/libcrypto/bio/bio_chain.c
index f5c46d710b..810395676f 100644
--- a/src/regress/lib/libcrypto/bio/bio_chain.c
+++ b/src/regress/lib/libcrypto/bio/bio_chain.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bio_chain.c,v 1.11 2022/12/09 17:23:05 tb Exp $ */ 1/* $OpenBSD: bio_chain.c,v 1.12 2022/12/10 10:42:13 tb Exp $ */
2/* 2/*
3 * Copyright (c) 2022 Theo Buehler <tb@openbsd.org> 3 * Copyright (c) 2022 Theo Buehler <tb@openbsd.org>
4 * 4 *
@@ -200,24 +200,15 @@ walk_forward(BIO *start, BIO *end, size_t expected_len, size_t i, size_t j,
200 size_t len; 200 size_t len;
201 int ret = 0; 201 int ret = 0;
202 202
203 if (start == NULL || end == NULL) { 203 prev = NULL;
204 if (expected_len != 0) {
205 fprintf(stderr, "%s case (%zu, %zu) %s: empty chain "
206 "with expected length %zu > 0\n",
207 fn, i, j, description, expected_len);
208 goto err;
209 }
210 goto done;
211 }
212
213 next = start; 204 next = start;
214 len = 0; 205 len = 0;
215 206
216 do { 207 while (next != NULL) {
217 prev = next; 208 prev = next;
218 next = BIO_next(prev); 209 next = BIO_next(prev);
219 len++; 210 len++;
220 } while (next != NULL); 211 }
221 212
222 if (prev != end) { 213 if (prev != end) {
223 fprintf(stderr, "%s case (%zu, %zu) %s has unexpected end\n", 214 fprintf(stderr, "%s case (%zu, %zu) %s has unexpected end\n",
@@ -232,7 +223,6 @@ walk_forward(BIO *start, BIO *end, size_t expected_len, size_t i, size_t j,
232 goto err; 223 goto err;
233 } 224 }
234 225
235 done:
236 ret = 1; 226 ret = 1;
237 227
238 err: 228 err:
@@ -247,24 +237,15 @@ walk_backward(BIO *start, BIO *end, size_t expected_len, size_t i, size_t j,
247 size_t len; 237 size_t len;
248 int ret = 0; 238 int ret = 0;
249 239
250 if (start == NULL || end == NULL) { 240 next = NULL;
251 if (expected_len != 0) {
252 fprintf(stderr, "%s case (%zu, %zu) %s: empty chain "
253 "with expected length %zu > 0\n",
254 fn, i, j, description, expected_len);
255 goto err;
256 }
257 goto done;
258 }
259
260 prev = end; 241 prev = end;
261 len = 0; 242 len = 0;
262 243
263 do { 244 while (prev != NULL) {
264 next = prev; 245 next = prev;
265 prev = BIO_prev(prev); 246 prev = BIO_prev(prev);
266 len++; 247 len++;
267 } while (prev != NULL); 248 }
268 249
269 if (next != start) { 250 if (next != start) {
270 fprintf(stderr, "%s case (%zu, %zu) %s has unexpected start\n", 251 fprintf(stderr, "%s case (%zu, %zu) %s has unexpected start\n",
@@ -279,7 +260,6 @@ walk_backward(BIO *start, BIO *end, size_t expected_len, size_t i, size_t j,
279 goto err; 260 goto err;
280 } 261 }
281 262
282 done:
283 ret = 1; 263 ret = 1;
284 264
285 err: 265 err:
@@ -369,6 +349,7 @@ link_chains_at(size_t i, size_t j, int use_bio_push)
369 349
370 new_start = A[0]; 350 new_start = A[0];
371 new_end = B[nitems(B) - 1]; 351 new_end = B[nitems(B) - 1];
352 /* new_len depends on use_bio_push. It is set a few lines down. */
372 353
373 oldhead_start = B[0]; 354 oldhead_start = B[0];
374 oldhead_end = BIO_prev(B[j]); 355 oldhead_end = BIO_prev(B[j]);
@@ -394,6 +375,13 @@ link_chains_at(size_t i, size_t j, int use_bio_push)
394 oldtail_start = BIO_next(A[i]); 375 oldtail_start = BIO_next(A[i]);
395 oldtail_end = A[nitems(A) - 1]; 376 oldtail_end = A[nitems(A) - 1];
396 oldtail_len = nitems(A) - i - 1; 377 oldtail_len = nitems(A) - i - 1;
378
379 /* If we set next on end of A[], the oldtail chain is empty. */
380 if (i == nitems(A) - 1) {
381 oldtail_start = NULL;
382 oldtail_end = NULL;
383 oldtail_len = 0;
384 }
397 } 385 }
398 386
399 /* The two chains A[] and B[] are split into three disjoint pieces. */ 387 /* The two chains A[] and B[] are split into three disjoint pieces. */