diff options
| author | sin | 2015-01-30 16:17:01 +0000 |
|---|---|---|
| committer | sin | 2015-01-30 16:17:31 +0000 |
| commit | e6837a7874a40d5fe78dd3edd5f6dab68d87a962 (patch) | |
| tree | 13d6900696defc624e8b0a06391b4085439b6631 /include/sys/select.h | |
| parent | 03886aa26ca739f8458a54c663602ad09dc0a5b1 (diff) | |
Add FD_{CLR,SET} checks
Diffstat (limited to 'include/sys/select.h')
| -rw-r--r-- | include/sys/select.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/include/sys/select.h b/include/sys/select.h new file mode 100644 index 0000000..cb64af1 --- /dev/null +++ b/include/sys/select.h | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | /* See LICENSE file for copyright and license details. */ | ||
| 2 | #ifndef FORTIFY_SYS_SELECT_H_ | ||
| 3 | #define FORTIFY_SYS_SELECT_H_ | ||
| 4 | |||
| 5 | #include_next <sys/select.h> | ||
| 6 | |||
| 7 | #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 | ||
| 8 | |||
| 9 | static inline __attribute__ ((always_inline)) | ||
| 10 | int | ||
| 11 | __fortify_FD_CLR(int fd, fd_set *set) | ||
| 12 | { | ||
| 13 | size_t n = __builtin_object_size(set, 0); | ||
| 14 | |||
| 15 | if (fd < 0 || fd >= FD_SETSIZE || n < sizeof(fd_set)) | ||
| 16 | __builtin_trap(); | ||
| 17 | return FD_CLR(fd, set); | ||
| 18 | } | ||
| 19 | |||
| 20 | static inline __attribute__ ((always_inline)) | ||
| 21 | int | ||
| 22 | __fortify_FD_SET(int fd, fd_set *set) | ||
| 23 | { | ||
| 24 | size_t n = __builtin_object_size(set, 0); | ||
| 25 | |||
| 26 | if (fd < 0 || fd >= FD_SETSIZE || n < sizeof(fd_set)) | ||
| 27 | __builtin_trap(); | ||
| 28 | return FD_SET(fd, set); | ||
| 29 | } | ||
| 30 | |||
| 31 | #undef FD_CLR | ||
| 32 | #define FD_CLR(fd, set) __fortify_FD_CLR(fd, set) | ||
| 33 | #undef FD_SET | ||
| 34 | #define FD_SET(fd, set) __fortify_FD_SET(fd, set) | ||
| 35 | |||
| 36 | #endif | ||
| 37 | |||
| 38 | #endif | ||
