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. --- tests/Makefile | 2 ++ tests/test_select_dynamic.c | 16 ++++++++++++++++ tests/test_select_static.c | 16 ++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 tests/test_select_dynamic.c create mode 100644 tests/test_select_static.c (limited to 'tests') diff --git a/tests/Makefile b/tests/Makefile index a93e0e9..4889dc7 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -78,6 +78,8 @@ RUNTIME_TARGETS= \ test_recv_static \ test_recvfrom_dynamic \ test_recvfrom_static \ + test_select_dynamic \ + test_select_static \ test_send_dynamic \ test_send_static \ test_sendto_dynamic \ diff --git a/tests/test_select_dynamic.c b/tests/test_select_dynamic.c new file mode 100644 index 0000000..e67baf3 --- /dev/null +++ b/tests/test_select_dynamic.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include + +int main(int argc, char** argv) { +#if !defined(__clang__) + fd_set rfds; + + CHK_FAIL_START + select(FD_SETSIZE + argc, &rfds, NULL, NULL, NULL); + CHK_FAIL_END + + puts((const char*)&rfds); +#endif + return ret; +} diff --git a/tests/test_select_static.c b/tests/test_select_static.c new file mode 100644 index 0000000..c2abf7f --- /dev/null +++ b/tests/test_select_static.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include + +int main(int argc, char** argv) { +#if !defined(__clang__) + fd_set rfds; + + CHK_FAIL_START + select(1337, &rfds, NULL, NULL, NULL); + CHK_FAIL_END + + puts((const char*)&rfds); +#endif + return ret; +} -- cgit v1.3