fortify-headers

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

commit 4a18008ce14b77be67ed0b5f0e27b4db3db5beb8
parent 3d159480208ecad607490f513784a3a68f817f42
Author: sin <sin@2f30.org>
Date:   Thu, 29 Jan 2015 12:14:06 +0000

Add bzero() checks

Diffstat:
Minclude/strings.h | 14++++++++++++++
1 file changed, 14 insertions(+), 0 deletions(-)

diff --git a/include/strings.h b/include/strings.h @@ -21,8 +21,22 @@ __fortify_bcopy(const void *__restrict src, void *__restrict dest, size_t n) return bcopy(src, dest, n); } +static inline __attribute__ ((always_inline)) +void +__fortify_bzero(void *src, size_t n) +{ + size_t bos = __builtin_object_size(src, 0); + + if (n > bos) + __builtin_trap(); + return bzero(src, n); +} + #undef bcopy #define bcopy(src, dest, n) __fortify_bcopy(src, dest, n) +#undef bzero +#define bzero(src, n) __fortify_bzero(src, n) + #endif #endif