diff options
| author | sin | 2015-01-29 00:12:59 +0000 |
|---|---|---|
| committer | sin | 2015-01-29 00:12:59 +0000 |
| commit | 2f6dc9f34ff30887dd81d98e7e2a2b7e7ff8b431 (patch) | |
| tree | ecf936c11921d357dd6b1bfe58a7a2b66a97e20c /include | |
| parent | f54195479d315568ad4f7541ef33dc1d36a986b8 (diff) | |
Add fgets() checks
Diffstat (limited to 'include')
| -rw-r--r-- | include/stdio.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/include/stdio.h b/include/stdio.h index c092435..c358825 100644 --- a/include/stdio.h +++ b/include/stdio.h | |||
| @@ -5,6 +5,16 @@ | |||
| 5 | 5 | ||
| 6 | #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 | 6 | #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 |
| 7 | 7 | ||
| 8 | static inline __attribute__ ((always_inline)) | ||
| 9 | char *__fortify_fgets(char *s, int n, FILE *fp) | ||
| 10 | { | ||
| 11 | size_t bos = __builtin_object_size(s, 0); | ||
| 12 | |||
| 13 | if ((size_t)n > bos) | ||
| 14 | __builtin_trap(); | ||
| 15 | return fgets(s, n, fp); | ||
| 16 | } | ||
| 17 | |||
| 8 | static inline | 18 | static inline |
| 9 | __attribute__ ((always_inline)) | 19 | __attribute__ ((always_inline)) |
| 10 | __attribute__ ((__format__ (printf, 3, 0))) | 20 | __attribute__ ((__format__ (printf, 3, 0))) |
| @@ -20,6 +30,8 @@ __fortify_vsnprintf(char *__restrict s, size_t n, const char *__restrict fmt, | |||
| 20 | return vsnprintf(s, n, fmt, ap); | 30 | return vsnprintf(s, n, fmt, ap); |
| 21 | } | 31 | } |
| 22 | 32 | ||
| 33 | #undef fgets | ||
| 34 | #define fgets(s, n, fp) __fortify_fgets(s, n, fp) | ||
| 23 | #undef vsnprintf | 35 | #undef vsnprintf |
| 24 | #define vsnprintf(s, n, fmt, ap) __fortify_vsnprintf(s, n, fmt, ap) | 36 | #define vsnprintf(s, n, fmt, ap) __fortify_vsnprintf(s, n, fmt, ap) |
| 25 | #undef snprintf | 37 | #undef snprintf |
