summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/stdio.h12
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
8static inline __attribute__ ((always_inline))
9char *__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
8static inline 18static 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