fortify-headers

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

commit e6837a7874a40d5fe78dd3edd5f6dab68d87a962
parent 03886aa26ca739f8458a54c663602ad09dc0a5b1
Author: sin <sin@2f30.org>
Date:   Fri, 30 Jan 2015 16:17:01 +0000

Add FD_{CLR,SET} checks

Diffstat:
Ainclude/sys/select.h | 38++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+), 0 deletions(-)

diff --git a/include/sys/select.h b/include/sys/select.h @@ -0,0 +1,38 @@ +/* See LICENSE file for copyright and license details. */ +#ifndef FORTIFY_SYS_SELECT_H_ +#define FORTIFY_SYS_SELECT_H_ + +#include_next <sys/select.h> + +#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 + +static inline __attribute__ ((always_inline)) +int +__fortify_FD_CLR(int fd, fd_set *set) +{ + size_t n = __builtin_object_size(set, 0); + + if (fd < 0 || fd >= FD_SETSIZE || n < sizeof(fd_set)) + __builtin_trap(); + return FD_CLR(fd, set); +} + +static inline __attribute__ ((always_inline)) +int +__fortify_FD_SET(int fd, fd_set *set) +{ + size_t n = __builtin_object_size(set, 0); + + if (fd < 0 || fd >= FD_SETSIZE || n < sizeof(fd_set)) + __builtin_trap(); + return FD_SET(fd, set); +} + +#undef FD_CLR +#define FD_CLR(fd, set) __fortify_FD_CLR(fd, set) +#undef FD_SET +#define FD_SET(fd, set) __fortify_FD_SET(fd, set) + +#endif + +#endif