diff options
| author | sin | 2015-02-28 12:10:41 +0000 |
|---|---|---|
| committer | sin | 2015-02-28 12:10:41 +0000 |
| commit | 2ea31ca96f0e836b7477a52b3c15f313f69c1098 (patch) | |
| tree | b4dcd152b4e983bff93474a79f45a6ee12d1c28a /include | |
| parent | 195fffa420525a53ecd72c6d49c8660630e97359 (diff) | |
Add poll() check
Not sure if including stddef.h from poll.h is acceptable.
Diffstat (limited to 'include')
| -rw-r--r-- | include/poll.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/include/poll.h b/include/poll.h new file mode 100644 index 0000000..54fc4ab --- /dev/null +++ b/include/poll.h | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | #ifndef FORTIFY_POLL_H_ | ||
| 2 | #define FORTIFY_POLL_H_ | ||
| 3 | |||
| 4 | #include_next <stddef.h> | ||
| 5 | #include_next <poll.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_poll(struct pollfd *fds, nfds_t nfds, int timeout) | ||
| 12 | { | ||
| 13 | size_t bos = __builtin_object_size(fds, 0); | ||
| 14 | |||
| 15 | if (bos != -1 && nfds > bos / sizeof(struct pollfd)) | ||
| 16 | __builtin_trap(); | ||
| 17 | return poll(fds, nfds, timeout); | ||
| 18 | } | ||
| 19 | |||
| 20 | #undef poll | ||
| 21 | #define poll(fds, nfds, timeout) __fortify_poll(fds, nfds, timeout) | ||
| 22 | |||
| 23 | #endif | ||
| 24 | |||
| 25 | #endif | ||
