diff options
| author | sin | 2015-01-28 16:54:48 +0000 |
|---|---|---|
| committer | sin | 2015-01-28 16:54:48 +0000 |
| commit | e2a76a9502415f2bbbc83d634afb4991da2ea960 (patch) | |
| tree | b9f035a7507eb50b636147458654518ff2f012a9 /include/stdio.h | |
| parent | 1872b6a7e567a6f983b3db973ccddd0f9b045b34 (diff) | |
Add vsnprintf() checks
Diffstat (limited to '')
| -rw-r--r-- | include/stdio.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/include/stdio.h b/include/stdio.h new file mode 100644 index 0000000..122e678 --- /dev/null +++ b/include/stdio.h | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | #ifndef FORTIFY_STDIO_H_ | ||
| 2 | #define FORTIFY_STDIO_H_ | ||
| 3 | |||
| 4 | #include_next <stdio.h> | ||
| 5 | |||
| 6 | #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 | ||
| 7 | |||
| 8 | static inline | ||
| 9 | __attribute__ ((always_inline)) | ||
| 10 | __attribute__ ((__format__ (printf, 3, 0))) | ||
| 11 | __attribute__ ((__nonnull__ (3))) | ||
| 12 | int __fortify_vsnprintf(char *__restrict s, size_t n, const char *__restrict fmt, __va_list ap) | ||
| 13 | { | ||
| 14 | size_t bos = __builtin_object_size(s, 0); | ||
| 15 | |||
| 16 | if (bos == (size_t)-1) | ||
| 17 | return vsnprintf(s, n, fmt, ap); | ||
| 18 | if (__builtin_constant_p(n) && n > bos) | ||
| 19 | __builtin_trap(); | ||
| 20 | return vsnprintf(s, n, fmt, ap); | ||
| 21 | } | ||
| 22 | |||
| 23 | #undef vsnprintf | ||
| 24 | #define vsnprintf(s, n, fmt, ap) __fortify_vsnprintf(s, n, fmt, ap) | ||
| 25 | |||
| 26 | #endif | ||
| 27 | |||
| 28 | #endif | ||
