From 2ea31ca96f0e836b7477a52b3c15f313f69c1098 Mon Sep 17 00:00:00 2001 From: sin Date: Sat, 28 Feb 2015 12:10:41 +0000 Subject: Add poll() check Not sure if including stddef.h from poll.h is acceptable. --- include/poll.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 include/poll.h 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 @@ +#ifndef FORTIFY_POLL_H_ +#define FORTIFY_POLL_H_ + +#include_next +#include_next + +#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 + +static inline __attribute__ ((always_inline)) +int +__fortify_poll(struct pollfd *fds, nfds_t nfds, int timeout) +{ + size_t bos = __builtin_object_size(fds, 0); + + if (bos != -1 && nfds > bos / sizeof(struct pollfd)) + __builtin_trap(); + return poll(fds, nfds, timeout); +} + +#undef poll +#define poll(fds, nfds, timeout) __fortify_poll(fds, nfds, timeout) + +#endif + +#endif -- cgit v1.3