summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/sys/select.h11
-rw-r--r--tests/Makefile2
-rw-r--r--tests/test_FD_ISSET_SETSIZE.c14
-rw-r--r--tests/test_FD_ISSET_negative.c14
4 files changed, 41 insertions, 0 deletions
diff --git a/include/sys/select.h b/include/sys/select.h
index df32003..29819be 100644
--- 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)
49 FD_SET(__f, __s); 49 FD_SET(__f, __s);
50} 50}
51 51
52_STI int __fortify_FD_ISSET(int __f, fd_set * _FORTIFY_POS0 __s)
53{
54 size_t __b = __bos(__s, 0);
55
56 if (__f < 0 || __f >= FD_SETSIZE || __b < sizeof(fd_set))
57 __builtin_trap();
58 return FD_ISSET(__f, __s);
59}
60
52#undef _STI 61#undef _STI
53 62
54#undef FD_CLR 63#undef FD_CLR
55#define FD_CLR(fd, set) __fortify_FD_CLR(fd, set) 64#define FD_CLR(fd, set) __fortify_FD_CLR(fd, set)
56#undef FD_SET 65#undef FD_SET
57#define FD_SET(fd, set) __fortify_FD_SET(fd, set) 66#define FD_SET(fd, set) __fortify_FD_SET(fd, set)
67#undef FD_ISSET
68#define FD_ISSET(fd, set) __fortify_FD_ISSET(fd, set)
58 69
59#ifdef __cplusplus 70#ifdef __cplusplus
60} 71}
diff --git a/tests/Makefile b/tests/Makefile
index 5f70069..a93e0e9 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -10,6 +10,8 @@ RUNTIME_TARGETS= \
10 test_FD_CLR_negative \ 10 test_FD_CLR_negative \
11 test_FD_SET_SETSIZE \ 11 test_FD_SET_SETSIZE \
12 test_FD_SET_negative \ 12 test_FD_SET_negative \
13 test_FD_ISSET_SETSIZE \
14 test_FD_ISSET_negative \
13 test_bcopy_dynamic_read \ 15 test_bcopy_dynamic_read \
14 test_bcopy_dynamic_write \ 16 test_bcopy_dynamic_write \
15 test_bcopy_static_read \ 17 test_bcopy_static_read \
diff --git a/tests/test_FD_ISSET_SETSIZE.c b/tests/test_FD_ISSET_SETSIZE.c
new file mode 100644
index 0000000..0362aaa
--- /dev/null
+++ b/tests/test_FD_ISSET_SETSIZE.c
@@ -0,0 +1,14 @@
1#include "common.h"
2
3#include <sys/select.h>
4
5int main(int argc, char** argv) {
6 fd_set rfds;
7
8 CHK_FAIL_START
9 FD_ISSET(FD_SETSIZE, &rfds);
10 CHK_FAIL_END
11
12 puts((const char*)&rfds);
13 return ret;
14}
diff --git a/tests/test_FD_ISSET_negative.c b/tests/test_FD_ISSET_negative.c
new file mode 100644
index 0000000..f0ff89a
--- /dev/null
+++ b/tests/test_FD_ISSET_negative.c
@@ -0,0 +1,14 @@
1#include "common.h"
2
3#include <sys/select.h>
4
5int main(int argc, char** argv) {
6 fd_set rfds;
7
8 CHK_FAIL_START
9 FD_ISSET(-1, &rfds);
10 CHK_FAIL_END
11
12 puts((const char*)&rfds);
13 return ret;
14}