From fdaf78656fb6cc7caeb7b4e37068e8a8bf4dc639 Mon Sep 17 00:00:00 2001 From: Wilco Dijkstra Date: Fri, 10 Jun 2022 17:13:29 +0100 Subject: Add bounds check to __libc_ifunc_impl_list Add a proper bounds check to __libc_ifunc_impl_list. This makes MAX_IFUNC redundant and fixes several targets that will write outside the array. To avoid unnecessary large diffs, pass the maximum in the argument 'i' to IFUNC_IMPL_ADD - 'max' can be used in new ifunc definitions and existing ones can be updated if desired. Passes buildmanyglibc. Reviewed-by: Adhemerval Zanella --- sysdeps/i386/i686/multiarch/ifunc-impl-list.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'sysdeps/i386/i686') diff --git a/sysdeps/i386/i686/multiarch/ifunc-impl-list.c b/sysdeps/i386/i686/multiarch/ifunc-impl-list.c index c014f52bf9..9237b589f5 100644 --- a/sysdeps/i386/i686/multiarch/ifunc-impl-list.c +++ b/sysdeps/i386/i686/multiarch/ifunc-impl-list.c @@ -22,9 +22,6 @@ #include #include "init-arch.h" -/* Maximum number of IFUNC implementations. */ -#define MAX_IFUNC 4 - /* Fill ARRAY of MAX elements with IFUNC implementations for function NAME and return the number of valid entries. */ @@ -32,9 +29,7 @@ size_t __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array, size_t max) { - assert (max >= MAX_IFUNC); - - size_t i = 0; + size_t i = max; /* Support sysdeps/i386/i686/multiarch/memchr.S. */ IFUNC_IMPL (i, name, memchr, @@ -358,5 +353,5 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array, IFUNC_IMPL_ADD (array, i, strncmp, 1, __strncmp_ia32)) #endif - return i; + return 0; } -- cgit 1.4.1