summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/stack
diff options
context:
space:
mode:
authorbeck <>2023-04-24 15:35:22 +0000
committerbeck <>2023-04-24 15:35:22 +0000
commitdab4782765bc32e8d3dca61bf2c34c641fa49e9d (patch)
treeb277ee580caad60cc9b349311bac1e8ffb5a7e1d /src/lib/libcrypto/stack
parenta0854b226644afa70c3d41b9b81da7fb0d797a2a (diff)
downloadopenbsd-dab4782765bc32e8d3dca61bf2c34c641fa49e9d.tar.gz
openbsd-dab4782765bc32e8d3dca61bf2c34c641fa49e9d.tar.bz2
openbsd-dab4782765bc32e8d3dca61bf2c34c641fa49e9d.zip
Fix sk_is_sorted to tread 0 and 1 element lists as sorted.
from boringssl ok tb@ jsing@
Diffstat (limited to 'src/lib/libcrypto/stack')
-rw-r--r--src/lib/libcrypto/stack/stack.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/lib/libcrypto/stack/stack.c b/src/lib/libcrypto/stack/stack.c
index bc5b2f6e83..65bd3217d1 100644
--- a/src/lib/libcrypto/stack/stack.c
+++ b/src/lib/libcrypto/stack/stack.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: stack.c,v 1.22 2023/02/16 08:38:17 tb Exp $ */ 1/* $OpenBSD: stack.c,v 1.23 2023/04/24 15:35:22 beck 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 *
@@ -356,8 +356,17 @@ LCRYPTO_ALIAS(sk_sort);
356int 356int
357sk_is_sorted(const _STACK *st) 357sk_is_sorted(const _STACK *st)
358{ 358{
359 if (!st) 359 if (st == NULL)
360 return 1;
361
362 if (st->sorted)
360 return 1; 363 return 1;
361 return st->sorted; 364
365 /* If there is no comparison function we cannot sort. */
366 if (st->comp == NULL)
367 return 0;
368
369 /* Lists with zero or one elements are always sorted. */
370 return st->num <= 1;
362} 371}
363LCRYPTO_ALIAS(sk_is_sorted); 372LCRYPTO_ALIAS(sk_is_sorted);