fortify-headers

standalone fortify-source implementation
git clone git://git.2f30.org/fortify-headers.git
Log | Files | Refs | README | LICENSE

commit 2ea31ca96f0e836b7477a52b3c15f313f69c1098
parent 195fffa420525a53ecd72c6d49c8660630e97359
Author: sin <sin@2f30.org>
Date:   Sat Feb 28 12:10:41 +0000

Add poll() check

Not sure if including stddef.h from poll.h is acceptable.

Diffstat:
include/poll.h | 25+++++++++++++++++++++++++
1 file changed, 25 insertions(+), 0 deletions(-)
diff --git a/include/poll.h b/include/poll.h @@ -0,0 +1,25 @@ +#ifndef FORTIFY_POLL_H_ +#define FORTIFY_POLL_H_ + +#include_next <stddef.h> +#include_next <poll.h> + +#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