fortify-headers

standalone fortify-source implementation
git clone git://git.2f30.org/fortify-headers
Log | Files | Refs | README | LICENSE

commit cfdcaf72ca60db28ad8a7240a5a09e99151cab24
parent 8439dc0d1b986e7652afd78c1462707f4bf90f8b
Author: jvoisin <julien.voisin@dustri.org>
Date:   Wed,  1 Nov 2023 21:55:04 +0100

Add support for FD_ISSET

Diffstat:
Minclude/sys/select.h | 11+++++++++++
Mtests/Makefile | 2++
Atests/test_FD_ISSET_SETSIZE.c | 14++++++++++++++
Atests/test_FD_ISSET_negative.c | 14++++++++++++++
4 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/include/sys/select.h b/include/sys/select.h @@ -49,12 +49,23 @@ _STI void __fortify_FD_SET(int __f, fd_set * _FORTIFY_POS0 __s) FD_SET(__f, __s); } +_STI int __fortify_FD_ISSET(int __f, fd_set * _FORTIFY_POS0 __s) +{ + size_t __b = __bos(__s, 0); + + if (__f < 0 || __f >= FD_SETSIZE || __b < sizeof(fd_set)) + __builtin_trap(); + return FD_ISSET(__f, __s); +} + #undef _STI #undef FD_CLR #define FD_CLR(fd, set) __fortify_FD_CLR(fd, set) #undef FD_SET #define FD_SET(fd, set) __fortify_FD_SET(fd, set) +#undef FD_ISSET +#define FD_ISSET(fd, set) __fortify_FD_ISSET(fd, set) #ifdef __cplusplus } diff --git a/tests/Makefile b/tests/Makefile @@ -10,6 +10,8 @@ RUNTIME_TARGETS= \ test_FD_CLR_negative \ test_FD_SET_SETSIZE \ test_FD_SET_negative \ + test_FD_ISSET_SETSIZE \ + test_FD_ISSET_negative \ test_bcopy_dynamic_read \ test_bcopy_dynamic_write \ test_bcopy_static_read \ diff --git a/tests/test_FD_ISSET_SETSIZE.c b/tests/test_FD_ISSET_SETSIZE.c @@ -0,0 +1,14 @@ +#include "common.h" + +#include <sys/select.h> + +int main(int argc, char** argv) { + fd_set rfds; + + CHK_FAIL_START + FD_ISSET(FD_SETSIZE, &rfds); + CHK_FAIL_END + + puts((const char*)&rfds); + return ret; +} diff --git a/tests/test_FD_ISSET_negative.c b/tests/test_FD_ISSET_negative.c @@ -0,0 +1,14 @@ +#include "common.h" + +#include <sys/select.h> + +int main(int argc, char** argv) { + fd_set rfds; + + CHK_FAIL_START + FD_ISSET(-1, &rfds); + CHK_FAIL_END + + puts((const char*)&rfds); + return ret; +}