From 52ec4848225a0e9f577272015ced52c45923d4ba Mon Sep 17 00:00:00 2001 From: jvoisin Date: Thu, 16 Nov 2023 16:42:41 +0100 Subject: Add hardening for select() This is unlikely to be used, since fd_set is usually manipulated by macros, but it doesn't hurt to add a simple comparison. --- include/sys/select.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'include') diff --git a/include/sys/select.h b/include/sys/select.h index 29819be..f1cefee 100644 --- a/include/sys/select.h +++ b/include/sys/select.h @@ -67,6 +67,18 @@ _STI int __fortify_FD_ISSET(int __f, fd_set * _FORTIFY_POS0 __s) #undef FD_ISSET #define FD_ISSET(fd, set) __fortify_FD_ISSET(fd, set) +#ifndef __clang__ +#undef select +_FORTIFY_FN(select) int select(int nfds, fd_set* readfds, + fd_set* writefds, + fd_set* exceptfds, + struct timeval *timeout){ + if (nfds > FD_SETSIZE + 1) + __builtin_trap(); + return __orig_select(nfds, readfds, writefds, exceptfds, timeout); +} +#endif + #ifdef __cplusplus } #endif -- cgit v1.3