From: beck Date: Mon, 24 Apr 2023 15:35:22 +0000 (+0000) Subject: Fix sk_is_sorted to tread 0 and 1 element lists as sorted. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=bde0d557ea6456f3e667fe44e53439162f51db33;p=openbsd Fix sk_is_sorted to tread 0 and 1 element lists as sorted. from boringssl ok tb@ jsing@ --- 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);