diff options
-rw-r--r-- | lib/libcrypto/stack/stack.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/libcrypto/stack/stack.c b/lib/libcrypto/stack/stack.c index bc5b2f6e837..65bd3217d12 100644 --- a/lib/libcrypto/stack/stack.c +++ b/lib/libcrypto/stack/stack.c @@ -1,4 +1,4 @@ -/* $OpenBSD: stack.c,v 1.22 2023/02/16 08:38:17 tb Exp $ */ +/* $OpenBSD: stack.c,v 1.23 2023/04/24 15:35:22 beck Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -356,8 +356,17 @@ LCRYPTO_ALIAS(sk_sort); int sk_is_sorted(const _STACK *st) { - if (!st) + if (st == NULL) + return 1; + + if (st->sorted) return 1; - return st->sorted; + + /* If there is no comparison function we cannot sort. */ + if (st->comp == NULL) + return 0; + + /* Lists with zero or one elements are always sorted. */ + return st->num <= 1; } LCRYPTO_ALIAS(sk_is_sorted); |