diff options
| author | sin | 2015-05-13 12:04:15 +0100 |
|---|---|---|
| committer | sin | 2015-05-13 12:05:29 +0100 |
| commit | 158782b3bb791eae3c97947944c7023452bfbc96 (patch) | |
| tree | b76e70744ab0a2f76d781a65a0456b1b010c54df /include/string.h | |
| parent | 316a48653315b4bc36d8c50b542471b18441c9d5 (diff) | |
Add fortify_fn() helper in fortify-headers.h
Diffstat (limited to 'include/string.h')
| -rw-r--r-- | include/string.h | 73 |
1 files changed, 25 insertions, 48 deletions
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 |
| 9 | extern "C" { | 10 | extern "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"); | 21 | fortify_fn(memcpy) void *memcpy(void *dst, const void *src, size_t n) |
| 21 | extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) | ||
| 22 | void *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"); | 38 | fortify_fn(memmove) void *memmove(void *dst, const void *src, size_t n) |
| 40 | extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) | ||
| 41 | void *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"); | 48 | fortify_fn(memset) void *memset(void *dst, int c, size_t n) |
| 52 | extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) | ||
| 53 | void *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"); | 61 | fortify_fn(stpcpy) char *stpcpy(char *dst, const char *src) |
| 67 | extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) | ||
| 68 | char *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"); | 71 | fortify_fn(stpncpy) char *stpncpy(char *dst, const char *src, size_t n) |
| 79 | extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) | ||
| 80 | char *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"); | 81 | fortify_fn(strcat) char *strcat(char *dst, const char *src) |
| 91 | extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) | ||
| 92 | char *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"); | 90 | fortify_fn(strcpy) char *strcpy(char *dst, const char *src) |
| 102 | extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) | ||
| 103 | char *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"); | 99 | fortify_fn(strncat) char *strncat(char *dst, const char *src, size_t n) |
| 113 | extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) | ||
| 114 | char *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"); | 115 | fortify_fn(strncpy) char *strncpy(char *dst, const char *src, size_t n) |
| 131 | extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) | ||
| 132 | char *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"); | 126 | fortify_fn(mempcpy) void *mempcpy(void *dst, const void *src, size_t n) |
| 144 | extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) | ||
| 145 | void *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"); | 140 | fortify_fn(strlcat) size_t strlcat(char *dst, const char *src, size_t n) |
| 160 | extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) | ||
| 161 | size_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"); | 149 | fortify_fn(strlcpy) size_t strlcpy(char *dst, const char *src, size_t n) |
| 171 | extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) | ||
| 172 | size_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 | ||
