Commit 9343a5d7c1 for openssl.org
commit 9343a5d7c1134dad5eda1c339267b6ca033a1ac0
Author: Nicky Mouha <nicky@mouha.be>
Date: Sun Nov 8 17:34:27 2026 -0500
crypto/bsearch.c: strengthen ossl_bsearch() input guard
This strengthens the ossl_bsearch() input guard to reject non-positive
values of num and size, and to limit num to INT_MAX/size.
Reviewed-by: Eugene Syromiatnikov <esyr@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
Merge-date: Tue Nov 10 05:38:11 2026
Merged-from: https://github.com/openssl/openssl/pull/33606
diff --git a/crypto/bsearch.c b/crypto/bsearch.c
index 201bc6e5f3..a5d76c839c 100644
--- a/crypto/bsearch.c
+++ b/crypto/bsearch.c
@@ -8,6 +8,7 @@
*/
#include <stddef.h>
+#include <limits.h>
#include "internal/cryptlib.h"
typedef int (*cmpthunk_fn)(const void *, const void *);
@@ -20,7 +21,7 @@ const void *ossl_bsearch(const void *key, const void *base, int num,
int l, h, i = 0, c = 0;
const char *p = NULL;
- if (num == 0)
+ if (num <= 0 || size <= 0 || num > INT_MAX / size)
return NULL;
l = 0;
h = num;