summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorsin2015-05-13 12:04:15 +0100
committersin2015-05-13 12:05:29 +0100
commit158782b3bb791eae3c97947944c7023452bfbc96 (patch)
treeb76e70744ab0a2f76d781a65a0456b1b010c54df /include
parent316a48653315b4bc36d8c50b542471b18441c9d5 (diff)
Add fortify_fn() helper in fortify-headers.h
Diffstat (limited to 'include')
-rw-r--r--include/fortify-headers.h7
-rw-r--r--include/poll.h14
-rw-r--r--include/stdio.h48
-rw-r--r--include/stdlib.h7
-rw-r--r--include/string.h73
-rw-r--r--include/strings.h13
-rw-r--r--include/sys/socket.h29
-rw-r--r--include/unistd.h73
-rw-r--r--include/wchar.h101
9 files changed, 135 insertions, 230 deletions
diff --git a/include/fortify-headers.h b/include/fortify-headers.h
new file mode 100644
index 0000000..c64963f
--- /dev/null
+++ b/include/fortify-headers.h
@@ -0,0 +1,7 @@
1#ifndef _FORTIFY_HEADERS_H
2#define _FORTIFY_HEADERS_H
3
4#define fortify_fn(fn) __typeof__(fn) __orig_##fn __asm__(__USER_LABEL_PREFIX__ #fn); \
5 extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
6
7#endif
diff --git a/include/poll.h b/include/poll.h
index d00d7c1..995f197 100644
--- a/include/poll.h
+++ b/include/poll.h
@@ -4,6 +4,7 @@
4#include_next <poll.h> 4#include_next <poll.h>
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#include "fortify-headers.h"
7 8
8#ifdef __cplusplus 9#ifdef __cplusplus
9extern "C" { 10extern "C" {
@@ -11,28 +12,25 @@ extern "C" {
11 12
12#undef poll 13#undef poll
13 14
14__typeof__(poll) __poll_orig __asm__(__USER_LABEL_PREFIX__ "poll"); 15fortify_fn(poll) int poll(struct pollfd *fds, nfds_t nfds, int timeout)
15extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
16int poll(struct pollfd *fds, nfds_t nfds, int timeout)
17{ 16{
18 __typeof__(sizeof 0) bos = __builtin_object_size(fds, 0); 17 __typeof__(sizeof 0) bos = __builtin_object_size(fds, 0);
19 18
20 if (nfds > bos / sizeof(struct pollfd)) 19 if (nfds > bos / sizeof(struct pollfd))
21 __builtin_trap(); 20 __builtin_trap();
22 return __poll_orig(fds, nfds, timeout); 21 return __orig_poll(fds, nfds, timeout);
23} 22}
24 23
25#ifdef _GNU_SOURCE 24#ifdef _GNU_SOURCE
26#undef ppoll 25#undef ppoll
27__typeof__(ppoll) __ppoll_orig __asm__(__USER_LABEL_PREFIX__ "ppoll"); 26fortify_fn(ppoll) int ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout,
28extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) 27 const sigset_t *mask)
29int ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout, const sigset_t *mask)
30{ 28{
31 __typeof__(sizeof 0) bos = __builtin_object_size(fds, 0); 29 __typeof__(sizeof 0) bos = __builtin_object_size(fds, 0);
32 30
33 if (nfds > bos / sizeof(struct pollfd)) 31 if (nfds > bos / sizeof(struct pollfd))
34 __builtin_trap(); 32 __builtin_trap();
35 return __ppoll_orig(fds, nfds, timeout, mask); 33 return __orig_ppoll(fds, nfds, timeout, mask);
36} 34}
37#endif 35#endif
38 36
diff --git a/include/stdio.h b/include/stdio.h
index ad80488..2e59e50 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -4,6 +4,7 @@
4#include_next <stdio.h> 4#include_next <stdio.h>
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#include "fortify-headers.h"
7 8
8#ifdef __cplusplus 9#ifdef __cplusplus
9extern "C" { 10extern "C" {
@@ -17,20 +18,16 @@ extern "C" {
17#undef snprintf 18#undef snprintf
18#undef sprintf 19#undef sprintf
19 20
20__typeof__(fgets) __fgets_orig __asm__(__USER_LABEL_PREFIX__ "fgets"); 21fortify_fn(fgets) char *fgets(char *s, int n, FILE *fp)
21extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
22char *fgets(char *s, int n, FILE *fp)
23{ 22{
24 size_t bos = __builtin_object_size(s, 0); 23 size_t bos = __builtin_object_size(s, 0);
25 24
26 if ((size_t)n > bos) 25 if ((size_t)n > bos)
27 __builtin_trap(); 26 __builtin_trap();
28 return __fgets_orig(s, n, fp); 27 return __orig_fgets(s, n, fp);
29} 28}
30 29
31__typeof__(fread) __fread_orig __asm__(__USER_LABEL_PREFIX__ "fread"); 30fortify_fn(fread) size_t fread(void *dst, size_t n, size_t nmemb, FILE *fp)
32extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
33size_t fread(void *dst, size_t n, size_t nmemb, FILE *fp)
34{ 31{
35 size_t bos = __builtin_object_size(dst, 0); 32 size_t bos = __builtin_object_size(dst, 0);
36 33
@@ -38,12 +35,10 @@ size_t fread(void *dst, size_t n, size_t nmemb, FILE *fp)
38 __builtin_trap(); 35 __builtin_trap();
39 if (n * nmemb > bos) 36 if (n * nmemb > bos)
40 __builtin_trap(); 37 __builtin_trap();
41 return __fread_orig(dst, n, nmemb, fp); 38 return __orig_fread(dst, n, nmemb, fp);
42} 39}
43 40
44__typeof__(fwrite) __fwrite_orig __asm__(__USER_LABEL_PREFIX__ "fwrite"); 41fortify_fn(fwrite) size_t fwrite(const void *dst, size_t n, size_t nmemb, FILE *fp)
45extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
46size_t fwrite(const void *dst, size_t n, size_t nmemb, FILE *fp)
47{ 42{
48 size_t bos = __builtin_object_size(dst, 0); 43 size_t bos = __builtin_object_size(dst, 0);
49 44
@@ -51,61 +46,54 @@ size_t fwrite(const void *dst, size_t n, size_t nmemb, FILE *fp)
51 __builtin_trap(); 46 __builtin_trap();
52 if (n * nmemb > bos) 47 if (n * nmemb > bos)
53 __builtin_trap(); 48 __builtin_trap();
54 return __fwrite_orig(dst, n, nmemb, fp); 49 return __orig_fwrite(dst, n, nmemb, fp);
55} 50}
56 51
57__typeof__(vsnprintf) __vsnprintf_orig __asm__(__USER_LABEL_PREFIX__ "vsnprintf"); 52fortify_fn(vsnprintf) int vsnprintf(char *s, size_t n, const char *fmt,
58extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) 53 __builtin_va_list ap)
59int vsnprintf(char *s, size_t n, const char *fmt, __builtin_va_list ap)
60{ 54{
61 size_t bos = __builtin_object_size(s, 0); 55 size_t bos = __builtin_object_size(s, 0);
62 56
63 if (n > bos) 57 if (n > bos)
64 __builtin_trap(); 58 __builtin_trap();
65 return __vsnprintf_orig(s, n, fmt, ap); 59 return __orig_vsnprintf(s, n, fmt, ap);
66} 60}
67 61
68__typeof__(vsprintf) __vsprintf_orig __asm__(__USER_LABEL_PREFIX__ "vsprintf"); 62fortify_fn(vsprintf) int vsprintf(char *s, const char *fmt, __builtin_va_list ap)
69extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
70int vsprintf(char *s, const char *fmt, __builtin_va_list ap)
71{ 63{
72 size_t bos = __builtin_object_size(s, 0); 64 size_t bos = __builtin_object_size(s, 0);
73 int r; 65 int r;
74 66
75 if (bos != (size_t)-1) { 67 if (bos != (size_t)-1) {
76 r = __vsnprintf_orig(s, bos, fmt, ap); 68 r = __orig_vsnprintf(s, bos, fmt, ap);
77 if (r != -1 && (size_t)r >= bos) 69 if (r != -1 && (size_t)r >= bos)
78 __builtin_trap(); 70 __builtin_trap();
79 } else { 71 } else {
80 r = __vsprintf_orig(s, fmt, ap); 72 r = __orig_vsprintf(s, fmt, ap);
81 } 73 }
82 return r; 74 return r;
83} 75}
84 76
85__typeof__(snprintf) __snprintf_orig __asm__(__USER_LABEL_PREFIX__ "snprintf"); 77fortify_fn(snprintf) int snprintf(char *s, size_t n, const char *fmt, ...)
86extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
87int snprintf(char *s, size_t n, const char *fmt, ...)
88{ 78{
89 size_t bos = __builtin_object_size(s, 0); 79 size_t bos = __builtin_object_size(s, 0);
90 80
91 if (n > bos) 81 if (n > bos)
92 __builtin_trap(); 82 __builtin_trap();
93 return __snprintf_orig(s, n, fmt, __builtin_va_arg_pack()); 83 return __orig_snprintf(s, n, fmt, __builtin_va_arg_pack());
94} 84}
95 85
96__typeof__(sprintf) __sprintf_orig __asm__(__USER_LABEL_PREFIX__ "sprintf"); 86fortify_fn(sprintf) int sprintf(char *s, const char *fmt, ...)
97extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
98int sprintf(char *s, const char *fmt, ...)
99{ 87{
100 size_t bos = __builtin_object_size(s, 0); 88 size_t bos = __builtin_object_size(s, 0);
101 int r; 89 int r;
102 90
103 if (bos != (size_t)-1) { 91 if (bos != (size_t)-1) {
104 r = __snprintf_orig(s, bos, fmt, __builtin_va_arg_pack()); 92 r = __orig_snprintf(s, bos, fmt, __builtin_va_arg_pack());
105 if (r != -1 && (size_t)r >= bos) 93 if (r != -1 && (size_t)r >= bos)
106 __builtin_trap(); 94 __builtin_trap();
107 } else { 95 } else {
108 r = __sprintf_orig(s, fmt, __builtin_va_arg_pack()); 96 r = __orig_sprintf(s, fmt, __builtin_va_arg_pack());
109 } 97 }
110 return r; 98 return r;
111} 99}
diff --git a/include/stdlib.h b/include/stdlib.h
index 0c4a7a6..16102ad 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -8,6 +8,7 @@
8#endif 8#endif
9 9
10#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 10#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0
11#include "fortify-headers.h"
11 12
12#ifdef __cplusplus 13#ifdef __cplusplus
13extern "C" { 14extern "C" {
@@ -15,9 +16,7 @@ extern "C" {
15 16
16#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 17#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
17#undef realpath 18#undef realpath
18__typeof__(realpath) __realpath_orig __asm__(__USER_LABEL_PREFIX__ "realpath"); 19fortify_fn(realpath) char *realpath(const char *path, char *resolved)
19extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
20char *realpath(const char *path, char *resolved)
21{ 20{
22 size_t bos; 21 size_t bos;
23 22
@@ -30,7 +29,7 @@ char *realpath(const char *path, char *resolved)
30 __builtin_trap(); 29 __builtin_trap();
31#endif 30#endif
32 } 31 }
33 return __realpath_orig(path, resolved); 32 return __orig_realpath(path, resolved);
34} 33}
35#endif 34#endif
36 35
diff --git a/include/string.h b/include/string.h
index eca7c63..42c43a2 100644
--- a/include/string.h
+++ b/include/string.h
@@ -4,6 +4,7 @@
4#include_next <string.h> 4#include_next <string.h>
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#include "fortify-headers.h"
7 8
8#ifdef __cplusplus 9#ifdef __cplusplus
9extern "C" { 10extern "C" {
@@ -17,9 +18,7 @@ extern "C" {
17#undef strncat 18#undef strncat
18#undef strncpy 19#undef strncpy
19 20
20__typeof__(memcpy) __memcpy_orig __asm__(__USER_LABEL_PREFIX__ "memcpy"); 21fortify_fn(memcpy) void *memcpy(void *dst, const void *src, size_t n)
21extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
22void *memcpy(void *dst, const void *src, size_t n)
23{ 22{
24 size_t bos_dst = __builtin_object_size(dst, 0); 23 size_t bos_dst = __builtin_object_size(dst, 0);
25 size_t bos_src = __builtin_object_size(src, 0); 24 size_t bos_src = __builtin_object_size(src, 0);
@@ -33,85 +32,71 @@ void *memcpy(void *dst, const void *src, size_t n)
33 __builtin_trap(); 32 __builtin_trap();
34 if (n > bos_dst || n > bos_src) 33 if (n > bos_dst || n > bos_src)
35 __builtin_trap(); 34 __builtin_trap();
36 return __memcpy_orig(dst, src, n); 35 return __orig_memcpy(dst, src, n);
37} 36}
38 37
39__typeof__(memmove) __memmove_orig __asm__(__USER_LABEL_PREFIX__ "memmove"); 38fortify_fn(memmove) void *memmove(void *dst, const void *src, size_t n)
40extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
41void *memmove(void *dst, const void *src, size_t n)
42{ 39{
43 size_t bos_dst = __builtin_object_size(dst, 0); 40 size_t bos_dst = __builtin_object_size(dst, 0);
44 size_t bos_src = __builtin_object_size(src, 0); 41 size_t bos_src = __builtin_object_size(src, 0);
45 42
46 if (n > bos_dst || n > bos_src) 43 if (n > bos_dst || n > bos_src)
47 __builtin_trap(); 44 __builtin_trap();
48 return __memmove_orig(dst, src, n); 45 return __orig_memmove(dst, src, n);
49} 46}
50 47
51__typeof__(memset) __memset_orig __asm__(__USER_LABEL_PREFIX__ "memset"); 48fortify_fn(memset) void *memset(void *dst, int c, size_t n)
52extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
53void *memset(void *dst, int c, size_t n)
54{ 49{
55 size_t bos = __builtin_object_size(dst, 0); 50 size_t bos = __builtin_object_size(dst, 0);
56 51
57 if (n > bos) 52 if (n > bos)
58 __builtin_trap(); 53 __builtin_trap();
59 return __memset_orig(dst, c, n); 54 return __orig_memset(dst, c, n);
60} 55}
61 56
62#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ 57#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
63 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ 58 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
64 || defined(_BSD_SOURCE) 59 || defined(_BSD_SOURCE)
65#undef stpcpy 60#undef stpcpy
66__typeof__(stpcpy) __stpcpy_orig __asm__(__USER_LABEL_PREFIX__ "stpcpy"); 61fortify_fn(stpcpy) char *stpcpy(char *dst, const char *src)
67extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
68char *stpcpy(char *dst, const char *src)
69{ 62{
70 size_t bos = __builtin_object_size(dst, 0); 63 size_t bos = __builtin_object_size(dst, 0);
71 64
72 if (strlen(src) + 1 > bos) 65 if (strlen(src) + 1 > bos)
73 __builtin_trap(); 66 __builtin_trap();
74 return __stpcpy_orig(dst, src); 67 return __orig_stpcpy(dst, src);
75} 68}
76 69
77#undef stpncpy 70#undef stpncpy
78__typeof__(stpncpy) __stpncpy_orig __asm__(__USER_LABEL_PREFIX__ "stpncpy"); 71fortify_fn(stpncpy) char *stpncpy(char *dst, const char *src, size_t n)
79extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
80char *stpncpy(char *dst, const char *src, size_t n)
81{ 72{
82 size_t bos = __builtin_object_size(dst, 0); 73 size_t bos = __builtin_object_size(dst, 0);
83 74
84 if (n > bos) 75 if (n > bos)
85 __builtin_trap(); 76 __builtin_trap();
86 return __stpncpy_orig(dst, src, n); 77 return __orig_stpncpy(dst, src, n);
87} 78}
88#endif 79#endif
89 80
90__typeof__(strcat) __strcat_orig __asm__(__USER_LABEL_PREFIX__ "strcat"); 81fortify_fn(strcat) char *strcat(char *dst, const char *src)
91extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
92char *strcat(char *dst, const char *src)
93{ 82{
94 size_t bos = __builtin_object_size(dst, 0); 83 size_t bos = __builtin_object_size(dst, 0);
95 84
96 if (strlen(src) + strlen(dst) + 1 > bos) 85 if (strlen(src) + strlen(dst) + 1 > bos)
97 __builtin_trap(); 86 __builtin_trap();
98 return __strcat_orig(dst, src); 87 return __orig_strcat(dst, src);
99} 88}
100 89
101__typeof__(strcpy) __strcpy_orig __asm__(__USER_LABEL_PREFIX__ "strcpy"); 90fortify_fn(strcpy) char *strcpy(char *dst, const char *src)
102extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
103char *strcpy(char *dst, const char *src)
104{ 91{
105 size_t bos = __builtin_object_size(dst, 0); 92 size_t bos = __builtin_object_size(dst, 0);
106 93
107 if (strlen(src) + 1 > bos) 94 if (strlen(src) + 1 > bos)
108 __builtin_trap(); 95 __builtin_trap();
109 return __strcpy_orig(dst, src); 96 return __orig_strcpy(dst, src);
110} 97}
111 98
112__typeof__(strncat) __strncat_orig __asm__(__USER_LABEL_PREFIX__ "strncat"); 99fortify_fn(strncat) char *strncat(char *dst, const char *src, size_t n)
113extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
114char *strncat(char *dst, const char *src, size_t n)
115{ 100{
116 size_t bos = __builtin_object_size(dst, 0); 101 size_t bos = __builtin_object_size(dst, 0);
117 size_t slen, dlen; 102 size_t slen, dlen;
@@ -124,58 +109,50 @@ char *strncat(char *dst, const char *src, size_t n)
124 if (slen + dlen + 1 > bos) 109 if (slen + dlen + 1 > bos)
125 __builtin_trap(); 110 __builtin_trap();
126 } 111 }
127 return __strncat_orig(dst, src, n); 112 return __orig_strncat(dst, src, n);
128} 113}
129 114
130__typeof__(strncpy) __strncpy_orig __asm__(__USER_LABEL_PREFIX__ "strncpy"); 115fortify_fn(strncpy) char *strncpy(char *dst, const char *src, size_t n)
131extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
132char *strncpy(char *dst, const char *src, size_t n)
133{ 116{
134 size_t bos = __builtin_object_size(dst, 0); 117 size_t bos = __builtin_object_size(dst, 0);
135 118
136 if (n > bos) 119 if (n > bos)
137 __builtin_trap(); 120 __builtin_trap();
138 return __strncpy_orig(dst, src, n); 121 return __orig_strncpy(dst, src, n);
139} 122}
140 123
141#ifdef _GNU_SOURCE 124#ifdef _GNU_SOURCE
142#undef mempcpy 125#undef mempcpy
143__typeof__(mempcpy) __mempcpy_orig __asm__(__USER_LABEL_PREFIX__ "mempcpy"); 126fortify_fn(mempcpy) void *mempcpy(void *dst, const void *src, size_t n)
144extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
145void *mempcpy(void *dst, const void *src, size_t n)
146{ 127{
147 size_t bos_dst = __builtin_object_size(dst, 0); 128 size_t bos_dst = __builtin_object_size(dst, 0);
148 size_t bos_src = __builtin_object_size(src, 0); 129 size_t bos_src = __builtin_object_size(src, 0);
149 130
150 if (n > bos_dst || n > bos_src) 131 if (n > bos_dst || n > bos_src)
151 __builtin_trap(); 132 __builtin_trap();
152 return __mempcpy_orig(dst, src, n); 133 return __orig_mempcpy(dst, src, n);
153} 134}
154#endif 135#endif
155 136
156#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 137#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
157#undef strlcat 138#undef strlcat
158#undef strlcpy 139#undef strlcpy
159__typeof__(strlcat) __strlcat_orig __asm__(__USER_LABEL_PREFIX__ "strlcat"); 140fortify_fn(strlcat) size_t strlcat(char *dst, const char *src, size_t n)
160extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
161size_t strlcat(char *dst, const char *src, size_t n)
162{ 141{
163 size_t bos = __builtin_object_size(dst, 0); 142 size_t bos = __builtin_object_size(dst, 0);
164 143
165 if (n > bos) 144 if (n > bos)
166 __builtin_trap(); 145 __builtin_trap();
167 return __strlcat_orig(dst, src, n); 146 return __orig_strlcat(dst, src, n);
168} 147}
169 148
170__typeof__(strlcpy) __strlcpy_orig __asm__(__USER_LABEL_PREFIX__ "strlcpy"); 149fortify_fn(strlcpy) size_t strlcpy(char *dst, const char *src, size_t n)
171extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
172size_t strlcpy(char *dst, const char *src, size_t n)
173{ 150{
174 size_t bos = __builtin_object_size(dst, 0); 151 size_t bos = __builtin_object_size(dst, 0);
175 152
176 if (n > bos) 153 if (n > bos)
177 __builtin_trap(); 154 __builtin_trap();
178 return __strlcpy_orig(dst, src, n); 155 return __orig_strlcpy(dst, src, n);
179} 156}
180#endif 157#endif
181 158
diff --git a/include/strings.h b/include/strings.h
index 4e0c194..b5f1f5b 100644
--- a/include/strings.h
+++ b/include/strings.h
@@ -4,6 +4,7 @@
4#include_next <strings.h> 4#include_next <strings.h>
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#include "fortify-headers.h"
7 8
8#ifdef __cplusplus 9#ifdef __cplusplus
9extern "C" { 10extern "C" {
@@ -14,27 +15,23 @@ extern "C" {
14 || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) 15 || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700)
15#undef bcopy 16#undef bcopy
16#undef bzero 17#undef bzero
17__typeof__(bcopy) __bcopy_orig __asm__(__USER_LABEL_PREFIX__ "bcopy"); 18fortify_fn(bcopy) void bcopy(const void *src, void *dst, size_t n)
18extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
19void bcopy(const void *src, void *dst, size_t n)
20{ 19{
21 size_t bos_dst = __builtin_object_size(dst, 0); 20 size_t bos_dst = __builtin_object_size(dst, 0);
22 size_t bos_src = __builtin_object_size(src, 0); 21 size_t bos_src = __builtin_object_size(src, 0);
23 22
24 if (n > bos_dst || n > bos_src) 23 if (n > bos_dst || n > bos_src)
25 __builtin_trap(); 24 __builtin_trap();
26 return __bcopy_orig(src, dst, n); 25 return __orig_bcopy(src, dst, n);
27} 26}
28 27
29__typeof__(bzero) __bzero_orig __asm__(__USER_LABEL_PREFIX__ "bzero"); 28fortify_fn(bzero) void bzero(void *src, size_t n)
30extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
31void bzero(void *src, size_t n)
32{ 29{
33 size_t bos = __builtin_object_size(src, 0); 30 size_t bos = __builtin_object_size(src, 0);
34 31
35 if (n > bos) 32 if (n > bos)
36 __builtin_trap(); 33 __builtin_trap();
37 return __bzero_orig(src, n); 34 return __orig_bzero(src, n);
38} 35}
39#endif 36#endif
40 37
diff --git a/include/sys/socket.h b/include/sys/socket.h
index d7871ae..5db1cb1 100644
--- a/include/sys/socket.h
+++ b/include/sys/socket.h
@@ -4,6 +4,7 @@
4#include_next <sys/socket.h> 4#include_next <sys/socket.h>
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#include "../fortify-headers.h"
7 8
8#ifdef __cplusplus 9#ifdef __cplusplus
9extern "C" { 10extern "C" {
@@ -14,50 +15,42 @@ extern "C" {
14#undef send 15#undef send
15#undef sendto 16#undef sendto
16 17
17__typeof__(recv) __recv_orig __asm__(__USER_LABEL_PREFIX__ "recv"); 18fortify_fn(recv) ssize_t recv(int sockfd, void *buf, size_t n, int flags)
18extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
19ssize_t recv(int sockfd, void *buf, size_t n, int flags)
20{ 19{
21 size_t bos = __builtin_object_size(buf, 0); 20 size_t bos = __builtin_object_size(buf, 0);
22 21
23 if (n > bos) 22 if (n > bos)
24 __builtin_trap(); 23 __builtin_trap();
25 return __recv_orig(sockfd, buf, n, flags); 24 return __orig_recv(sockfd, buf, n, flags);
26} 25}
27 26
28__typeof__(recvfrom) __recvfrom_orig __asm__(__USER_LABEL_PREFIX__ "recvfrom"); 27fortify_fn(recvfrom) ssize_t recvfrom(int sockfd, void *buf, size_t n, int flags,
29extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) 28 struct sockaddr *sa, socklen_t *salen)
30ssize_t recvfrom(int sockfd, void *buf, size_t n, int flags,
31 struct sockaddr *sa, socklen_t *salen)
32{ 29{
33 size_t bos = __builtin_object_size(buf, 0); 30 size_t bos = __builtin_object_size(buf, 0);
34 31
35 if (n > bos) 32 if (n > bos)
36 __builtin_trap(); 33 __builtin_trap();
37 return __recvfrom_orig(sockfd, buf, n, flags, sa, salen); 34 return __orig_recvfrom(sockfd, buf, n, flags, sa, salen);
38} 35}
39 36
40__typeof__(send) __send_orig __asm__(__USER_LABEL_PREFIX__ "send"); 37fortify_fn(send) ssize_t send(int sockfd, const void *buf, size_t n, int flags)
41extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
42ssize_t send(int sockfd, const void *buf, size_t n, int flags)
43{ 38{
44 size_t bos = __builtin_object_size(buf, 0); 39 size_t bos = __builtin_object_size(buf, 0);
45 40
46 if (n > bos) 41 if (n > bos)
47 __builtin_trap(); 42 __builtin_trap();
48 return __send_orig(sockfd, buf, n, flags); 43 return __orig_send(sockfd, buf, n, flags);
49} 44}
50 45
51__typeof__(sendto) __sendto_orig __asm__(__USER_LABEL_PREFIX__ "sendto"); 46fortify_fn(sendto) ssize_t sendto(int sockfd, const void *buf, size_t n, int flags,
52extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) 47 const struct sockaddr *sa, socklen_t salen)
53ssize_t sendto(int sockfd, const void *buf, size_t n, int flags,
54 const struct sockaddr *sa, socklen_t salen)
55{ 48{
56 size_t bos = __builtin_object_size(buf, 0); 49 size_t bos = __builtin_object_size(buf, 0);
57 50
58 if (n > bos) 51 if (n > bos)
59 __builtin_trap(); 52 __builtin_trap();
60 return __sendto_orig(sockfd, buf, n, flags, sa, salen); 53 return __orig_sendto(sockfd, buf, n, flags, sa, salen);
61} 54}
62 55
63#ifdef __cplusplus 56#ifdef __cplusplus
diff --git a/include/unistd.h b/include/unistd.h
index 318fcc5..23a8341 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -4,6 +4,7 @@
4#include_next <unistd.h> 4#include_next <unistd.h>
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#include "fortify-headers.h"
7 8
8#ifdef __cplusplus 9#ifdef __cplusplus
9extern "C" { 10extern "C" {
@@ -21,139 +22,115 @@ extern "C" {
21#undef ttyname_r 22#undef ttyname_r
22#undef write 23#undef write
23 24
24__typeof__(confstr) __confstr_orig __asm__(__USER_LABEL_PREFIX__ "confstr"); 25fortify_fn(confstr) size_t confstr(int name, char *buf, size_t len)
25extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
26size_t confstr(int name, char *buf, size_t len)
27{ 26{
28 size_t bos = __builtin_object_size(buf, 0); 27 size_t bos = __builtin_object_size(buf, 0);
29 28
30 if (len > bos) 29 if (len > bos)
31 __builtin_trap(); 30 __builtin_trap();
32 return __confstr_orig(name, buf, len); 31 return __orig_confstr(name, buf, len);
33} 32}
34 33
35__typeof__(getcwd) __getcwd_orig __asm__(__USER_LABEL_PREFIX__ "getcwd"); 34fortify_fn(getcwd) char *getcwd(char *buf, size_t len)
36extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
37char *getcwd(char *buf, size_t len)
38{ 35{
39 size_t bos = __builtin_object_size(buf, 0); 36 size_t bos = __builtin_object_size(buf, 0);
40 37
41 if (len > bos) 38 if (len > bos)
42 __builtin_trap(); 39 __builtin_trap();
43 return __getcwd_orig(buf, len); 40 return __orig_getcwd(buf, len);
44} 41}
45 42
46#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 43#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
47#undef getdomainname 44#undef getdomainname
48__typeof__(getdomainname) __getdomainname_orig __asm__(__USER_LABEL_PREFIX__ "getdomainname"); 45fortify_fn(getdomainname) int getdomainname(char *name, size_t len)
49extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
50int getdomainname(char *name, size_t len)
51{ 46{
52 size_t bos = __builtin_object_size(name, 0); 47 size_t bos = __builtin_object_size(name, 0);
53 48
54 if (len > bos) 49 if (len > bos)
55 __builtin_trap(); 50 __builtin_trap();
56 return __getdomainname_orig(name, len); 51 return __orig_getdomainname(name, len);
57} 52}
58#endif 53#endif
59 54
60__typeof__(getgroups) __getgroups_orig __asm__(__USER_LABEL_PREFIX__ "getgroups"); 55fortify_fn(getgroups) int getgroups(int len, gid_t *set)
61extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
62int getgroups(int len, gid_t *set)
63{ 56{
64 size_t bos = __builtin_object_size(set, 0); 57 size_t bos = __builtin_object_size(set, 0);
65 58
66 if (len > bos / sizeof(gid_t)) 59 if (len > bos / sizeof(gid_t))
67 __builtin_trap(); 60 __builtin_trap();
68 return __getgroups_orig(len, set); 61 return __orig_getgroups(len, set);
69} 62}
70 63
71__typeof__(gethostname) __gethostname_orig __asm__(__USER_LABEL_PREFIX__ "gethostname"); 64fortify_fn(gethostname) int gethostname(char *name, size_t len)
72extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
73int gethostname(char *name, size_t len)
74{ 65{
75 size_t bos = __builtin_object_size(name, 0); 66 size_t bos = __builtin_object_size(name, 0);
76 67
77 if (len > bos) 68 if (len > bos)
78 __builtin_trap(); 69 __builtin_trap();
79 return __gethostname_orig(name, len); 70 return __orig_gethostname(name, len);
80} 71}
81 72
82__typeof__(getlogin_r) __getlogin_r_orig __asm__(__USER_LABEL_PREFIX__ "getlogin_r"); 73fortify_fn(getlogin_r) int getlogin_r(char *name, size_t len)
83extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
84int getlogin_r(char *name, size_t len)
85{ 74{
86 size_t bos = __builtin_object_size(name, 0); 75 size_t bos = __builtin_object_size(name, 0);
87 76
88 if (len > bos) 77 if (len > bos)
89 __builtin_trap(); 78 __builtin_trap();
90 return __getlogin_r_orig(name, len); 79 return __orig_getlogin_r(name, len);
91} 80}
92 81
93__typeof__(pread) __pread_orig __asm__(__USER_LABEL_PREFIX__ "pread"); 82fortify_fn(pread) ssize_t pread(int fd, void *buf, size_t n, off_t offset)
94extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
95ssize_t pread(int fd, void *buf, size_t n, off_t offset)
96{ 83{
97 size_t bos = __builtin_object_size(buf, 0); 84 size_t bos = __builtin_object_size(buf, 0);
98 85
99 if (n > bos) 86 if (n > bos)
100 __builtin_trap(); 87 __builtin_trap();
101 return __pread_orig(fd, buf, n, offset); 88 return __orig_pread(fd, buf, n, offset);
102} 89}
103 90
104__typeof__(read) __read_orig __asm__(__USER_LABEL_PREFIX__ "read"); 91fortify_fn(read) ssize_t read(int fd, void *buf, size_t n)
105extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
106ssize_t read(int fd, void *buf, size_t n)
107{ 92{
108 size_t bos = __builtin_object_size(buf, 0); 93 size_t bos = __builtin_object_size(buf, 0);
109 94
110 if (n > bos) 95 if (n > bos)
111 __builtin_trap(); 96 __builtin_trap();
112 return __read_orig(fd, buf, n); 97 return __orig_read(fd, buf, n);
113} 98}
114 99
115__typeof__(readlink) __readlink_orig __asm__(__USER_LABEL_PREFIX__ "readlink"); 100fortify_fn(readlink) ssize_t readlink(const char *path, char *buf, size_t n)
116extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
117ssize_t readlink(const char *path, char *buf, size_t n)
118{ 101{
119 size_t bos = __builtin_object_size(buf, 0); 102 size_t bos = __builtin_object_size(buf, 0);
120 103
121 if (n > bos) 104 if (n > bos)
122 __builtin_trap(); 105 __builtin_trap();
123 return __readlink_orig(path, buf, n); 106 return __orig_readlink(path, buf, n);
124} 107}
125 108
126__typeof__(readlinkat) __readlinkat_orig __asm__(__USER_LABEL_PREFIX__ "readlinkat"); 109fortify_fn(readlinkat) ssize_t readlinkat(int fd, const char *path, char *buf, size_t n)
127extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
128ssize_t readlinkat(int fd, const char *path, char *buf, size_t n)
129{ 110{
130 size_t bos = __builtin_object_size(buf, 0); 111 size_t bos = __builtin_object_size(buf, 0);
131 112
132 if (n > bos) 113 if (n > bos)
133 __builtin_trap(); 114 __builtin_trap();
134 return __readlinkat_orig(fd, path, buf, n); 115 return __orig_readlinkat(fd, path, buf, n);
135} 116}
136 117
137__typeof__(ttyname_r) __ttyname_r_orig __asm__(__USER_LABEL_PREFIX__ "ttyname_r"); 118fortify_fn(ttyname_r) int ttyname_r(int fd, char *name, size_t n)
138extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
139int ttyname_r(int fd, char *name, size_t n)
140{ 119{
141 size_t bos = __builtin_object_size(name, 0); 120 size_t bos = __builtin_object_size(name, 0);
142 121
143 if (n > bos) 122 if (n > bos)
144 __builtin_trap(); 123 __builtin_trap();
145 return __ttyname_r_orig(fd, name, n); 124 return __orig_ttyname_r(fd, name, n);
146} 125}
147 126
148__typeof__(write) __write_orig __asm__(__USER_LABEL_PREFIX__ "write"); 127fortify_fn(write) ssize_t write(int fd, const void *buf, size_t n)
149extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
150ssize_t write(int fd, const void *buf, size_t n)
151{ 128{
152 size_t bos = __builtin_object_size(buf, 0); 129 size_t bos = __builtin_object_size(buf, 0);
153 130
154 if (n > bos) 131 if (n > bos)
155 __builtin_trap(); 132 __builtin_trap();
156 return __write_orig(fd, buf, n); 133 return __orig_write(fd, buf, n);
157} 134}
158 135
159#ifdef __cplusplus 136#ifdef __cplusplus
diff --git a/include/wchar.h b/include/wchar.h
index e2d56e8..33f1fbf 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -5,6 +5,7 @@
5#include_next <wchar.h> 5#include_next <wchar.h>
6 6
7#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 7#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0
8#include "fortify-headers.h"
8 9
9#ifdef __cplusplus 10#ifdef __cplusplus
10extern "C" { 11extern "C" {
@@ -25,34 +26,30 @@ extern "C" {
25#undef wmemmove 26#undef wmemmove
26#undef wmemset 27#undef wmemset
27 28
28__typeof__(fgetws) __fgetws_orig __asm__(__USER_LABEL_PREFIX__ "fgetws"); 29fortify_fn(fgetws) wchar_t *fgetws(wchar_t *s, int n, FILE *fp)
29extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
30wchar_t *fgetws(wchar_t *s, int n, FILE *fp)
31{ 30{
32 size_t bos = __builtin_object_size(s, 0); 31 size_t bos = __builtin_object_size(s, 0);
33 32
34 if ((size_t)n > bos / sizeof(wchar_t)) 33 if ((size_t)n > bos / sizeof(wchar_t))
35 __builtin_trap(); 34 __builtin_trap();
36 return __fgetws_orig(s, n, fp); 35 return __orig_fgetws(s, n, fp);
37} 36}
38 37
39#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ 38#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
40 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 39 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
41#undef mbsnrtowcs 40#undef mbsnrtowcs
42__typeof__(mbsnrtowcs) __mbsnrtowcs_orig __asm__(__USER_LABEL_PREFIX__ "mbsnrtowcs"); 41fortify_fn(mbsnrtowcs) size_t mbsnrtowcs(wchar_t *d, const char **s, size_t n, size_t wn, mbstate_t *st)
43extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
44size_t mbsnrtowcs(wchar_t *d, const char **s, size_t n, size_t wn, mbstate_t *st)
45{ 42{
46 size_t bos = __builtin_object_size(d, 0); 43 size_t bos = __builtin_object_size(d, 0);
47 size_t r; 44 size_t r;
48 45
49 if (wn > n / sizeof(wchar_t)) { 46 if (wn > n / sizeof(wchar_t)) {
50 bos /= sizeof(wchar_t); 47 bos /= sizeof(wchar_t);
51 r = __mbsnrtowcs_orig(d, s, n, wn > bos ? bos : wn, st); 48 r = __orig_mbsnrtowcs(d, s, n, wn > bos ? bos : wn, st);
52 if (bos < wn && d && *s && r != (size_t)-1) 49 if (bos < wn && d && *s && r != (size_t)-1)
53 __builtin_trap(); 50 __builtin_trap();
54 } else { 51 } else {
55 r = __mbsnrtowcs_orig(d, s, n > bos ? bos : n, wn, st); 52 r = __orig_mbsnrtowcs(d, s, n > bos ? bos : n, wn, st);
56 if (bos < n && d && *s && r != (size_t)-1) 53 if (bos < n && d && *s && r != (size_t)-1)
57 __builtin_trap(); 54 __builtin_trap();
58 } 55 }
@@ -60,67 +57,55 @@ size_t mbsnrtowcs(wchar_t *d, const char **s, size_t n, size_t wn, mbstate_t *st
60} 57}
61#endif 58#endif
62 59
63__typeof__(mbsrtowcs) __mbsrtowcs_orig __asm__(__USER_LABEL_PREFIX__ "mbsrtowcs"); 60fortify_fn(mbsrtowcs) size_t mbsrtowcs(wchar_t *d, const char **s, size_t wn, mbstate_t *st)
64extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
65size_t mbsrtowcs(wchar_t *d, const char **s, size_t wn, mbstate_t *st)
66{ 61{
67 size_t bos = __builtin_object_size(d, 0); 62 size_t bos = __builtin_object_size(d, 0);
68 size_t r; 63 size_t r;
69 64
70 bos /= sizeof(wchar_t); 65 bos /= sizeof(wchar_t);
71 r = __mbsrtowcs_orig(d, s, wn > bos ? bos : wn, st); 66 r = __orig_mbsrtowcs(d, s, wn > bos ? bos : wn, st);
72 if (bos < wn && d && *s && r != (size_t)-1) 67 if (bos < wn && d && *s && r != (size_t)-1)
73 __builtin_trap(); 68 __builtin_trap();
74 return r; 69 return r;
75} 70}
76 71
77__typeof__(mbstowcs) __mbstowcs_orig __asm__(__USER_LABEL_PREFIX__ "mbstowcs"); 72fortify_fn(mbstowcs) size_t mbstowcs(wchar_t *ws, const char *s, size_t wn)
78extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
79size_t mbstowcs(wchar_t *ws, const char *s, size_t wn)
80{ 73{
81 size_t bos = __builtin_object_size(ws, 0); 74 size_t bos = __builtin_object_size(ws, 0);
82 75
83 if (ws && wn > bos / sizeof(wchar_t)) 76 if (ws && wn > bos / sizeof(wchar_t))
84 __builtin_trap(); 77 __builtin_trap();
85 return __mbstowcs_orig(ws, s, wn); 78 return __orig_mbstowcs(ws, s, wn);
86} 79}
87 80
88__typeof__(wcrtomb) __wcrtomb_orig __asm__(__USER_LABEL_PREFIX__ "wcrtomb"); 81fortify_fn(wcrtomb) size_t wcrtomb(char *s, wchar_t wc, mbstate_t *st)
89extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
90size_t wcrtomb(char *s, wchar_t wc, mbstate_t *st)
91{ 82{
92 size_t bos = __builtin_object_size(s, 0); 83 size_t bos = __builtin_object_size(s, 0);
93 84
94 if (s && MB_CUR_MAX > bos) 85 if (s && MB_CUR_MAX > bos)
95 __builtin_trap(); 86 __builtin_trap();
96 return __wcrtomb_orig(s, wc, st); 87 return __orig_wcrtomb(s, wc, st);
97} 88}
98 89
99__typeof__(wcscat) __wcscat_orig __asm__(__USER_LABEL_PREFIX__ "wcscat"); 90fortify_fn(wcscat) wchar_t *wcscat(wchar_t *d, const wchar_t *s)
100extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
101wchar_t *wcscat(wchar_t *d, const wchar_t *s)
102{ 91{
103 size_t bos = __builtin_object_size(d, 0); 92 size_t bos = __builtin_object_size(d, 0);
104 93
105 if (wcslen(s) + wcslen(d) + 1 > bos / sizeof(wchar_t)) 94 if (wcslen(s) + wcslen(d) + 1 > bos / sizeof(wchar_t))
106 __builtin_trap(); 95 __builtin_trap();
107 return __wcscat_orig(d, s); 96 return __orig_wcscat(d, s);
108} 97}
109 98
110__typeof__(wcscpy) __wcscpy_orig __asm__(__USER_LABEL_PREFIX__ "wcscpy"); 99fortify_fn(wcscpy) wchar_t *wcscpy(wchar_t *d, const wchar_t *s)
111extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
112wchar_t *wcscpy(wchar_t *d, const wchar_t *s)
113{ 100{
114 size_t bos = __builtin_object_size(d, 0); 101 size_t bos = __builtin_object_size(d, 0);
115 102
116 if (wcslen(s) + 1 > bos / sizeof(wchar_t)) 103 if (wcslen(s) + 1 > bos / sizeof(wchar_t))
117 __builtin_trap(); 104 __builtin_trap();
118 return __wcscpy_orig(d, s); 105 return __orig_wcscpy(d, s);
119} 106}
120 107
121__typeof__(wcsncat) __wcsncat_orig __asm__(__USER_LABEL_PREFIX__ "wcsncat"); 108fortify_fn(wcsncat) wchar_t *wcsncat(wchar_t *d, const wchar_t *s, size_t n)
122extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
123wchar_t *wcsncat(wchar_t *d, const wchar_t *s, size_t n)
124{ 109{
125 size_t bos = __builtin_object_size(d, 0); 110 size_t bos = __builtin_object_size(d, 0);
126 size_t slen, dlen; 111 size_t slen, dlen;
@@ -133,37 +118,33 @@ wchar_t *wcsncat(wchar_t *d, const wchar_t *s, size_t n)
133 if (slen + dlen + 1 > bos / sizeof(wchar_t)) 118 if (slen + dlen + 1 > bos / sizeof(wchar_t))
134 __builtin_trap(); 119 __builtin_trap();
135 } 120 }
136 return __wcsncat_orig(d, s, n); 121 return __orig_wcsncat(d, s, n);
137} 122}
138 123
139__typeof__(wcsncpy) __wcsncpy_orig __asm__(__USER_LABEL_PREFIX__ "wcsncpy"); 124fortify_fn(wcsncpy) wchar_t *wcsncpy(wchar_t *d, const wchar_t *s, size_t n)
140extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
141wchar_t *wcsncpy(wchar_t *d, const wchar_t *s, size_t n)
142{ 125{
143 size_t bos = __builtin_object_size(d, 0); 126 size_t bos = __builtin_object_size(d, 0);
144 127
145 if (n > bos / sizeof(wchar_t)) 128 if (n > bos / sizeof(wchar_t))
146 __builtin_trap(); 129 __builtin_trap();
147 return __wcsncpy_orig(d, s, n); 130 return __orig_wcsncpy(d, s, n);
148} 131}
149 132
150#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ 133#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
151 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 134 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
152#undef wcsnrtombs 135#undef wcsnrtombs
153__typeof__(wcsnrtombs) __wcsnrtombs_orig __asm__(__USER_LABEL_PREFIX__ "wcsnrtombs"); 136fortify_fn(wcsnrtombs) size_t wcsnrtombs(char *d, const wchar_t **s, size_t wn, size_t n, mbstate_t *st)
154extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
155size_t wcsnrtombs(char *d, const wchar_t **s, size_t wn, size_t n, mbstate_t *st)
156{ 137{
157 size_t bos = __builtin_object_size(d, 0); 138 size_t bos = __builtin_object_size(d, 0);
158 size_t r; 139 size_t r;
159 140
160 if (wn > n / sizeof(wchar_t)) { 141 if (wn > n / sizeof(wchar_t)) {
161 bos /= sizeof(wchar_t); 142 bos /= sizeof(wchar_t);
162 r = __wcsnrtombs_orig(d, s, wn > bos ? bos : wn, n, st); 143 r = __orig_wcsnrtombs(d, s, wn > bos ? bos : wn, n, st);
163 if (bos < wn && d && *s && r != (size_t)-1) 144 if (bos < wn && d && *s && r != (size_t)-1)
164 __builtin_trap(); 145 __builtin_trap();
165 } else { 146 } else {
166 r = __wcsnrtombs_orig(d, s, wn, n > bos ? bos : n, st); 147 r = __orig_wcsnrtombs(d, s, wn, n > bos ? bos : n, st);
167 if (bos < n && d && *s && r != (size_t)-1) 148 if (bos < n && d && *s && r != (size_t)-1)
168 __builtin_trap(); 149 __builtin_trap();
169 } 150 }
@@ -171,72 +152,60 @@ size_t wcsnrtombs(char *d, const wchar_t **s, size_t wn, size_t n, mbstate_t *st
171} 152}
172#endif 153#endif
173 154
174__typeof__(wcsrtombs) __wcsrtombs_orig __asm__(__USER_LABEL_PREFIX__ "wcsrtombs"); 155fortify_fn(wcsrtombs) size_t wcsrtombs(char *d, const wchar_t **s, size_t n, mbstate_t *st)
175extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
176size_t wcsrtombs(char *d, const wchar_t **s, size_t n, mbstate_t *st)
177{ 156{
178 size_t bos = __builtin_object_size(d, 0); 157 size_t bos = __builtin_object_size(d, 0);
179 size_t r; 158 size_t r;
180 159
181 r = __wcsrtombs_orig(d, s, n > bos ? bos : n, st); 160 r = __orig_wcsrtombs(d, s, n > bos ? bos : n, st);
182 if (bos < n && d && *s && r != (size_t)-1) 161 if (bos < n && d && *s && r != (size_t)-1)
183 __builtin_trap(); 162 __builtin_trap();
184 return r; 163 return r;
185} 164}
186 165
187__typeof__(wcstombs) __wcstombs_orig __asm__(__USER_LABEL_PREFIX__ "wcstombs"); 166fortify_fn(wcstombs) size_t wcstombs(char *s, const wchar_t *ws, size_t n)
188extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
189size_t wcstombs(char *s, const wchar_t *ws, size_t n)
190{ 167{
191 size_t bos = __builtin_object_size(s, 0); 168 size_t bos = __builtin_object_size(s, 0);
192 169
193 if (s && n > bos) 170 if (s && n > bos)
194 __builtin_trap(); 171 __builtin_trap();
195 return __wcstombs_orig(s, ws, n); 172 return __orig_wcstombs(s, ws, n);
196} 173}
197 174
198__typeof__(wctomb) __wctomb_orig __asm__(__USER_LABEL_PREFIX__ "wctomb"); 175fortify_fn(wctomb) int wctomb(char *s, wchar_t wc)
199extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
200int wctomb(char *s, wchar_t wc)
201{ 176{
202 size_t bos = __builtin_object_size(s, 0); 177 size_t bos = __builtin_object_size(s, 0);
203 178
204 if (s && MB_CUR_MAX > bos) 179 if (s && MB_CUR_MAX > bos)
205 __builtin_trap(); 180 __builtin_trap();
206 return __wctomb_orig(s, wc); 181 return __orig_wctomb(s, wc);
207} 182}
208 183
209__typeof__(wmemcpy) __wmemcpy_orig __asm__(__USER_LABEL_PREFIX__ "wmemcpy"); 184fortify_fn(wmemcpy) wchar_t *wmemcpy(wchar_t *d, const wchar_t *s, size_t n)
210extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
211wchar_t *wmemcpy(wchar_t *d, const wchar_t *s, size_t n)
212{ 185{
213 size_t bos = __builtin_object_size(d, 0); 186 size_t bos = __builtin_object_size(d, 0);
214 187
215 if (n > bos / sizeof(wchar_t)) 188 if (n > bos / sizeof(wchar_t))
216 __builtin_trap(); 189 __builtin_trap();
217 return __wmemcpy_orig(d, s, n); 190 return __orig_wmemcpy(d, s, n);
218} 191}
219 192
220__typeof__(wmemmove) __wmemmove_orig __asm__(__USER_LABEL_PREFIX__ "wmemmove"); 193fortify_fn(wmemmove) wchar_t *wmemmove(wchar_t *d, const wchar_t *s, size_t n)
221extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
222wchar_t *wmemmove(wchar_t *d, const wchar_t *s, size_t n)
223{ 194{
224 size_t bos = __builtin_object_size(d, 0); 195 size_t bos = __builtin_object_size(d, 0);
225 196
226 if (n > bos / sizeof(wchar_t)) 197 if (n > bos / sizeof(wchar_t))
227 __builtin_trap(); 198 __builtin_trap();
228 return __wmemmove_orig(d, s, n); 199 return __orig_wmemmove(d, s, n);
229} 200}
230 201
231__typeof__(wmemset) __wmemset_orig __asm__(__USER_LABEL_PREFIX__ "wmemset"); 202fortify_fn(wmemset) wchar_t *wmemset(wchar_t *s, wchar_t c, size_t n)
232extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
233wchar_t *wmemset(wchar_t *s, wchar_t c, size_t n)
234{ 203{
235 size_t bos = __builtin_object_size(s, 0); 204 size_t bos = __builtin_object_size(s, 0);
236 205
237 if (n > bos / sizeof(wchar_t)) 206 if (n > bos / sizeof(wchar_t))
238 __builtin_trap(); 207 __builtin_trap();
239 return __wmemset_orig(s, c, n); 208 return __orig_wmemset(s, c, n);
240} 209}
241 210
242#ifdef __cplusplus 211#ifdef __cplusplus