From: tb Date: Mon, 26 Feb 2024 15:00:30 +0000 (+0000) Subject: Neuter OBJ_bsearch{_,ex_}() X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=2eb0a250e80745cc11675f1fc5a21fbec68d9399;p=openbsd Neuter OBJ_bsearch{_,ex_}() Make these functions always fail. A copy of OBJ_bsearch_ex_() is kept in stack.c, where it is still used by internal_find() for sk_find{,_ex}(). sk_find_ex() will be removed in the upcoming bump, and then we can simplify or rewrite what's still needed. ok jsing --- diff --git a/lib/libcrypto/objects/obj_dat.c b/lib/libcrypto/objects/obj_dat.c index 170a6d58a38..1719cc73e20 100644 --- a/lib/libcrypto/objects/obj_dat.c +++ b/lib/libcrypto/objects/obj_dat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: obj_dat.c,v 1.85 2024/01/24 14:05:10 jsing Exp $ */ +/* $OpenBSD: obj_dat.c,v 1.86 2024/02/26 15:00:30 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -440,7 +440,8 @@ const void * OBJ_bsearch_(const void *key, const void *base, int num, int size, int (*cmp)(const void *, const void *)) { - return OBJ_bsearch_ex_(key, base, num, size, cmp, 0); + OBJerror(ERR_R_DISABLED); + return NULL; } LCRYPTO_ALIAS(OBJ_bsearch_); @@ -448,33 +449,8 @@ const void * OBJ_bsearch_ex_(const void *key, const void *base_, int num, int size, int (*cmp)(const void *, const void *), int flags) { - const char *base = base_; - int l, h, i = 0, c = 0; - const char *p = NULL; - - if (num == 0) - return (NULL); - l = 0; - h = num; - while (l < h) { - i = (l + h) / 2; - p = &(base[i * size]); - c = (*cmp)(key, p); - if (c < 0) - h = i; - else if (c > 0) - l = i + 1; - else - break; - } - if (c != 0 && !(flags & OBJ_BSEARCH_VALUE_ON_NOMATCH)) - p = NULL; - else if (c == 0 && (flags & OBJ_BSEARCH_FIRST_VALUE_ON_MATCH)) { - while (i > 0 && (*cmp)(key, &(base[(i - 1) * size])) == 0) - i--; - p = &(base[i * size]); - } - return (p); + OBJerror(ERR_R_DISABLED); + return NULL; } /* Convert an object name into an ASN1_OBJECT diff --git a/lib/libcrypto/stack/stack.c b/lib/libcrypto/stack/stack.c index f5c568dc5e7..818e7384470 100644 --- a/lib/libcrypto/stack/stack.c +++ b/lib/libcrypto/stack/stack.c @@ -1,4 +1,4 @@ -/* $OpenBSD: stack.c,v 1.24 2024/01/13 16:32:53 tb Exp $ */ +/* $OpenBSD: stack.c,v 1.25 2024/02/26 15:00:30 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -195,6 +195,39 @@ sk_delete(_STACK *st, int loc) } LCRYPTO_ALIAS(sk_delete); +static const void * +obj_bsearch_ex(const void *key, const void *base_, int num, int size, + int (*cmp)(const void *, const void *), int flags) +{ + const char *base = base_; + int l, h, i = 0, c = 0; + const char *p = NULL; + + if (num == 0) + return (NULL); + l = 0; + h = num; + while (l < h) { + i = (l + h) / 2; + p = &(base[i * size]); + c = (*cmp)(key, p); + if (c < 0) + h = i; + else if (c > 0) + l = i + 1; + else + break; + } + if (c != 0 && !(flags & OBJ_BSEARCH_VALUE_ON_NOMATCH)) + p = NULL; + else if (c == 0 && (flags & OBJ_BSEARCH_FIRST_VALUE_ON_MATCH)) { + while (i > 0 && (*cmp)(key, &(base[(i - 1) * size])) == 0) + i--; + p = &(base[i * size]); + } + return (p); +} + static int internal_find(_STACK *st, void *data, int ret_val_options) { @@ -213,7 +246,7 @@ internal_find(_STACK *st, void *data, int ret_val_options) sk_sort(st); if (data == NULL) return (-1); - r = OBJ_bsearch_ex_(&data, st->data, st->num, sizeof(void *), st->comp, + r = obj_bsearch_ex(&data, st->data, st->num, sizeof(void *), st->comp, ret_val_options); if (r == NULL) return (-1);