diff options
| author | sin | 2015-03-13 11:00:46 +0000 |
|---|---|---|
| committer | sin | 2015-03-13 11:00:46 +0000 |
| commit | 9f8c543dc81f0c4239acae6713f5414eb7dc681d (patch) | |
| tree | 0c8dad17e27c510cc3c98502841aa1a75dfa3d1e | |
| parent | b211796d68c4a6b56f999534627791f3576b6135 (diff) | |
Rework fortify implementation to use extern inline
Overriding functions with macros is legal in C but a lot of software
is not prepared for it. Use the extern inline method to achieve the
same result.
| -rw-r--r-- | include/poll.h | 29 | ||||
| -rw-r--r-- | include/stdio.h | 65 | ||||
| -rw-r--r-- | include/stdlib.h | 13 | ||||
| -rw-r--r-- | include/string.h | 151 | ||||
| -rw-r--r-- | include/strings.h | 25 | ||||
| -rw-r--r-- | include/sys/select.h | 10 | ||||
| -rw-r--r-- | include/sys/socket.h | 53 | ||||
| -rw-r--r-- | include/unistd.h | 149 | ||||
| -rw-r--r-- | include/wchar.h | 201 |
9 files changed, 335 insertions, 361 deletions
diff --git a/include/poll.h b/include/poll.h index 5490b94..93976dd 100644 --- a/include/poll.h +++ b/include/poll.h | |||
| @@ -6,40 +6,35 @@ | |||
| 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 | #ifndef __cplusplus | 8 | #ifndef __cplusplus |
| 9 | #undef poll | ||
| 9 | 10 | ||
| 10 | static inline __attribute__ ((always_inline)) | 11 | extern int __poll_orig(struct pollfd *, nfds_t, int) |
| 11 | int | 12 | __asm__(__USER_LABEL_PREFIX__ "poll"); |
| 12 | __fortify_poll(struct pollfd *fds, nfds_t nfds, int timeout) | 13 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 14 | int poll(struct pollfd *fds, nfds_t nfds, int timeout) | ||
| 13 | { | 15 | { |
| 14 | __typeof__(sizeof 0) bos = __builtin_object_size(fds, 0); | 16 | __typeof__(sizeof 0) bos = __builtin_object_size(fds, 0); |
| 15 | 17 | ||
| 16 | if (nfds > bos / sizeof(struct pollfd)) | 18 | if (nfds > bos / sizeof(struct pollfd)) |
| 17 | __builtin_trap(); | 19 | __builtin_trap(); |
| 18 | return poll(fds, nfds, timeout); | 20 | return __poll_orig(fds, nfds, timeout); |
| 19 | } | 21 | } |
| 20 | 22 | ||
| 21 | #ifdef _GNU_SOURCE | 23 | #ifdef _GNU_SOURCE |
| 22 | static inline __attribute__ ((always_inline)) | 24 | #undef ppoll |
| 23 | int | 25 | extern int __ppoll_orig(struct pollfd *, nfds_t, const struct timespec *, const sigset_t *) |
| 24 | __fortify_ppoll(struct pollfd *fds, nfds_t nfds, | 26 | __asm__(__USER_LABEL_PREFIX__ "ppoll"); |
| 25 | const struct timespec *timeout, const sigset_t *mask) | 27 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 28 | int ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout, const sigset_t *mask) | ||
| 26 | { | 29 | { |
| 27 | __typeof__(sizeof 0) bos = __builtin_object_size(fds, 0); | 30 | __typeof__(sizeof 0) bos = __builtin_object_size(fds, 0); |
| 28 | 31 | ||
| 29 | if (nfds > bos / sizeof(struct pollfd)) | 32 | if (nfds > bos / sizeof(struct pollfd)) |
| 30 | __builtin_trap(); | 33 | __builtin_trap(); |
| 31 | return ppoll(fds, nfds, timeout, mask); | 34 | return __ppoll_orig(fds, nfds, timeout, mask); |
| 32 | } | 35 | } |
| 33 | #endif | 36 | #endif |
| 34 | 37 | ||
| 35 | #undef poll | ||
| 36 | #define poll(fds, nfds, timeout) __fortify_poll(fds, nfds, timeout) | ||
| 37 | |||
| 38 | #ifdef _GNU_SOURCE | ||
| 39 | #undef ppoll | ||
| 40 | #define ppoll(fds, nfds, timeout, mask) __fortify_ppoll(fds, nfds, timeout, mask) | ||
| 41 | #endif | ||
| 42 | |||
| 43 | #endif | 38 | #endif |
| 44 | 39 | ||
| 45 | #endif | 40 | #endif |
diff --git a/include/stdio.h b/include/stdio.h index a33514d..98e51ac 100644 --- a/include/stdio.h +++ b/include/stdio.h | |||
| @@ -6,21 +6,30 @@ | |||
| 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 | #ifndef __cplusplus | 8 | #ifndef __cplusplus |
| 9 | #undef fgets | ||
| 10 | #undef fread | ||
| 11 | #undef fwrite | ||
| 12 | #undef vsnprintf | ||
| 13 | #undef vsnprintf | ||
| 14 | #undef snprintf | ||
| 15 | #undef sprintf | ||
| 9 | 16 | ||
| 10 | static inline __attribute__ ((always_inline)) | 17 | extern char *__fgets_orig(char *, int, FILE *) |
| 11 | char * | 18 | __asm__(__USER_LABEL_PREFIX__ "fgets"); |
| 12 | __fortify_fgets(char *s, int n, FILE *fp) | 19 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 20 | char *fgets(char *s, int n, FILE *fp) | ||
| 13 | { | 21 | { |
| 14 | size_t bos = __builtin_object_size(s, 0); | 22 | size_t bos = __builtin_object_size(s, 0); |
| 15 | 23 | ||
| 16 | if ((size_t)n > bos) | 24 | if ((size_t)n > bos) |
| 17 | __builtin_trap(); | 25 | __builtin_trap(); |
| 18 | return fgets(s, n, fp); | 26 | return __fgets_orig(s, n, fp); |
| 19 | } | 27 | } |
| 20 | 28 | ||
| 21 | static inline __attribute__ ((always_inline)) | 29 | extern size_t __fread_orig(void *, size_t, size_t, FILE *) |
| 22 | size_t | 30 | __asm__(__USER_LABEL_PREFIX__ "fread"); |
| 23 | __fortify_fread(void *dst, size_t n, size_t nmemb, FILE *fp) | 31 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 32 | size_t fread(void *dst, size_t n, size_t nmemb, FILE *fp) | ||
| 24 | { | 33 | { |
| 25 | size_t bos = __builtin_object_size(dst, 0); | 34 | size_t bos = __builtin_object_size(dst, 0); |
| 26 | 35 | ||
| @@ -28,12 +37,13 @@ __fortify_fread(void *dst, size_t n, size_t nmemb, FILE *fp) | |||
| 28 | __builtin_trap(); | 37 | __builtin_trap(); |
| 29 | if (n * nmemb > bos) | 38 | if (n * nmemb > bos) |
| 30 | __builtin_trap(); | 39 | __builtin_trap(); |
| 31 | return fread(dst, n, nmemb, fp); | 40 | return __fread_orig(dst, n, nmemb, fp); |
| 32 | } | 41 | } |
| 33 | 42 | ||
| 34 | static inline __attribute__ ((always_inline)) | 43 | extern size_t __fwrite_orig(const void *, size_t, size_t, FILE *) |
| 35 | size_t | 44 | __asm__(__USER_LABEL_PREFIX__ "fwrite"); |
| 36 | __fortify_fwrite(const void *dst, size_t n, size_t nmemb, FILE *fp) | 45 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 46 | size_t fwrite(const void *dst, size_t n, size_t nmemb, FILE *fp) | ||
| 37 | { | 47 | { |
| 38 | size_t bos = __builtin_object_size(dst, 0); | 48 | size_t bos = __builtin_object_size(dst, 0); |
| 39 | 49 | ||
| @@ -41,48 +51,39 @@ __fortify_fwrite(const void *dst, size_t n, size_t nmemb, FILE *fp) | |||
| 41 | __builtin_trap(); | 51 | __builtin_trap(); |
| 42 | if (n * nmemb > bos) | 52 | if (n * nmemb > bos) |
| 43 | __builtin_trap(); | 53 | __builtin_trap(); |
| 44 | return fwrite(dst, n, nmemb, fp); | 54 | return __fwrite_orig(dst, n, nmemb, fp); |
| 45 | } | 55 | } |
| 46 | 56 | ||
| 47 | static inline __attribute__ ((always_inline)) | 57 | extern int __vsprintf_orig(char *, const char *, __builtin_va_list) |
| 48 | int | 58 | __asm__(__USER_LABEL_PREFIX__ "vsprintf"); |
| 49 | __fortify_vsprintf(char *s, const char *fmt, __builtin_va_list ap) | 59 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 60 | int vsprintf(char *s, const char *fmt, __builtin_va_list ap) | ||
| 50 | { | 61 | { |
| 51 | size_t bos = __builtin_object_size(s, 0); | 62 | size_t bos = __builtin_object_size(s, 0); |
| 52 | int r; | 63 | int r; |
| 53 | 64 | ||
| 54 | if (bos != (size_t)-1) { | 65 | if (bos != (size_t)-1) { |
| 55 | r = vsnprintf(s, bos, fmt, ap); | 66 | r = __vsnprintf_orig(s, bos, fmt, ap); |
| 56 | if (r != -1 && (size_t)r >= bos) | 67 | if (r != -1 && (size_t)r >= bos) |
| 57 | __builtin_trap(); | 68 | __builtin_trap(); |
| 58 | } else { | 69 | } else { |
| 59 | r = vsprintf(s, fmt, ap); | 70 | r = __vsprintf_orig(s, fmt, ap); |
| 60 | } | 71 | } |
| 61 | return r; | 72 | return r; |
| 62 | } | 73 | } |
| 63 | 74 | ||
| 64 | static inline __attribute__ ((always_inline)) | 75 | extern int __vsnprintf_orig(char *, size_t, const char *, __builtin_va_list) |
| 65 | int | 76 | __asm__(__USER_LABEL_PREFIX__ "vsnprintf"); |
| 66 | __fortify_vsnprintf(char *s, size_t n, const char *fmt, __builtin_va_list ap) | 77 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 78 | int vsnprintf(char *s, size_t n, const char *fmt, __builtin_va_list ap) | ||
| 67 | { | 79 | { |
| 68 | size_t bos = __builtin_object_size(s, 0); | 80 | size_t bos = __builtin_object_size(s, 0); |
| 69 | 81 | ||
| 70 | if (n > bos) | 82 | if (n > bos) |
| 71 | __builtin_trap(); | 83 | __builtin_trap(); |
| 72 | return vsnprintf(s, n, fmt, ap); | 84 | return __vsnprintf_orig(s, n, fmt, ap); |
| 73 | } | 85 | } |
| 74 | 86 | ||
| 75 | #undef fgets | ||
| 76 | #define fgets(s, n, fp) __fortify_fgets(s, n, fp) | ||
| 77 | #undef fread | ||
| 78 | #define fread(dst, n, nmemb, fp) __fortify_fread(dst, n, nmemb, fp) | ||
| 79 | #undef fwrite | ||
| 80 | #define fwrite(dst, n, nmemb, fp) __fortify_fwrite(dst, n, nmemb, fp) | ||
| 81 | #undef vsprintf | ||
| 82 | #define vsprintf(s, fmt, ap) __fortify_vsprintf(s, fmt, ap) | ||
| 83 | #undef vsnprintf | ||
| 84 | #define vsnprintf(s, n, fmt, ap) __fortify_vsnprintf(s, n, fmt, ap) | ||
| 85 | |||
| 86 | #undef snprintf | 87 | #undef snprintf |
| 87 | #define snprintf(s, n, fmt, ...) ({ \ | 88 | #define snprintf(s, n, fmt, ...) ({ \ |
| 88 | size_t _n = n; \ | 89 | size_t _n = n; \ |
diff --git a/include/stdlib.h b/include/stdlib.h index 4aff9d9..f4a026b 100644 --- a/include/stdlib.h +++ b/include/stdlib.h | |||
| @@ -12,9 +12,11 @@ | |||
| 12 | #ifndef __cplusplus | 12 | #ifndef __cplusplus |
| 13 | 13 | ||
| 14 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | 14 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) |
| 15 | static inline __attribute__ ((always_inline)) | 15 | #undef realpath |
| 16 | char * | 16 | extern char *__realpath_orig(const char *, char *) |
| 17 | __fortify_realpath(const char *path, char *resolved) | 17 | __asm__(__USER_LABEL_PREFIX__ "realpath"); |
| 18 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) | ||
| 19 | char *realpath(const char *path, char *resolved) | ||
| 18 | { | 20 | { |
| 19 | size_t bos; | 21 | size_t bos; |
| 20 | 22 | ||
| @@ -27,11 +29,8 @@ __fortify_realpath(const char *path, char *resolved) | |||
| 27 | __builtin_trap(); | 29 | __builtin_trap(); |
| 28 | #endif | 30 | #endif |
| 29 | } | 31 | } |
| 30 | return realpath(path, resolved); | 32 | return __realpath_orig(path, resolved); |
| 31 | } | 33 | } |
| 32 | |||
| 33 | #undef realpath | ||
| 34 | #define realpath(path, resolved) __fortify_realpath(path, resolved) | ||
| 35 | #endif | 34 | #endif |
| 36 | 35 | ||
| 37 | #endif | 36 | #endif |
diff --git a/include/string.h b/include/string.h index 65df3a1..02e931e 100644 --- a/include/string.h +++ b/include/string.h | |||
| @@ -6,10 +6,20 @@ | |||
| 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 | #ifndef __cplusplus | 8 | #ifndef __cplusplus |
| 9 | #undef memcpy | ||
| 10 | #undef memmove | ||
| 11 | #undef memset | ||
| 12 | #undef stpcpy | ||
| 13 | #undef stpncpy | ||
| 14 | #undef strcat | ||
| 15 | #undef strcpy | ||
| 16 | #undef strncat | ||
| 17 | #undef strncpy | ||
| 9 | 18 | ||
| 10 | static inline __attribute__ ((always_inline)) | 19 | extern void *__memcpy_orig(void *, const void *, size_t) |
| 11 | void * | 20 | __asm__(__USER_LABEL_PREFIX__ "memcpy"); |
| 12 | __fortify_memcpy(void *dest, const void *src, size_t n) | 21 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 22 | void *memcpy(void *dest, const void *src, size_t n) | ||
| 13 | { | 23 | { |
| 14 | size_t bos = __builtin_object_size(dest, 0); | 24 | size_t bos = __builtin_object_size(dest, 0); |
| 15 | char *d = dest; | 25 | char *d = dest; |
| @@ -22,78 +32,85 @@ __fortify_memcpy(void *dest, const void *src, size_t n) | |||
| 22 | __builtin_trap(); | 32 | __builtin_trap(); |
| 23 | if (n > bos) | 33 | if (n > bos) |
| 24 | __builtin_trap(); | 34 | __builtin_trap(); |
| 25 | return memcpy(dest, src, n); | 35 | return __memcpy_orig(dest, src, n); |
| 26 | } | 36 | } |
| 27 | 37 | ||
| 28 | static inline __attribute__ ((always_inline)) | 38 | extern void *__memmove_orig(void *, const void *, size_t) |
| 29 | void * | 39 | __asm__(__USER_LABEL_PREFIX__ "memmove"); |
| 30 | __fortify_memmove(void *dest, const void *src, size_t n) | 40 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 41 | void *memmove(void *dest, const void *src, size_t n) | ||
| 31 | { | 42 | { |
| 32 | size_t bos = __builtin_object_size(dest, 0); | 43 | size_t bos = __builtin_object_size(dest, 0); |
| 33 | 44 | ||
| 34 | if (n > bos) | 45 | if (n > bos) |
| 35 | __builtin_trap(); | 46 | __builtin_trap(); |
| 36 | return memmove(dest, src, n); | 47 | return __memmove_orig(dest, src, n); |
| 37 | } | 48 | } |
| 38 | 49 | ||
| 39 | static inline __attribute__ ((always_inline)) | 50 | extern void *__memset_orig(void *, int, size_t) |
| 40 | void * | 51 | __asm__(__USER_LABEL_PREFIX__ "memset"); |
| 41 | __fortify_memset(void *dest, int c, size_t n) | 52 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 53 | void *memset(void *dest, int c, size_t n) | ||
| 42 | { | 54 | { |
| 43 | size_t bos = __builtin_object_size(dest, 0); | 55 | size_t bos = __builtin_object_size(dest, 0); |
| 44 | 56 | ||
| 45 | if (n > bos) | 57 | if (n > bos) |
| 46 | __builtin_trap(); | 58 | __builtin_trap(); |
| 47 | return memset(dest, c, n); | 59 | return __memset_orig(dest, c, n); |
| 48 | } | 60 | } |
| 49 | 61 | ||
| 50 | static inline __attribute__ ((always_inline)) | 62 | extern char *__stpcpy_orig(char *, const char *) |
| 51 | char * | 63 | __asm__(__USER_LABEL_PREFIX__ "stpcpy"); |
| 52 | __fortify_stpcpy(char *dest, const char *src) | 64 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 65 | char *stpcpy(char *dest, const char *src) | ||
| 53 | { | 66 | { |
| 54 | size_t bos = __builtin_object_size(dest, 0); | 67 | size_t bos = __builtin_object_size(dest, 0); |
| 55 | 68 | ||
| 56 | if (strlen(src) + 1 > bos) | 69 | if (strlen(src) + 1 > bos) |
| 57 | __builtin_trap(); | 70 | __builtin_trap(); |
| 58 | return stpcpy(dest, src); | 71 | return __stpcpy_orig(dest, src); |
| 59 | } | 72 | } |
| 60 | 73 | ||
| 61 | static inline __attribute__ ((always_inline)) | 74 | extern char *__stpncpy_orig(char *, const char *, size_t) |
| 62 | char * | 75 | __asm__(__USER_LABEL_PREFIX__ "stpncpy"); |
| 63 | __fortify_stpncpy(char *dest, const char *src, size_t n) | 76 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 77 | char *stpncpy(char *dest, const char *src, size_t n) | ||
| 64 | { | 78 | { |
| 65 | size_t bos = __builtin_object_size(dest, 0); | 79 | size_t bos = __builtin_object_size(dest, 0); |
| 66 | 80 | ||
| 67 | if (n > bos) | 81 | if (n > bos) |
| 68 | __builtin_trap(); | 82 | __builtin_trap(); |
| 69 | return stpncpy(dest, src, n); | 83 | return __stpncpy_orig(dest, src, n); |
| 70 | } | 84 | } |
| 71 | 85 | ||
| 72 | static inline __attribute__ ((always_inline)) | 86 | extern char *__strcat_orig(char *, const char *) |
| 73 | char * | 87 | __asm__(__USER_LABEL_PREFIX__ "strcat"); |
| 74 | __fortify_strcat(char *dest, const char *src) | 88 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 89 | char *strcat(char *dest, const char *src) | ||
| 75 | { | 90 | { |
| 76 | size_t bos = __builtin_object_size(dest, 0); | 91 | size_t bos = __builtin_object_size(dest, 0); |
| 77 | 92 | ||
| 78 | if (strlen(src) + strlen(dest) + 1 > bos) | 93 | if (strlen(src) + strlen(dest) + 1 > bos) |
| 79 | __builtin_trap(); | 94 | __builtin_trap(); |
| 80 | return strcat(dest, src); | 95 | return __strcat_orig(dest, src); |
| 81 | } | 96 | } |
| 82 | 97 | ||
| 83 | static inline __attribute__ ((always_inline)) | 98 | extern char *__strcpy_orig(char *, const char *) |
| 84 | char * | 99 | __asm__(__USER_LABEL_PREFIX__ "strcpy"); |
| 85 | __fortify_strcpy(char *dest, const char *src) | 100 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 101 | char *strcpy(char *dest, const char *src) | ||
| 86 | { | 102 | { |
| 87 | size_t bos = __builtin_object_size(dest, 0); | 103 | size_t bos = __builtin_object_size(dest, 0); |
| 88 | 104 | ||
| 89 | if (strlen(src) + 1 > bos) | 105 | if (strlen(src) + 1 > bos) |
| 90 | __builtin_trap(); | 106 | __builtin_trap(); |
| 91 | return strcpy(dest, src); | 107 | return __strcpy_orig(dest, src); |
| 92 | } | 108 | } |
| 93 | 109 | ||
| 94 | static inline __attribute__ ((always_inline)) | 110 | extern char *__strncat_orig(char *, const char *, size_t) |
| 95 | char * | 111 | __asm__(__USER_LABEL_PREFIX__ "strncat"); |
| 96 | __fortify_strncat(char *dest, const char *src, size_t n) | 112 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 113 | char *strncat(char *dest, const char *src, size_t n) | ||
| 97 | { | 114 | { |
| 98 | size_t bos = __builtin_object_size(dest, 0); | 115 | size_t bos = __builtin_object_size(dest, 0); |
| 99 | size_t slen, dlen; | 116 | size_t slen, dlen; |
| @@ -106,88 +123,64 @@ __fortify_strncat(char *dest, const char *src, size_t n) | |||
| 106 | if (slen + dlen + 1 > bos) | 123 | if (slen + dlen + 1 > bos) |
| 107 | __builtin_trap(); | 124 | __builtin_trap(); |
| 108 | } | 125 | } |
| 109 | return strncat(dest, src, n); | 126 | return __strncat_orig(dest, src, n); |
| 110 | } | 127 | } |
| 111 | 128 | ||
| 112 | static inline __attribute__ ((always_inline)) | 129 | extern char *__strncpy_orig(char *, const char *, size_t) |
| 113 | char * | 130 | __asm__(__USER_LABEL_PREFIX__ "strncpy"); |
| 114 | __fortify_strncpy(char *dest, const char *src, size_t n) | 131 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 132 | char *strncpy(char *dest, const char *src, size_t n) | ||
| 115 | { | 133 | { |
| 116 | size_t bos = __builtin_object_size(dest, 0); | 134 | size_t bos = __builtin_object_size(dest, 0); |
| 117 | 135 | ||
| 118 | if (n > bos) | 136 | if (n > bos) |
| 119 | __builtin_trap(); | 137 | __builtin_trap(); |
| 120 | return strncpy(dest, src, n); | 138 | return __strncpy_orig(dest, src, n); |
| 121 | } | 139 | } |
| 122 | 140 | ||
| 123 | #ifdef _GNU_SOURCE | 141 | #ifdef _GNU_SOURCE |
| 124 | static inline __attribute__ ((always_inline)) | 142 | #undef mempcpy |
| 125 | void * | 143 | extern void *__mempcpy_orig(void *, const void *, size_t n) |
| 126 | __fortify_mempcpy(void *dest, const void *src, size_t n) | 144 | __asm__(__USER_LABEL_PREFIX__ "mempcpy"); |
| 145 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) | ||
| 146 | void *mempcpy(void *dest, const void *src, size_t n) | ||
| 127 | { | 147 | { |
| 128 | size_t bos = __builtin_object_size(dest, 0); | 148 | size_t bos = __builtin_object_size(dest, 0); |
| 129 | 149 | ||
| 130 | if (n > bos) | 150 | if (n > bos) |
| 131 | __builtin_trap(); | 151 | __builtin_trap(); |
| 132 | return mempcpy(dest, src, n); | 152 | return __mempcpy_orig(dest, src, n); |
| 133 | } | 153 | } |
| 134 | #endif | 154 | #endif |
| 135 | 155 | ||
| 136 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | 156 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) |
| 137 | static inline __attribute__ ((always_inline)) | 157 | #undef strlcat |
| 138 | size_t | 158 | #undef strlcpy |
| 139 | __fortify_strlcat(char *dest, const char *src, size_t n) | 159 | extern size_t __strlcat_orig(char *, const char *, size_t) |
| 160 | __asm__(__USER_LABEL_PREFIX__ "strlcat"); | ||
| 161 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) | ||
| 162 | size_t strlcat(char *dest, const char *src, size_t n) | ||
| 140 | { | 163 | { |
| 141 | size_t bos = __builtin_object_size(dest, 0); | 164 | size_t bos = __builtin_object_size(dest, 0); |
| 142 | 165 | ||
| 143 | if (n > bos) | 166 | if (n > bos) |
| 144 | __builtin_trap(); | 167 | __builtin_trap(); |
| 145 | return strlcat(dest, src, n); | 168 | return __strlcat_orig(dest, src, n); |
| 146 | } | 169 | } |
| 147 | 170 | ||
| 148 | static inline __attribute__ ((always_inline)) | 171 | extern size_t __strlcpy_orig(char *, const char *, size_t) |
| 149 | size_t | 172 | __asm__(__USER_LABEL_PREFIX__ "strlcpy"); |
| 150 | __fortify_strlcpy(char *dest, const char *src, size_t n) | 173 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 174 | size_t strlcpy(char *dest, const char *src, size_t n) | ||
| 151 | { | 175 | { |
| 152 | size_t bos = __builtin_object_size(dest, 0); | 176 | size_t bos = __builtin_object_size(dest, 0); |
| 153 | 177 | ||
| 154 | if (n > bos) | 178 | if (n > bos) |
| 155 | __builtin_trap(); | 179 | __builtin_trap(); |
| 156 | return strlcpy(dest, src, n); | 180 | return __strlcpy_orig(dest, src, n); |
| 157 | } | 181 | } |
| 158 | #endif | 182 | #endif |
| 159 | 183 | ||
| 160 | #undef memcpy | ||
| 161 | #define memcpy(dest, src, n) __fortify_memcpy(dest, src, n) | ||
| 162 | #undef memmove | ||
| 163 | #define memmove(dest, src, n) __fortify_memmove(dest, src, n) | ||
| 164 | #undef memset | ||
| 165 | #define memset(dest, src, n) __fortify_memset(dest, src, n) | ||
| 166 | #undef stpcpy | ||
| 167 | #define stpcpy(dest, src) __fortify_stpcpy(dest, src) | ||
| 168 | #undef stpncpy | ||
| 169 | #define stpncpy(dest, src, n) __fortify_stpncpy(dest, src, n) | ||
| 170 | #undef strcat | ||
| 171 | #define strcat(dest, src) __fortify_strcat(dest, src) | ||
| 172 | #undef strcpy | ||
| 173 | #define strcpy(dest, src) __fortify_strcpy(dest, src) | ||
| 174 | #undef strncat | ||
| 175 | #define strncat(dest, src, n) __fortify_strncat(dest, src, n) | ||
| 176 | #undef strncpy | ||
| 177 | #define strncpy(dest, src, n) __fortify_strncpy(dest, src, n) | ||
| 178 | |||
| 179 | #ifdef _GNU_SOURCE | ||
| 180 | #undef mempcpy | ||
| 181 | #define mempcpy(dest, src, n) __fortify_mempcpy(dest, src, n) | ||
| 182 | #endif | ||
| 183 | |||
| 184 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 185 | #undef strlcat | ||
| 186 | #define strlcat(dest, src, n) __fortify_strlcat(dest, src, n) | ||
| 187 | #undef strlcpy | ||
| 188 | #define strlcpy(dest, src, n) __fortify_strlcpy(dest, src, n) | ||
| 189 | #endif | ||
| 190 | |||
| 191 | #endif | 184 | #endif |
| 192 | 185 | ||
| 193 | #endif | 186 | #endif |
diff --git a/include/strings.h b/include/strings.h index d7118f3..1adbf51 100644 --- a/include/strings.h +++ b/include/strings.h | |||
| @@ -10,32 +10,31 @@ | |||
| 10 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_POSIX_SOURCE) \ | 10 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_POSIX_SOURCE) \ |
| 11 | || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE+0 < 200809L) \ | 11 | || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE+0 < 200809L) \ |
| 12 | || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) | 12 | || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) |
| 13 | static inline __attribute__ ((always_inline)) | 13 | #undef bcopy |
| 14 | void | 14 | #undef bzero |
| 15 | __fortify_bcopy(const void *src, void *dest, size_t n) | 15 | extern void __bcopy_orig(const void *, void *, size_t) |
| 16 | __asm__(__USER_LABEL_PREFIX__ "bcopy"); | ||
| 17 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) | ||
| 18 | void bcopy(const void *src, void *dest, size_t n) | ||
| 16 | { | 19 | { |
| 17 | size_t bos = __builtin_object_size(dest, 0); | 20 | size_t bos = __builtin_object_size(dest, 0); |
| 18 | 21 | ||
| 19 | if (n > bos) | 22 | if (n > bos) |
| 20 | __builtin_trap(); | 23 | __builtin_trap(); |
| 21 | return bcopy(src, dest, n); | 24 | return __bcopy_orig(src, dest, n); |
| 22 | } | 25 | } |
| 23 | 26 | ||
| 24 | static inline __attribute__ ((always_inline)) | 27 | extern void __bzero_orig(void *, size_t) |
| 25 | void | 28 | __asm__(__USER_LABEL_PREFIX__ "bzero"); |
| 26 | __fortify_bzero(void *src, size_t n) | 29 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 30 | void bzero(void *src, size_t n) | ||
| 27 | { | 31 | { |
| 28 | size_t bos = __builtin_object_size(src, 0); | 32 | size_t bos = __builtin_object_size(src, 0); |
| 29 | 33 | ||
| 30 | if (n > bos) | 34 | if (n > bos) |
| 31 | __builtin_trap(); | 35 | __builtin_trap(); |
| 32 | return bzero(src, n); | 36 | return __bzero_orig(src, n); |
| 33 | } | 37 | } |
| 34 | |||
| 35 | #undef bcopy | ||
| 36 | #define bcopy(src, dest, n) __fortify_bcopy(src, dest, n) | ||
| 37 | #undef bzero | ||
| 38 | #define bzero(src, n) __fortify_bzero(src, n) | ||
| 39 | #endif | 38 | #endif |
| 40 | 39 | ||
| 41 | #endif | 40 | #endif |
diff --git a/include/sys/select.h b/include/sys/select.h index c73613d..7838041 100644 --- a/include/sys/select.h +++ b/include/sys/select.h | |||
| @@ -7,9 +7,8 @@ | |||
| 7 | 7 | ||
| 8 | #ifndef __cplusplus | 8 | #ifndef __cplusplus |
| 9 | 9 | ||
| 10 | static inline __attribute__ ((always_inline)) | 10 | static __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 11 | int | 11 | int __fortify_FD_CLR(int fd, fd_set *set) |
| 12 | __fortify_FD_CLR(int fd, fd_set *set) | ||
| 13 | { | 12 | { |
| 14 | size_t bos = __builtin_object_size(set, 0); | 13 | size_t bos = __builtin_object_size(set, 0); |
| 15 | 14 | ||
| @@ -18,9 +17,8 @@ __fortify_FD_CLR(int fd, fd_set *set) | |||
| 18 | return FD_CLR(fd, set); | 17 | return FD_CLR(fd, set); |
| 19 | } | 18 | } |
| 20 | 19 | ||
| 21 | static inline __attribute__ ((always_inline)) | 20 | static __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 22 | int | 21 | int __fortify_FD_SET(int fd, fd_set *set) |
| 23 | __fortify_FD_SET(int fd, fd_set *set) | ||
| 24 | { | 22 | { |
| 25 | size_t bos = __builtin_object_size(set, 0); | 23 | size_t bos = __builtin_object_size(set, 0); |
| 26 | 24 | ||
diff --git a/include/sys/socket.h b/include/sys/socket.h index 5e6d679..4602866 100644 --- a/include/sys/socket.h +++ b/include/sys/socket.h | |||
| @@ -6,62 +6,61 @@ | |||
| 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 | #ifndef __cplusplus | 8 | #ifndef __cplusplus |
| 9 | #undef recv | ||
| 10 | #undef recvfrom | ||
| 11 | #undef send | ||
| 12 | #undef sendto | ||
| 9 | 13 | ||
| 10 | static inline __attribute__ ((always_inline)) | 14 | extern ssize_t __recv_orig(int, void *, size_t, int) |
| 11 | ssize_t | 15 | __asm__(__USER_LABEL_PREFIX__ "recv"); |
| 12 | __fortify_recv(int sockfd, void *buf, size_t n, int flags) | 16 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 17 | ssize_t recv(int sockfd, void *buf, size_t n, int flags) | ||
| 13 | { | 18 | { |
| 14 | size_t bos = __builtin_object_size(buf, 0); | 19 | size_t bos = __builtin_object_size(buf, 0); |
| 15 | 20 | ||
| 16 | if (n > bos) | 21 | if (n > bos) |
| 17 | __builtin_trap(); | 22 | __builtin_trap(); |
| 18 | return recv(sockfd, buf, n, flags); | 23 | return __recv_orig(sockfd, buf, n, flags); |
| 19 | } | 24 | } |
| 20 | 25 | ||
| 21 | static inline __attribute__ ((always_inline)) | 26 | extern ssize_t __recvfrom_orig(int, void *, size_t, int, struct sockaddr *, socklen_t *) |
| 22 | ssize_t | 27 | __asm__(__USER_LABEL_PREFIX__ "recvfrom"); |
| 23 | __fortify_recvfrom(int sockfd, void *buf, size_t n, int flags, | 28 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 24 | struct sockaddr *sa, socklen_t *salen) | 29 | ssize_t recvfrom(int sockfd, void *buf, size_t n, int flags, |
| 30 | struct sockaddr *sa, socklen_t *salen) | ||
| 25 | { | 31 | { |
| 26 | size_t bos = __builtin_object_size(buf, 0); | 32 | size_t bos = __builtin_object_size(buf, 0); |
| 27 | 33 | ||
| 28 | if (n > bos) | 34 | if (n > bos) |
| 29 | __builtin_trap(); | 35 | __builtin_trap(); |
| 30 | return recvfrom(sockfd, buf, n, flags, sa, salen); | 36 | return __recvfrom_orig(sockfd, buf, n, flags, sa, salen); |
| 31 | } | 37 | } |
| 32 | 38 | ||
| 33 | static inline __attribute__ ((always_inline)) | 39 | extern ssize_t __send_orig(int, const void *, size_t, int) |
| 34 | ssize_t | 40 | __asm__(__USER_LABEL_PREFIX__ "send"); |
| 35 | __fortify_send(int sockfd, const void *buf, size_t n, int flags) | 41 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 42 | ssize_t send(int sockfd, const void *buf, size_t n, int flags) | ||
| 36 | { | 43 | { |
| 37 | size_t bos = __builtin_object_size(buf, 0); | 44 | size_t bos = __builtin_object_size(buf, 0); |
| 38 | 45 | ||
| 39 | if (n > bos) | 46 | if (n > bos) |
| 40 | __builtin_trap(); | 47 | __builtin_trap(); |
| 41 | return send(sockfd, buf, n, flags); | 48 | return __send_orig(sockfd, buf, n, flags); |
| 42 | } | 49 | } |
| 43 | 50 | ||
| 44 | static inline __attribute__ ((always_inline)) | 51 | extern ssize_t __sendto_orig(int, const void *, size_t, int, const struct sockaddr *, socklen_t) |
| 45 | ssize_t | 52 | __asm__(__USER_LABEL_PREFIX__ "sendto"); |
| 46 | __fortify_sendto(int sockfd, const void *buf, size_t n, int flags, | 53 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 47 | const struct sockaddr *sa, socklen_t salen) | 54 | ssize_t sendto(int sockfd, const void *buf, size_t n, int flags, |
| 55 | const struct sockaddr *sa, socklen_t salen) | ||
| 48 | { | 56 | { |
| 49 | size_t bos = __builtin_object_size(buf, 0); | 57 | size_t bos = __builtin_object_size(buf, 0); |
| 50 | 58 | ||
| 51 | if (n > bos) | 59 | if (n > bos) |
| 52 | __builtin_trap(); | 60 | __builtin_trap(); |
| 53 | return sendto(sockfd, buf, n, flags, sa, salen); | 61 | return __sendto_orig(sockfd, buf, n, flags, sa, salen); |
| 54 | } | 62 | } |
| 55 | 63 | ||
| 56 | #undef recv | ||
| 57 | #define recv(sockfd, buf, n, flags) __fortify_recv(sockfd, buf, n, flags) | ||
| 58 | #undef recvfrom | ||
| 59 | #define recvfrom(sockfd, buf, n, flags, sa, salen) __fortify_recvfrom(sockfd, buf, n, flags, sa, salen) | ||
| 60 | #undef send | ||
| 61 | #define send(sockfd, buf, n, flags) __fortify_send(sockfd, buf, n, flags) | ||
| 62 | #undef sendto | ||
| 63 | #define sendto(sockfd, buf, n, flags, sa, salen) __fortify_sendto(sockfd, buf, n, flags, sa, salen) | ||
| 64 | |||
| 65 | #endif | 64 | #endif |
| 66 | 65 | ||
| 67 | #endif | 66 | #endif |
diff --git a/include/unistd.h b/include/unistd.h index 5991155..aa4ddff 100644 --- a/include/unistd.h +++ b/include/unistd.h | |||
| @@ -6,170 +6,165 @@ | |||
| 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 | #ifndef __cplusplus | 8 | #ifndef __cplusplus |
| 9 | #undef confstr | ||
| 10 | #undef getcwd | ||
| 11 | #undef getgroups | ||
| 12 | #undef gethostname | ||
| 13 | #undef getlogin_r | ||
| 14 | #undef pread | ||
| 15 | #undef read | ||
| 16 | #undef readlink | ||
| 17 | #undef readlinkat | ||
| 18 | #undef ttyname_r | ||
| 19 | #undef write | ||
| 9 | 20 | ||
| 10 | static inline __attribute__ ((always_inline)) | 21 | extern size_t __confstr_orig(int, char *, size_t) |
| 11 | size_t | 22 | __asm__(__USER_LABEL_PREFIX__ "confstr"); |
| 12 | __fortify_confstr(int name, char *buf, size_t len) | 23 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 24 | size_t confstr(int name, char *buf, size_t len) | ||
| 13 | { | 25 | { |
| 14 | size_t bos = __builtin_object_size(buf, 0); | 26 | size_t bos = __builtin_object_size(buf, 0); |
| 15 | 27 | ||
| 16 | if (len > bos) | 28 | if (len > bos) |
| 17 | __builtin_trap(); | 29 | __builtin_trap(); |
| 18 | return confstr(name, buf, len); | 30 | return __confstr_orig(name, buf, len); |
| 19 | } | 31 | } |
| 20 | 32 | ||
| 21 | static inline __attribute__ ((always_inline)) | 33 | extern char *__getcwd_orig(char *, size_t) |
| 22 | char * | 34 | __asm__(__USER_LABEL_PREFIX__ "getcwd"); |
| 23 | __fortify_getcwd(char *buf, size_t len) | 35 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 36 | char *getcwd(char *buf, size_t len) | ||
| 24 | { | 37 | { |
| 25 | size_t bos = __builtin_object_size(buf, 0); | 38 | size_t bos = __builtin_object_size(buf, 0); |
| 26 | 39 | ||
| 27 | if (len > bos) | 40 | if (len > bos) |
| 28 | __builtin_trap(); | 41 | __builtin_trap(); |
| 29 | return getcwd(buf, len); | 42 | return __getcwd_orig(buf, len); |
| 30 | } | 43 | } |
| 31 | 44 | ||
| 32 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | 45 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) |
| 33 | static inline __attribute__ ((always_inline)) | 46 | #undef getdomainname |
| 34 | int | 47 | extern int __getdomainname_orig(char *, size_t) |
| 35 | __fortify_getdomainname(char *name, size_t len) | 48 | __asm__(__USER_LABEL_PREFIX__ "getdomainname"); |
| 49 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) | ||
| 50 | int getdomainname(char *name, size_t len) | ||
| 36 | { | 51 | { |
| 37 | size_t bos = __builtin_object_size(name, 0); | 52 | size_t bos = __builtin_object_size(name, 0); |
| 38 | 53 | ||
| 39 | if (len > bos) | 54 | if (len > bos) |
| 40 | __builtin_trap(); | 55 | __builtin_trap(); |
| 41 | return getdomainname(name, len); | 56 | return __getdomainname_orig(name, len); |
| 42 | } | 57 | } |
| 43 | #endif | 58 | #endif |
| 44 | 59 | ||
| 45 | static inline __attribute__ ((always_inline)) | 60 | extern int __getgroups_orig(int, gid_t *) |
| 46 | int | 61 | __asm__(__USER_LABEL_PREFIX__ "getgroups"); |
| 47 | __fortify_getgroups(int len, gid_t *set) | 62 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 63 | int getgroups(int len, gid_t *set) | ||
| 48 | { | 64 | { |
| 49 | size_t bos = __builtin_object_size(set, 0); | 65 | size_t bos = __builtin_object_size(set, 0); |
| 50 | 66 | ||
| 51 | if (len > bos / sizeof(gid_t)) | 67 | if (len > bos / sizeof(gid_t)) |
| 52 | __builtin_trap(); | 68 | __builtin_trap(); |
| 53 | return getgroups(len, set); | 69 | return __getgroups_orig(len, set); |
| 54 | } | 70 | } |
| 55 | 71 | ||
| 56 | static inline __attribute__ ((always_inline)) | 72 | extern int __gethostname_orig(char *, size_t) |
| 57 | int | 73 | __asm__(__USER_LABEL_PREFIX__ "gethostname"); |
| 58 | __fortify_gethostname(char *name, size_t len) | 74 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 75 | int gethostname(char *name, size_t len) | ||
| 59 | { | 76 | { |
| 60 | size_t bos = __builtin_object_size(name, 0); | 77 | size_t bos = __builtin_object_size(name, 0); |
| 61 | 78 | ||
| 62 | if (len > bos) | 79 | if (len > bos) |
| 63 | __builtin_trap(); | 80 | __builtin_trap(); |
| 64 | return gethostname(name, len); | 81 | return __gethostname_orig(name, len); |
| 65 | } | 82 | } |
| 66 | 83 | ||
| 67 | static inline __attribute__ ((always_inline)) | 84 | extern int __getlogin_r_orig(char *, size_t) |
| 68 | int | 85 | __asm__(__USER_LABEL_PREFIX__ "getlogin_r"); |
| 69 | __fortify_getlogin_r(char *name, size_t len) | 86 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 87 | int getlogin_r(char *name, size_t len) | ||
| 70 | { | 88 | { |
| 71 | size_t bos = __builtin_object_size(name, 0); | 89 | size_t bos = __builtin_object_size(name, 0); |
| 72 | 90 | ||
| 73 | if (len > bos) | 91 | if (len > bos) |
| 74 | __builtin_trap(); | 92 | __builtin_trap(); |
| 75 | return getlogin_r(name, len); | 93 | return __getlogin_r_orig(name, len); |
| 76 | } | 94 | } |
| 77 | 95 | ||
| 78 | static inline __attribute__ ((always_inline)) | 96 | extern ssize_t __pread_orig(int, void *, size_t, off_t) |
| 79 | ssize_t | 97 | __asm__(__USER_LABEL_PREFIX__ "pread"); |
| 80 | __fortify_pread(int fd, void *buf, size_t n, off_t offset) | 98 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 99 | ssize_t pread(int fd, void *buf, size_t n, off_t offset) | ||
| 81 | { | 100 | { |
| 82 | size_t bos = __builtin_object_size(buf, 0); | 101 | size_t bos = __builtin_object_size(buf, 0); |
| 83 | 102 | ||
| 84 | if (n > bos) | 103 | if (n > bos) |
| 85 | __builtin_trap(); | 104 | __builtin_trap(); |
| 86 | return pread(fd, buf, n, offset); | 105 | return __pread_orig(fd, buf, n, offset); |
| 87 | } | 106 | } |
| 88 | 107 | ||
| 89 | static inline __attribute__ ((always_inline)) | 108 | extern ssize_t __read_orig(int, void *, size_t) |
| 90 | ssize_t | 109 | __asm__(__USER_LABEL_PREFIX__ "read"); |
| 91 | __fortify_read(int fd, void *buf, size_t n) | 110 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 111 | ssize_t read(int fd, void *buf, size_t n) | ||
| 92 | { | 112 | { |
| 93 | size_t bos = __builtin_object_size(buf, 0); | 113 | size_t bos = __builtin_object_size(buf, 0); |
| 94 | 114 | ||
| 95 | if (n > bos) | 115 | if (n > bos) |
| 96 | __builtin_trap(); | 116 | __builtin_trap(); |
| 97 | return read(fd, buf, n); | 117 | return __read_orig(fd, buf, n); |
| 98 | } | 118 | } |
| 99 | 119 | ||
| 100 | static inline __attribute__ ((always_inline)) | 120 | extern ssize_t __readlink_orig(const char *, char *, size_t) |
| 101 | ssize_t | 121 | __asm__(__USER_LABEL_PREFIX__ "readlink"); |
| 102 | __fortify_readlink(const char *path, char *buf, size_t n) | 122 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 123 | ssize_t readlink(const char *path, char *buf, size_t n) | ||
| 103 | { | 124 | { |
| 104 | size_t bos = __builtin_object_size(buf, 0); | 125 | size_t bos = __builtin_object_size(buf, 0); |
| 105 | 126 | ||
| 106 | if (n > bos) | 127 | if (n > bos) |
| 107 | __builtin_trap(); | 128 | __builtin_trap(); |
| 108 | return readlink(path, buf, n); | 129 | return __readlink_orig(path, buf, n); |
| 109 | } | 130 | } |
| 110 | 131 | ||
| 111 | static inline __attribute__ ((always_inline)) | 132 | extern ssize_t __readlinkat_orig(int, const char *, char *, size_t) |
| 112 | ssize_t | 133 | __asm__(__USER_LABEL_PREFIX__ "readlinkat"); |
| 113 | __fortify_readlinkat(int fd, const char *path, char *buf, size_t n) | 134 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 135 | ssize_t readlinkat(int fd, const char *path, char *buf, size_t n) | ||
| 114 | { | 136 | { |
| 115 | size_t bos = __builtin_object_size(buf, 0); | 137 | size_t bos = __builtin_object_size(buf, 0); |
| 116 | 138 | ||
| 117 | if (n > bos) | 139 | if (n > bos) |
| 118 | __builtin_trap(); | 140 | __builtin_trap(); |
| 119 | return readlinkat(fd, path, buf, n); | 141 | return __readlinkat_orig(fd, path, buf, n); |
| 120 | } | 142 | } |
| 121 | 143 | ||
| 122 | static inline __attribute__ ((always_inline)) | 144 | extern int __ttyname_r_orig(int, char *, size_t) |
| 123 | int | 145 | __asm__(__USER_LABEL_PREFIX__ "ttyname_r"); |
| 124 | __fortify_ttyname_r(int fd, char *name, size_t n) | 146 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 147 | int ttyname_r(int fd, char *name, size_t n) | ||
| 125 | { | 148 | { |
| 126 | size_t bos = __builtin_object_size(name, 0); | 149 | size_t bos = __builtin_object_size(name, 0); |
| 127 | 150 | ||
| 128 | if (n > bos) | 151 | if (n > bos) |
| 129 | __builtin_trap(); | 152 | __builtin_trap(); |
| 130 | return ttyname_r(fd, name, n); | 153 | return __ttyname_r_orig(fd, name, n); |
| 131 | } | 154 | } |
| 132 | 155 | ||
| 133 | static inline __attribute__ ((always_inline)) | 156 | extern ssize_t __write_orig(int, const void *, size_t) |
| 134 | ssize_t | 157 | __asm__(__USER_LABEL_PREFIX__ "write"); |
| 135 | __fortify_write(int fd, const void *buf, size_t n) | 158 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 159 | ssize_t write(int fd, const void *buf, size_t n) | ||
| 136 | { | 160 | { |
| 137 | size_t bos = __builtin_object_size(buf, 0); | 161 | size_t bos = __builtin_object_size(buf, 0); |
| 138 | 162 | ||
| 139 | if (n > bos) | 163 | if (n > bos) |
| 140 | __builtin_trap(); | 164 | __builtin_trap(); |
| 141 | return write(fd, buf, n); | 165 | return __write_orig(fd, buf, n); |
| 142 | } | 166 | } |
| 143 | 167 | ||
| 144 | #undef confstr | ||
| 145 | #define confstr(name, buf, len) __fortify_confstr(name, buf, len) | ||
| 146 | #undef getcwd | ||
| 147 | #define getcwd(buf, len) __fortify_getcwd(buf, len) | ||
| 148 | |||
| 149 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 150 | #undef getdomainname | ||
| 151 | #define getdomainname(name, len) __fortify_getdomainname(name, len) | ||
| 152 | #endif | ||
| 153 | |||
| 154 | #undef getgroups | ||
| 155 | #define getgroups(len, set) __fortify_getgroups(len, set) | ||
| 156 | #undef gethostname | ||
| 157 | #define gethostname(name, len) __fortify_gethostname(name, len) | ||
| 158 | #undef getlogin_r | ||
| 159 | #define getlogin_r(name, len) __fortify_getlogin_r(name, len) | ||
| 160 | #undef pread | ||
| 161 | #define pread(fd, buf, n, offset) __fortify_pread(fd, buf, n, offset) | ||
| 162 | #undef read | ||
| 163 | #define read(fd, buf, n) __fortify_read(fd, buf, n) | ||
| 164 | #undef readlink | ||
| 165 | #define readlink(path, buf, n) __fortify_readlink(path, buf, n) | ||
| 166 | #undef readlinkat | ||
| 167 | #define readlinkat(fd, path, buf, n) __fortify_readlinkat(fd, path, buf, n) | ||
| 168 | #undef ttyname_r | ||
| 169 | #define ttyname_r(fd, name, n) __fortify_ttyname_r(fd, name, n) | ||
| 170 | #undef write | ||
| 171 | #define write(fd, buf, n) __fortify_write(fd, buf, n) | ||
| 172 | |||
| 173 | #endif | 168 | #endif |
| 174 | 169 | ||
| 175 | #endif | 170 | #endif |
diff --git a/include/wchar.h b/include/wchar.h index 805f309..526275a 100644 --- a/include/wchar.h +++ b/include/wchar.h | |||
| @@ -7,101 +7,123 @@ | |||
| 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 | 8 | ||
| 9 | #ifndef __cplusplus | 9 | #ifndef __cplusplus |
| 10 | #undef fgetws | ||
| 11 | #undef mbsnrtowcs | ||
| 12 | #undef mbsrtowcs | ||
| 13 | #undef mbstowcs | ||
| 14 | #undef wcrtomb | ||
| 15 | #undef wcscat | ||
| 16 | #undef wcscpy | ||
| 17 | #undef wcsncat | ||
| 18 | #undef wcsncpy | ||
| 19 | #undef wcsnrtombs | ||
| 20 | #undef wcsrtombs | ||
| 21 | #undef wcstombs | ||
| 22 | #undef wctomb | ||
| 23 | #undef wmemcpy | ||
| 24 | #undef wmemmove | ||
| 25 | #undef wmemset | ||
| 10 | 26 | ||
| 11 | static inline __attribute__ ((always_inline)) | 27 | extern wchar_t *__fgetws_orig(wchar_t *, int, FILE *) |
| 12 | wchar_t * | 28 | __asm__(__USER_LABEL_PREFIX__ "fgetws"); |
| 13 | __fortify_fgetws(wchar_t *s, int n, FILE *fp) | 29 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 30 | wchar_t *fgetws(wchar_t *s, int n, FILE *fp) | ||
| 14 | { | 31 | { |
| 15 | size_t bos = __builtin_object_size(s, 0); | 32 | size_t bos = __builtin_object_size(s, 0); |
| 16 | 33 | ||
| 17 | if ((size_t)n > bos / sizeof(wchar_t)) | 34 | if ((size_t)n > bos / sizeof(wchar_t)) |
| 18 | __builtin_trap(); | 35 | __builtin_trap(); |
| 19 | return fgetws(s, n, fp); | 36 | return __fgetws_orig(s, n, fp); |
| 20 | } | 37 | } |
| 21 | 38 | ||
| 22 | static inline __attribute__ ((always_inline)) | 39 | extern size_t __mbsnrtowcs(wchar_t *, const char **, size_t, size_t, mbstate_t *) |
| 23 | size_t | 40 | __asm__(__USER_LABEL_PREFIX__ "mbsnrtowcs"); |
| 24 | __fortify_mbsnrtowcs(wchar_t *d, const char **s, size_t n, | 41 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 25 | size_t wn, mbstate_t *st) | 42 | size_t mbsnrtowcs(wchar_t *d, const char **s, size_t n, size_t wn, mbstate_t *st) |
| 26 | { | 43 | { |
| 27 | size_t bos = __builtin_object_size(d, 0); | 44 | size_t bos = __builtin_object_size(d, 0); |
| 28 | size_t r; | 45 | size_t r; |
| 29 | 46 | ||
| 30 | if (wn > n / sizeof(wchar_t)) { | 47 | if (wn > n / sizeof(wchar_t)) { |
| 31 | bos /= sizeof(wchar_t); | 48 | bos /= sizeof(wchar_t); |
| 32 | r = mbsnrtowcs(d, s, n, wn > bos ? bos : wn, st); | 49 | r = __mbsnrtowcs_orig(d, s, n, wn > bos ? bos : wn, st); |
| 33 | if (bos < wn && d && *s && r != (size_t)-1) | 50 | if (bos < wn && d && *s && r != (size_t)-1) |
| 34 | __builtin_trap(); | 51 | __builtin_trap(); |
| 35 | } else { | 52 | } else { |
| 36 | r = mbsnrtowcs(d, s, n > bos ? bos : n, wn, st); | 53 | r = __mbsnrtowcs_orig(d, s, n > bos ? bos : n, wn, st); |
| 37 | if (bos < n && d && *s && r != (size_t)-1) | 54 | if (bos < n && d && *s && r != (size_t)-1) |
| 38 | __builtin_trap(); | 55 | __builtin_trap(); |
| 39 | } | 56 | } |
| 40 | return r; | 57 | return r; |
| 41 | } | 58 | } |
| 42 | 59 | ||
| 43 | static inline __attribute__ ((always_inline)) | 60 | extern size_t __mbsrtowcs_orig(wchar_t *, const char **, size_t, mbstate_t *) |
| 44 | size_t | 61 | __asm__(__USER_LABEL_PREFIX__ "mbsrtowcs"); |
| 45 | __fortify_mbsrtowcs(wchar_t *d, const char **s, | 62 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 46 | size_t wn, mbstate_t *st) | 63 | size_t mbsrtowcs(wchar_t *d, const char **s, size_t wn, mbstate_t *st) |
| 47 | { | 64 | { |
| 48 | size_t bos = __builtin_object_size(d, 0); | 65 | size_t bos = __builtin_object_size(d, 0); |
| 49 | size_t r; | 66 | size_t r; |
| 50 | 67 | ||
| 51 | bos /= sizeof(wchar_t); | 68 | bos /= sizeof(wchar_t); |
| 52 | r = mbsrtowcs(d, s, wn > bos ? bos : wn, st); | 69 | r = __mbsrtowcs_orig(d, s, wn > bos ? bos : wn, st); |
| 53 | if (bos < wn && d && *s && r != (size_t)-1) | 70 | if (bos < wn && d && *s && r != (size_t)-1) |
| 54 | __builtin_trap(); | 71 | __builtin_trap(); |
| 55 | return r; | 72 | return r; |
| 56 | } | 73 | } |
| 57 | 74 | ||
| 58 | static inline __attribute__ ((always_inline)) | 75 | extern size_t __mbstowcs_orig(wchar_t *, const char *, size_t) |
| 59 | size_t | 76 | __asm__(__USER_LABEL_PREFIX__ "mbstowcs"); |
| 60 | __fortify_mbstowcs(wchar_t *ws, const char *s, size_t wn) | 77 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 78 | size_t mbstowcs(wchar_t *ws, const char *s, size_t wn) | ||
| 61 | { | 79 | { |
| 62 | size_t bos = __builtin_object_size(ws, 0); | 80 | size_t bos = __builtin_object_size(ws, 0); |
| 63 | 81 | ||
| 64 | if (ws && wn > bos / sizeof(wchar_t)) | 82 | if (ws && wn > bos / sizeof(wchar_t)) |
| 65 | __builtin_trap(); | 83 | __builtin_trap(); |
| 66 | return mbstowcs(ws, s, wn); | 84 | return __mbstowcs_orig(ws, s, wn); |
| 67 | } | 85 | } |
| 68 | 86 | ||
| 69 | static inline __attribute__ ((always_inline)) | 87 | extern size_t __wcrtomb_orig(char *, wchar_t, mbstate_t *) |
| 70 | size_t | 88 | __asm__(__USER_LABEL_PREFIX__ "wcrtomb"); |
| 71 | __fortify_wcrtomb(char *s, wchar_t wc, mbstate_t *st) | 89 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 90 | size_t wcrtomb(char *s, wchar_t wc, mbstate_t *st) | ||
| 72 | { | 91 | { |
| 73 | size_t bos = __builtin_object_size(s, 0); | 92 | size_t bos = __builtin_object_size(s, 0); |
| 74 | 93 | ||
| 75 | if (s && MB_CUR_MAX > bos) | 94 | if (s && MB_CUR_MAX > bos) |
| 76 | __builtin_trap(); | 95 | __builtin_trap(); |
| 77 | return wcrtomb(s, wc, st); | 96 | return __wcrtomb_orig(s, wc, st); |
| 78 | } | 97 | } |
| 79 | 98 | ||
| 80 | static inline __attribute__ ((always_inline)) | 99 | extern wchar_t *__wcscat_orig(wchar_t *, const wchar_t *) |
| 81 | wchar_t * | 100 | __asm__(__USER_LABEL_PREFIX__ "wcscat"); |
| 82 | __fortify_wcscat(wchar_t *d, const wchar_t *s) | 101 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 102 | wchar_t *wcscat(wchar_t *d, const wchar_t *s) | ||
| 83 | { | 103 | { |
| 84 | size_t bos = __builtin_object_size(d, 0); | 104 | size_t bos = __builtin_object_size(d, 0); |
| 85 | 105 | ||
| 86 | if (wcslen(s) + wcslen(d) + 1 > bos / sizeof(wchar_t)) | 106 | if (wcslen(s) + wcslen(d) + 1 > bos / sizeof(wchar_t)) |
| 87 | __builtin_trap(); | 107 | __builtin_trap(); |
| 88 | return wcscat(d, s); | 108 | return __wcscat_orig(d, s); |
| 89 | } | 109 | } |
| 90 | 110 | ||
| 91 | static inline __attribute__ ((always_inline)) | 111 | extern wchar_t *__wcscpy_orig(wchar_t *, const wchar_t *) |
| 92 | wchar_t * | 112 | __asm__(__USER_LABEL_PREFIX__ "wcscpy"); |
| 93 | __fortify_wcscpy(wchar_t *d, const wchar_t *s) | 113 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 114 | wchar_t *wcscpy(wchar_t *d, const wchar_t *s) | ||
| 94 | { | 115 | { |
| 95 | size_t bos = __builtin_object_size(d, 0); | 116 | size_t bos = __builtin_object_size(d, 0); |
| 96 | 117 | ||
| 97 | if (wcslen(s) + 1 > bos / sizeof(wchar_t)) | 118 | if (wcslen(s) + 1 > bos / sizeof(wchar_t)) |
| 98 | __builtin_trap(); | 119 | __builtin_trap(); |
| 99 | return wcscpy(d, s); | 120 | return __wcscpy_orig(d, s); |
| 100 | } | 121 | } |
| 101 | 122 | ||
| 102 | static inline __attribute__ ((always_inline)) | 123 | extern wchar_t *__wcsncat_orig(wchar_t *, const wchar_t *, size_t) |
| 103 | wchar_t * | 124 | __asm__(__USER_LABEL_PREFIX__ "wcsncat"); |
| 104 | __fortify_wcsncat(wchar_t *d, const wchar_t *s, size_t n) | 125 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 126 | wchar_t *wcsncat(wchar_t *d, const wchar_t *s, size_t n) | ||
| 105 | { | 127 | { |
| 106 | size_t bos = __builtin_object_size(d, 0); | 128 | size_t bos = __builtin_object_size(d, 0); |
| 107 | size_t slen, dlen; | 129 | size_t slen, dlen; |
| @@ -114,143 +136,116 @@ __fortify_wcsncat(wchar_t *d, const wchar_t *s, size_t n) | |||
| 114 | if (slen + dlen + 1 > bos / sizeof(wchar_t)) | 136 | if (slen + dlen + 1 > bos / sizeof(wchar_t)) |
| 115 | __builtin_trap(); | 137 | __builtin_trap(); |
| 116 | } | 138 | } |
| 117 | return wcsncat(d, s, n); | 139 | return __wcsncat_orig(d, s, n); |
| 118 | } | 140 | } |
| 119 | 141 | ||
| 120 | static inline __attribute__ ((always_inline)) | 142 | extern wchar_t *__wcsncpy_orig(wchar_t *, const wchar_t *, size_t) |
| 121 | wchar_t * | 143 | __asm__(__USER_LABEL_PREFIX__ "wcsncpy"); |
| 122 | __fortify_wcsncpy(wchar_t *d, const wchar_t *s, size_t n) | 144 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 145 | wchar_t *wcsncpy(wchar_t *d, const wchar_t *s, size_t n) | ||
| 123 | { | 146 | { |
| 124 | size_t bos = __builtin_object_size(d, 0); | 147 | size_t bos = __builtin_object_size(d, 0); |
| 125 | 148 | ||
| 126 | if (n > bos / sizeof(wchar_t)) | 149 | if (n > bos / sizeof(wchar_t)) |
| 127 | __builtin_trap(); | 150 | __builtin_trap(); |
| 128 | return wcsncpy(d, s, n); | 151 | return __wcsncpy_orig(d, s, n); |
| 129 | } | 152 | } |
| 130 | 153 | ||
| 131 | static inline __attribute__ ((always_inline)) | 154 | extern size_t __wcsnrtombs_orig(char *, const wchar_t **, size_t, size_t, mbstate_t *) |
| 132 | size_t | 155 | __asm__(__USER_LABEL_PREFIX__ "wcsnrtombs"); |
| 133 | __fortify_wcsnrtombs(char *d, const wchar_t **s, size_t wn, | 156 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 134 | size_t n, mbstate_t *st) | 157 | size_t wcsnrtombs(char *d, const wchar_t **s, size_t wn, size_t n, mbstate_t *st) |
| 135 | { | 158 | { |
| 136 | size_t bos = __builtin_object_size(d, 0); | 159 | size_t bos = __builtin_object_size(d, 0); |
| 137 | size_t r; | 160 | size_t r; |
| 138 | 161 | ||
| 139 | if (wn > n / sizeof(wchar_t)) { | 162 | if (wn > n / sizeof(wchar_t)) { |
| 140 | bos /= sizeof(wchar_t); | 163 | bos /= sizeof(wchar_t); |
| 141 | r = wcsnrtombs(d, s, wn > bos ? bos : wn, n, st); | 164 | r = __wcsnrtombs_orig(d, s, wn > bos ? bos : wn, n, st); |
| 142 | if (bos < wn && d && *s && r != (size_t)-1) | 165 | if (bos < wn && d && *s && r != (size_t)-1) |
| 143 | __builtin_trap(); | 166 | __builtin_trap(); |
| 144 | } else { | 167 | } else { |
| 145 | r = wcsnrtombs(d, s, wn, n > bos ? bos : n, st); | 168 | r = __wcsnrtombs_orig(d, s, wn, n > bos ? bos : n, st); |
| 146 | if (bos < n && d && *s && r != (size_t)-1) | 169 | if (bos < n && d && *s && r != (size_t)-1) |
| 147 | __builtin_trap(); | 170 | __builtin_trap(); |
| 148 | } | 171 | } |
| 149 | return r; | 172 | return r; |
| 150 | } | 173 | } |
| 151 | 174 | ||
| 152 | static inline __attribute__ ((always_inline)) | 175 | extern size_t __wcsrtombs_orig(char *, const wchar_t **, size_t, mbstate_t *) |
| 153 | size_t | 176 | __asm__(__USER_LABEL_PREFIX__ "wcsrtombs"); |
| 154 | __fortify_wcsrtombs(char *d, const wchar_t **s, size_t n, | 177 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 155 | mbstate_t *st) | 178 | size_t wcsrtombs(char *d, const wchar_t **s, size_t n, mbstate_t *st) |
| 156 | { | 179 | { |
| 157 | size_t bos = __builtin_object_size(d, 0); | 180 | size_t bos = __builtin_object_size(d, 0); |
| 158 | size_t r; | 181 | size_t r; |
| 159 | 182 | ||
| 160 | r = wcsrtombs(d, s, n > bos ? bos : n, st); | 183 | r = __wcsrtombs_orig(d, s, n > bos ? bos : n, st); |
| 161 | if (bos < n && d && *s && r != (size_t)-1) | 184 | if (bos < n && d && *s && r != (size_t)-1) |
| 162 | __builtin_trap(); | 185 | __builtin_trap(); |
| 163 | return r; | 186 | return r; |
| 164 | } | 187 | } |
| 165 | 188 | ||
| 166 | static inline __attribute__ ((always_inline)) | 189 | extern size_t __wcstombs_orig(char *, const wchar_t *, size_t) |
| 167 | size_t | 190 | __asm__(__USER_LABEL_PREFIX__ "wcstombs"); |
| 168 | __fortify_wcstombs(char *s, const wchar_t *ws, size_t n) | 191 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 192 | size_t wcstombs(char *s, const wchar_t *ws, size_t n) | ||
| 169 | { | 193 | { |
| 170 | size_t bos = __builtin_object_size(s, 0); | 194 | size_t bos = __builtin_object_size(s, 0); |
| 171 | 195 | ||
| 172 | if (s && n > bos) | 196 | if (s && n > bos) |
| 173 | __builtin_trap(); | 197 | __builtin_trap(); |
| 174 | return wcstombs(s, ws, n); | 198 | return __wcstombs_orig(s, ws, n); |
| 175 | } | 199 | } |
| 176 | 200 | ||
| 177 | static inline __attribute__ ((always_inline)) | 201 | extern int __wctomb_orig(char *, wchar_t) |
| 178 | int | 202 | __asm__(__USER_LABEL_PREFIX__ "wctomb"); |
| 179 | __fortify_wctomb(char *s, wchar_t wc) | 203 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 204 | int wctomb(char *s, wchar_t wc) | ||
| 180 | { | 205 | { |
| 181 | size_t bos = __builtin_object_size(s, 0); | 206 | size_t bos = __builtin_object_size(s, 0); |
| 182 | 207 | ||
| 183 | if (s && MB_CUR_MAX > bos) | 208 | if (s && MB_CUR_MAX > bos) |
| 184 | __builtin_trap(); | 209 | __builtin_trap(); |
| 185 | return wctomb(s, wc); | 210 | return __wctomb_orig(s, wc); |
| 186 | } | 211 | } |
| 187 | 212 | ||
| 188 | static inline __attribute__ ((always_inline)) | 213 | extern wchar_t *__wmemcpy_orig(wchar_t *, const wchar_t *, size_t) |
| 189 | wchar_t * | 214 | __asm__(__USER_LABEL_PREFIX__ "wmemcpy"); |
| 190 | __fortify_wmemcpy(wchar_t *d, const wchar_t *s, size_t n) | 215 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 216 | wchar_t *wmemcpy(wchar_t *d, const wchar_t *s, size_t n) | ||
| 191 | { | 217 | { |
| 192 | size_t bos = __builtin_object_size(d, 0); | 218 | size_t bos = __builtin_object_size(d, 0); |
| 193 | 219 | ||
| 194 | if (n > bos / sizeof(wchar_t)) | 220 | if (n > bos / sizeof(wchar_t)) |
| 195 | __builtin_trap(); | 221 | __builtin_trap(); |
| 196 | return wmemcpy(d, s, n); | 222 | return __wmemcpy_orig(d, s, n); |
| 197 | } | 223 | } |
| 198 | 224 | ||
| 199 | static inline __attribute__ ((always_inline)) | 225 | extern wchar_t *__wmemmove_orig(wchar_t *, const wchar_t *, size_t) |
| 200 | wchar_t * | 226 | __asm__(__USER_LABEL_PREFIX__ "wmemmove"); |
| 201 | __fortify_wmemmove(wchar_t *d, const wchar_t *s, size_t n) | 227 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 228 | wchar_t *wmemmove(wchar_t *d, const wchar_t *s, size_t n) | ||
| 202 | { | 229 | { |
| 203 | size_t bos = __builtin_object_size(d, 0); | 230 | size_t bos = __builtin_object_size(d, 0); |
| 204 | 231 | ||
| 205 | if (n > bos / sizeof(wchar_t)) | 232 | if (n > bos / sizeof(wchar_t)) |
| 206 | __builtin_trap(); | 233 | __builtin_trap(); |
| 207 | return wmemmove(d, s, n); | 234 | return __wmemmove_orig(d, s, n); |
| 208 | } | 235 | } |
| 209 | 236 | ||
| 210 | static inline __attribute__ ((always_inline)) | 237 | extern wchar_t *__wmemset_orig(wchar_t *, wchar_t, size_t) |
| 211 | wchar_t * | 238 | __asm__(__USER_LABEL_PREFIX__ "wmemset"); |
| 212 | __fortify_wmemset(wchar_t *s, wchar_t c, size_t n) | 239 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 240 | wchar_t *wmemset(wchar_t *s, wchar_t c, size_t n) | ||
| 213 | { | 241 | { |
| 214 | size_t bos = __builtin_object_size(s, 0); | 242 | size_t bos = __builtin_object_size(s, 0); |
| 215 | 243 | ||
| 216 | if (n > bos / sizeof(wchar_t)) | 244 | if (n > bos / sizeof(wchar_t)) |
| 217 | __builtin_trap(); | 245 | __builtin_trap(); |
| 218 | return wmemset(s, c, n); | 246 | return __wmemset_orig(s, c, n); |
| 219 | } | 247 | } |
| 220 | 248 | ||
| 221 | #undef fgetws | ||
| 222 | #define fgetws(s, n, fp) __fortify_fgetws(s, n, fp) | ||
| 223 | #undef mbsnrtowcs | ||
| 224 | #define mbsnrtowcs(d, s, n, wn, st) __fortify_mbsnrtowcs(d, s, n, wn, st) | ||
| 225 | #undef mbsrtowcs | ||
| 226 | #define mbsrtowcs(d, s, wn, st) __fortify_mbsrtowcs(d, s, wn, st) | ||
| 227 | #undef mbstowcs | ||
| 228 | #define mbstowcs(ws, s, wn) __fortify_mbstowcs(ws, s, wn) | ||
| 229 | #undef wcrtomb | ||
| 230 | #define wcrtomb(s, wc, st) __fortify_wcrtomb(s, wc, st) | ||
| 231 | #undef wcscat | ||
| 232 | #define wcscat(d, s) __fortify_wcscat(d, s) | ||
| 233 | #undef wcscpy | ||
| 234 | #define wcscpy(d, s) __fortify_wcscpy(d, s) | ||
| 235 | #undef wcsncat | ||
| 236 | #define wcsncat(d, s, n) __fortify_wcsncat(d, s, n) | ||
| 237 | #undef wcsncpy | ||
| 238 | #define wcsncpy(d, s, n) __fortify_wcsncpy(d, s, n) | ||
| 239 | #undef wcsnrtombs | ||
| 240 | #define wcsnrtombs(d, s, wn, n, st) __fortify_wcsnrtombs(d, s, wn, n, st) | ||
| 241 | #undef wcsrtombs | ||
| 242 | #define wcsrtombs(d, s, n, st) __fortify_wcsrtombs(d, s, n, st) | ||
| 243 | #undef wcstombs | ||
| 244 | #define wcstombs(s, ws, n) __fortify_wcstombs(s, ws, n) | ||
| 245 | #undef wctomb | ||
| 246 | #define wctomb(s, wc) __fortify_wctomb(s, wc) | ||
| 247 | #undef wmemcpy | ||
| 248 | #define wmemcpy(d, s, n) __fortify_wmemcpy(d, s, n) | ||
| 249 | #undef wmemmove | ||
| 250 | #define wmemmove(d, s, n) __fortify_wmemmove(d, s, n) | ||
| 251 | #undef wmemset | ||
| 252 | #define wmemset(s, c, n) __fortify_wmemset(s, c, n) | ||
| 253 | |||
| 254 | #endif | 249 | #endif |
| 255 | 250 | ||
| 256 | #endif | 251 | #endif |
