fortify-headers

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

commit 488c3c7183788de425a7854aa0008fe795241546
parent 66b34fbe593a3b2087d2276957b47a5bab567f18
Author: sin <sin@2f30.org>
Date:   Sun Mar  1 12:10:40 +0000

Add vsprintf() check

Diffstat:
include/stdio.h | 22++++++++++++++++++++++
1 file changed, 22 insertions(+), 0 deletions(-)
diff --git a/include/stdio.h b/include/stdio.h @@ -18,6 +18,26 @@ __fortify_fgets(char *s, int n, FILE *fp) static inline __attribute__ ((always_inline)) +__attribute__ ((__format__ (printf, 2, 0))) +__attribute__ ((__nonnull__ (2))) +int +__fortify_vsprintf(char *s, const char *fmt, __builtin_va_list ap) +{ + size_t bos = __builtin_object_size(s, 0); + int r; + + if (bos != -1) { + r = vsnprintf(s, bos, fmt, ap); + if (r == -1 || (size_t)r >= bos) + __builtin_trap(); + } else { + r = vsprintf(s, fmt, ap); + } + return r; +} + +static inline +__attribute__ ((always_inline)) __attribute__ ((__format__ (printf, 3, 0))) __attribute__ ((__nonnull__ (3))) int @@ -32,6 +52,8 @@ __fortify_vsnprintf(char *s, size_t n, const char *fmt, __builtin_va_list ap) #undef fgets #define fgets(s, n, fp) __fortify_fgets(s, n, fp) +#undef vsprintf +#define vsprintf(s, fmt, ap) __fortify_vsprintf(s, fmt, ap) #undef vsnprintf #define vsnprintf(s, n, fmt, ap) __fortify_vsnprintf(s, n, fmt, ap)