diff options
author | Bob Beck <beck@cvs.openbsd.org> | 2023-04-24 15:35:23 +0000 |
---|---|---|
committer | Bob Beck <beck@cvs.openbsd.org> | 2023-04-24 15:35:23 +0000 |
commit | f876a6f6bd10686ce72df5469816d60b83ff58ed (patch) | |
tree | 97cf4a17073fadc8ceeffc51e8ce2b858c106bda /lib/libcrypto/stack | |
parent | 0b81cfd83d8a0a1ccaaef33e1926b31106838f4e (diff) |
Fix sk_is_sorted to tread 0 and 1 element lists as sorted.
from boringssl
ok tb@ jsing@
Diffstat (limited to 'lib/libcrypto/stack')
-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); |