lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20191007192632.29535-1-thomas@m3y3r.de>
Date:   Mon,  7 Oct 2019 21:26:32 +0200
From:   Thomas Meyer <thomas@...3r.de>
To:     linux-kernel@...r.kernel.org
Cc:     linux@...musvillemoes.dk, Thomas Meyer <thomas@...3r.de>
Subject: [PATCH] kernel/groups.c: use bsearch library function

commit b7b2562f7252 ("kernel/groups.c: use sort library function")
introduced the sort library function.
also use the bsearch library function instead of open-coding the binary
search.

Signed-off-by: Thomas Meyer <thomas@...3r.de>
---
 kernel/groups.c | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/kernel/groups.c b/kernel/groups.c
index daae2f2dc6d4f..69561a9cb4d39 100644
--- a/kernel/groups.c
+++ b/kernel/groups.c
@@ -2,6 +2,7 @@
 /*
  * Supplementary group IDs
  */
+#include <linux/bsearch.h>
 #include <linux/cred.h>
 #include <linux/export.h>
 #include <linux/slab.h>
@@ -96,22 +97,12 @@ EXPORT_SYMBOL(groups_sort);
 /* a simple bsearch */
 int groups_search(const struct group_info *group_info, kgid_t grp)
 {
-	unsigned int left, right;
-
 	if (!group_info)
 		return 0;
 
-	left = 0;
-	right = group_info->ngroups;
-	while (left < right) {
-		unsigned int mid = (left+right)/2;
-		if (gid_gt(grp, group_info->gid[mid]))
-			left = mid + 1;
-		else if (gid_lt(grp, group_info->gid[mid]))
-			right = mid;
-		else
-			return 1;
-	}
+	if (bsearch(&grp, group_info->gid, group_info->ngroups,
+		    sizeof(*group_info->gid), gid_cmp))
+		return 1;
 	return 0;
 }
 
-- 
2.21.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ