diff options
| author | Julien Voisin | 2023-12-15 22:36:18 +0100 |
|---|---|---|
| committer | GitHub | 2023-12-15 22:36:18 +0100 |
| commit | e83bd596459896b9593b392d0f6055b34f45d561 (patch) | |
| tree | f4fb73a124fd3de49e5cef291077003d797dc2c9 /include | |
| parent | 8342bc50a16a2158fef729db6cbfef874734e4dc (diff) | |
| parent | 57a3e9c1c7507b5ce56122429cc3649009a4ecc7 (diff) | |
Remove superfluous includes
Diffstat (limited to 'include')
| -rw-r--r-- | include/fortify-headers.h | 8 | ||||
| -rw-r--r-- | include/poll.h | 4 | ||||
| -rw-r--r-- | include/stdio.h | 24 | ||||
| -rw-r--r-- | include/stdlib.h | 49 | ||||
| -rw-r--r-- | include/string.h | 46 | ||||
| -rw-r--r-- | include/strings.h | 6 | ||||
| -rw-r--r-- | include/sys/select.h | 6 | ||||
| -rw-r--r-- | include/sys/socket.h | 8 | ||||
| -rw-r--r-- | include/unistd.h | 28 | ||||
| -rw-r--r-- | include/wchar.h | 106 |
10 files changed, 135 insertions, 150 deletions
diff --git a/include/fortify-headers.h b/include/fortify-headers.h index c7b15f9..bd53954 100644 --- a/include/fortify-headers.h +++ b/include/fortify-headers.h | |||
| @@ -123,13 +123,17 @@ | |||
| 123 | 123 | ||
| 124 | #endif /* __has_attribute */ | 124 | #endif /* __has_attribute */ |
| 125 | 125 | ||
| 126 | // Since we're not allow to include anything. | ||
| 127 | // https://awesomekling.github.io/How-SerenityOS-declares-ssize_t/ | ||
| 128 | #define __fh_size_t __typeof__(sizeof(char)) | ||
| 129 | |||
| 126 | //TODO(jvoisin) Add a check for overflows | 130 | //TODO(jvoisin) Add a check for overflows |
| 127 | /* check if pointers are overlapping but not if dst == src, | 131 | /* check if pointers are overlapping but not if dst == src, |
| 128 | * since gcc seems to like to generate code that relies on dst == src */ | 132 | * since gcc seems to like to generate code that relies on dst == src */ |
| 129 | #define __fh_overlap(a, b, l) \ | 133 | #define __fh_overlap(a, b, l) \ |
| 130 | ( \ | 134 | ( \ |
| 131 | ((a) < (b) && (b) < (a) + (size_t)(l)) \ | 135 | ((a) < (b) && (b) < (a) + (__fh_size_t)(l)) \ |
| 132 | || ((b) < (a) && (a) < (b) + (size_t)(l)) \ | 136 | || ((b) < (a) && (a) < (b) + (__fh_size_t)(l)) \ |
| 133 | ) | 137 | ) |
| 134 | 138 | ||
| 135 | /* | 139 | /* |
diff --git a/include/poll.h b/include/poll.h index 8831f95..29e5c40 100644 --- a/include/poll.h +++ b/include/poll.h | |||
| @@ -36,7 +36,7 @@ __diagnose_as_builtin(__builtin_poll, 1, 2, 3) | |||
| 36 | #endif | 36 | #endif |
| 37 | _FORTIFY_FN(poll) int poll(struct pollfd * _FORTIFY_POS0 __f, nfds_t __n, int __s) | 37 | _FORTIFY_FN(poll) int poll(struct pollfd * _FORTIFY_POS0 __f, nfds_t __n, int __s) |
| 38 | { | 38 | { |
| 39 | size_t __b = __bos(__f, 0); | 39 | __fh_size_t __b = __bos(__f, 0); |
| 40 | 40 | ||
| 41 | if (__n > __b / sizeof(struct pollfd)) | 41 | if (__n > __b / sizeof(struct pollfd)) |
| 42 | __builtin_trap(); | 42 | __builtin_trap(); |
| @@ -51,7 +51,7 @@ __diagnose_as_builtin(__builtin_ppoll, 1, 2, 3, 4) | |||
| 51 | _FORTIFY_FN(ppoll) int ppoll(struct pollfd * _FORTIFY_POS0 __f, nfds_t __n, | 51 | _FORTIFY_FN(ppoll) int ppoll(struct pollfd * _FORTIFY_POS0 __f, nfds_t __n, |
| 52 | const struct timespec *__s, const sigset_t *__m) | 52 | const struct timespec *__s, const sigset_t *__m) |
| 53 | { | 53 | { |
| 54 | size_t __b = __bos(__f, 0); | 54 | __fh_size_t __b = __bos(__f, 0); |
| 55 | 55 | ||
| 56 | if (__n > __b / sizeof(struct pollfd)) | 56 | if (__n > __b / sizeof(struct pollfd)) |
| 57 | __builtin_trap(); | 57 | __builtin_trap(); |
diff --git a/include/stdio.h b/include/stdio.h index c69afcc..0e06e83 100644 --- a/include/stdio.h +++ b/include/stdio.h | |||
| @@ -54,9 +54,9 @@ __diagnose_as_builtin(__builtin_fgets, 1, 2, 3) | |||
| 54 | #endif | 54 | #endif |
| 55 | _FORTIFY_FN(fgets) char *fgets(char * _FORTIFY_POS0 __s, int __n, FILE *__f) | 55 | _FORTIFY_FN(fgets) char *fgets(char * _FORTIFY_POS0 __s, int __n, FILE *__f) |
| 56 | { | 56 | { |
| 57 | size_t __b = __bos(__s, 0); | 57 | __fh_size_t __b = __bos(__s, 0); |
| 58 | 58 | ||
| 59 | if ((size_t)__n > __b) | 59 | if ((__fh_size_t)__n > __b) |
| 60 | __builtin_trap(); | 60 | __builtin_trap(); |
| 61 | return __orig_fgets(__s, __n, __f); | 61 | return __orig_fgets(__s, __n, __f); |
| 62 | } | 62 | } |
| @@ -88,7 +88,7 @@ __diagnose_as_builtin(__builtin_fread, 1, 2, 3, 4) | |||
| 88 | _FORTIFY_FN(fread) size_t fread(void * _FORTIFY_POS0 __d, size_t __n, | 88 | _FORTIFY_FN(fread) size_t fread(void * _FORTIFY_POS0 __d, size_t __n, |
| 89 | size_t __m, FILE *__f) | 89 | size_t __m, FILE *__f) |
| 90 | { | 90 | { |
| 91 | size_t __b = __bos(__d, 0); | 91 | __fh_size_t __b = __bos(__d, 0); |
| 92 | 92 | ||
| 93 | if (__bmo(__n, __m)) | 93 | if (__bmo(__n, __m)) |
| 94 | __builtin_trap(); | 94 | __builtin_trap(); |
| @@ -104,7 +104,7 @@ __diagnose_as_builtin(__builtin_fwrite, 1, 2, 3, 4) | |||
| 104 | _FORTIFY_FN(fwrite) size_t fwrite(const void * _FORTIFY_POS0 __d, size_t __n, | 104 | _FORTIFY_FN(fwrite) size_t fwrite(const void * _FORTIFY_POS0 __d, size_t __n, |
| 105 | size_t __m, FILE *__f) | 105 | size_t __m, FILE *__f) |
| 106 | { | 106 | { |
| 107 | size_t __b = __bos(__d, 0); | 107 | __fh_size_t __b = __bos(__d, 0); |
| 108 | 108 | ||
| 109 | if (__bmo(__n, __m)) | 109 | if (__bmo(__n, __m)) |
| 110 | __builtin_trap(); | 110 | __builtin_trap(); |
| @@ -148,7 +148,7 @@ _FORTIFY_FN(vsnprintf) int vsnprintf(char * _FORTIFY_POS0 __s, size_t __n, | |||
| 148 | #if __has_builtin(__builtin___vsnprintf_chk) && USE_NATIVE_CHK | 148 | #if __has_builtin(__builtin___vsnprintf_chk) && USE_NATIVE_CHK |
| 149 | return __builtin___vsnprintf_chk(__s, __n, _FORTIFY_SOURCE, __bos(__s, 0), __f, __v); | 149 | return __builtin___vsnprintf_chk(__s, __n, _FORTIFY_SOURCE, __bos(__s, 0), __f, __v); |
| 150 | #else | 150 | #else |
| 151 | size_t __b = __bos(__s, 0); | 151 | __fh_size_t __b = __bos(__s, 0); |
| 152 | 152 | ||
| 153 | if (__n > __b) | 153 | if (__n > __b) |
| 154 | __builtin_trap(); | 154 | __builtin_trap(); |
| @@ -168,12 +168,12 @@ _FORTIFY_FN(vsprintf) int vsprintf(char * _FORTIFY_POS0 __s, const char *__f, | |||
| 168 | #if __has_builtin(__builtin___vsprintf_chk) && USE_NATIVE_CHK | 168 | #if __has_builtin(__builtin___vsprintf_chk) && USE_NATIVE_CHK |
| 169 | return __builtin___vsprintf_chk(__s, _FORTIFY_SOURCE, __bos(__s, 0), __f, __v); | 169 | return __builtin___vsprintf_chk(__s, _FORTIFY_SOURCE, __bos(__s, 0), __f, __v); |
| 170 | #else | 170 | #else |
| 171 | size_t __b = __bos(__s, 0); | 171 | __fh_size_t __b = __bos(__s, 0); |
| 172 | int __r; | 172 | int __r; |
| 173 | 173 | ||
| 174 | if (__b != (size_t)-1) { | 174 | if (__b != (__fh_size_t)-1) { |
| 175 | __r = __orig_vsnprintf(__s, __b, __f, __v); | 175 | __r = __orig_vsnprintf(__s, __b, __f, __v); |
| 176 | if (__r != -1 && (size_t)__r >= __b) | 176 | if (__r != -1 && (__fh_size_t)__r >= __b) |
| 177 | __builtin_trap(); | 177 | __builtin_trap(); |
| 178 | } else { | 178 | } else { |
| 179 | __r = __orig_vsprintf(__s, __f, __v); | 179 | __r = __orig_vsprintf(__s, __f, __v); |
| @@ -250,7 +250,7 @@ _FORTIFY_FN(snprintf) int snprintf(char *__s, size_t __n, | |||
| 250 | #if __has_builtin(__builtin___snprintf_chk) && USE_NATIVE_CHK | 250 | #if __has_builtin(__builtin___snprintf_chk) && USE_NATIVE_CHK |
| 251 | return __builtin___snprintf_chk(__s, __n, _FORTIFY_SOURCE, __bos(__s, 0), __f, __builtin_va_arg_pack()); | 251 | return __builtin___snprintf_chk(__s, __n, _FORTIFY_SOURCE, __bos(__s, 0), __f, __builtin_va_arg_pack()); |
| 252 | #else | 252 | #else |
| 253 | size_t __b = __bos(__s, 0); | 253 | __fh_size_t __b = __bos(__s, 0); |
| 254 | 254 | ||
| 255 | if (__n > __b) | 255 | if (__n > __b) |
| 256 | __builtin_trap(); | 256 | __builtin_trap(); |
| @@ -266,12 +266,12 @@ _FORTIFY_FN(sprintf) int sprintf(char *__s, const char *__f, ...) | |||
| 266 | #if __has_builtin(__builtin___sprintf_chk) && USE_NATIVE_CHK | 266 | #if __has_builtin(__builtin___sprintf_chk) && USE_NATIVE_CHK |
| 267 | return __builtin___sprintf_chk(__s, _FORTIFY_SOURCE, __bos(__s, 0), __f, __builtin_va_arg_pack()); | 267 | return __builtin___sprintf_chk(__s, _FORTIFY_SOURCE, __bos(__s, 0), __f, __builtin_va_arg_pack()); |
| 268 | #else | 268 | #else |
| 269 | size_t __b = __bos(__s, 0); | 269 | __fh_size_t __b = __bos(__s, 0); |
| 270 | int __r; | 270 | int __r; |
| 271 | 271 | ||
| 272 | if (__b != (size_t)-1) { | 272 | if (__b != (__fh_size_t)-1) { |
| 273 | __r = __orig_snprintf(__s, __b, __f, __builtin_va_arg_pack()); | 273 | __r = __orig_snprintf(__s, __b, __f, __builtin_va_arg_pack()); |
| 274 | if (__r != -1 && (size_t)__r >= __b) | 274 | if (__r != -1 && (__fh_size_t)__r >= __b) |
| 275 | __builtin_trap(); | 275 | __builtin_trap(); |
| 276 | } else { | 276 | } else { |
| 277 | __r = __orig_sprintf(__s, __f, __builtin_va_arg_pack()); | 277 | __r = __orig_sprintf(__s, __f, __builtin_va_arg_pack()); |
diff --git a/include/stdlib.h b/include/stdlib.h index 4a5cfde..6081170 100644 --- a/include/stdlib.h +++ b/include/stdlib.h | |||
| @@ -24,19 +24,41 @@ __extension__ | |||
| 24 | 24 | ||
| 25 | #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 | 25 | #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 |
| 26 | 26 | ||
| 27 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 28 | #if !defined(__cplusplus) && !defined(__clang__) | ||
| 29 | __extension__ | ||
| 30 | #endif | ||
| 31 | #include_next <limits.h> | ||
| 32 | #endif | ||
| 33 | |||
| 34 | #include "fortify-headers.h" | 27 | #include "fortify-headers.h" |
| 35 | 28 | ||
| 36 | #ifdef __cplusplus | 29 | #ifdef __cplusplus |
| 37 | extern "C" { | 30 | extern "C" { |
| 38 | #endif | 31 | #endif |
| 39 | 32 | ||
| 33 | #undef mbstowcs | ||
| 34 | #if __has_builtin(__builtin_mbstowcs) | ||
| 35 | __diagnose_as_builtin(__builtin_mbstowcs, 1, 2, 3) | ||
| 36 | #endif | ||
| 37 | _FORTIFY_FN(mbstowcs) size_t mbstowcs(wchar_t * _FORTIFY_POS0 __ws, | ||
| 38 | const char *__s, size_t __wn) | ||
| 39 | { | ||
| 40 | __fh_size_t __b = __bos(__ws, 0); | ||
| 41 | |||
| 42 | if (__ws && __wn > __b / sizeof(wchar_t)) | ||
| 43 | __builtin_trap(); | ||
| 44 | return __orig_mbstowcs(__ws, __s, __wn); | ||
| 45 | } | ||
| 46 | |||
| 47 | #undef wcstombs | ||
| 48 | __access(write_only, 1, 3) | ||
| 49 | #if __has_builtin(__builtin_wcstombs) | ||
| 50 | __diagnose_as_builtin(__builtin_wcstombs, 1, 2, 3) | ||
| 51 | #endif | ||
| 52 | _FORTIFY_FN(wcstombs) size_t wcstombs(char * _FORTIFY_POS0 __s, | ||
| 53 | const wchar_t *__ws, size_t __n) | ||
| 54 | { | ||
| 55 | __fh_size_t __b = __bos(__s, 0); | ||
| 56 | |||
| 57 | if (__s && __n > __b) | ||
| 58 | __builtin_trap(); | ||
| 59 | return __orig_wcstombs(__s, __ws, __n); | ||
| 60 | } | ||
| 61 | |||
| 40 | #undef qsort | 62 | #undef qsort |
| 41 | #if __has_builtin(__builtin_qsort) | 63 | #if __has_builtin(__builtin_qsort) |
| 42 | __diagnose_as_builtin(__builtin_qsort, 1, 2, 3, 4) | 64 | __diagnose_as_builtin(__builtin_qsort, 1, 2, 3, 4) |
| @@ -45,7 +67,7 @@ __access(read_write, 1) | |||
| 45 | _FORTIFY_FN(qsort) void qsort(void * _FORTIFY_POS0 base, size_t nmemb, size_t size, | 67 | _FORTIFY_FN(qsort) void qsort(void * _FORTIFY_POS0 base, size_t nmemb, size_t size, |
| 46 | int (*compar)(const void *, const void *)) | 68 | int (*compar)(const void *, const void *)) |
| 47 | { | 69 | { |
| 48 | size_t __b = __bos(base, 0); | 70 | __fh_size_t __b = __bos(base, 0); |
| 49 | 71 | ||
| 50 | if (__bmo(nmemb, size)) | 72 | if (__bmo(nmemb, size)) |
| 51 | __builtin_trap(); | 73 | __builtin_trap(); |
| @@ -113,12 +135,10 @@ __diagnose_as_builtin(__builtin_realpath, 1, 2) | |||
| 113 | #endif | 135 | #endif |
| 114 | _FORTIFY_FN(realpath) char *realpath(const char *__p, char *__r) | 136 | _FORTIFY_FN(realpath) char *realpath(const char *__p, char *__r) |
| 115 | { | 137 | { |
| 116 | #ifndef PATH_MAX | 138 | // PATH_MAX is defined as 4096 |
| 117 | #error PATH_MAX unset. A fortified realpath will not work. | 139 | if (__r && 4096 > __bos(__r, 2)) { |
| 118 | #else | 140 | char __buf[4096], *__ret; |
| 119 | if (__r && PATH_MAX > __bos(__r, 2)) { | 141 | __fh_size_t __l; |
| 120 | char __buf[PATH_MAX], *__ret; | ||
| 121 | size_t __l; | ||
| 122 | 142 | ||
| 123 | __ret = __orig_realpath(__p, __buf); | 143 | __ret = __orig_realpath(__p, __buf); |
| 124 | if (!__ret) | 144 | if (!__ret) |
| @@ -130,7 +150,6 @@ _FORTIFY_FN(realpath) char *realpath(const char *__p, char *__r) | |||
| 130 | return __r; | 150 | return __r; |
| 131 | } | 151 | } |
| 132 | return __orig_realpath(__p, __r); | 152 | return __orig_realpath(__p, __r); |
| 133 | #endif | ||
| 134 | } | 153 | } |
| 135 | #endif | 154 | #endif |
| 136 | 155 | ||
diff --git a/include/string.h b/include/string.h index a41c669..a6965b2 100644 --- a/include/string.h +++ b/include/string.h | |||
| @@ -51,8 +51,8 @@ __error_if((__bos(__od, 0) < __n), "'memcpy' called with `n` bigger than the siz | |||
| 51 | #if __has_builtin(__builtin___memcpy_chk) && USE_NATIVE_CHK | 51 | #if __has_builtin(__builtin___memcpy_chk) && USE_NATIVE_CHK |
| 52 | return __builtin___memcpy_chk(__od, __os, __n, __bos(__od, 0)); | 52 | return __builtin___memcpy_chk(__od, __os, __n, __bos(__od, 0)); |
| 53 | #else | 53 | #else |
| 54 | size_t __bd = __bos(__od, 0); | 54 | __fh_size_t __bd = __bos(__od, 0); |
| 55 | size_t __bs = __bos(__os, 0); | 55 | __fh_size_t __bs = __bos(__os, 0); |
| 56 | char *__d = (char *)__od; | 56 | char *__d = (char *)__od; |
| 57 | const char *__s = (const char *)__os; | 57 | const char *__s = (const char *)__os; |
| 58 | 58 | ||
| @@ -75,8 +75,8 @@ _FORTIFY_FN(memmove) void *memmove(void * _FORTIFY_POS0 __d, | |||
| 75 | #if __has_builtin(__builtin___memmove_chk) && USE_NATIVE_CHK | 75 | #if __has_builtin(__builtin___memmove_chk) && USE_NATIVE_CHK |
| 76 | return __builtin___memmove_chk(__d, __s, __n, __bos(__d, 0)); | 76 | return __builtin___memmove_chk(__d, __s, __n, __bos(__d, 0)); |
| 77 | #else | 77 | #else |
| 78 | size_t __bd = __bos(__d, 0); | 78 | __fh_size_t __bd = __bos(__d, 0); |
| 79 | size_t __bs = __bos(__s, 0); | 79 | __fh_size_t __bs = __bos(__s, 0); |
| 80 | 80 | ||
| 81 | if (__n > __bd || __n > __bs) | 81 | if (__n > __bd || __n > __bs) |
| 82 | __builtin_trap(); | 82 | __builtin_trap(); |
| @@ -94,7 +94,7 @@ __warning_if(__c != 0 && __n == 0, "'memset' will set `0` bytes; did you invert | |||
| 94 | #if __has_builtin(__builtin___memset_chk) && USE_NATIVE_CHK | 94 | #if __has_builtin(__builtin___memset_chk) && USE_NATIVE_CHK |
| 95 | return __builtin___memset_chk(__d, __c, __n, __bos(__d, 0)); | 95 | return __builtin___memset_chk(__d, __c, __n, __bos(__d, 0)); |
| 96 | #else | 96 | #else |
| 97 | size_t __b = __bos(__d, 0); | 97 | __fh_size_t __b = __bos(__d, 0); |
| 98 | 98 | ||
| 99 | if (__n > __b) | 99 | if (__n > __b) |
| 100 | __builtin_trap(); | 100 | __builtin_trap(); |
| @@ -111,7 +111,7 @@ _FORTIFY_FN(memchr) void *memchr(const void * _FORTIFY_POS0 __d, int __c, size_t | |||
| 111 | #if __has_builtin(__builtin___memchr_chk) && USE_NATIVE_CHK | 111 | #if __has_builtin(__builtin___memchr_chk) && USE_NATIVE_CHK |
| 112 | return __builtin___memchr_chk(__d, __c, __n, __bos(__d, 0)); | 112 | return __builtin___memchr_chk(__d, __c, __n, __bos(__d, 0)); |
| 113 | #else | 113 | #else |
| 114 | size_t __b = __bos(__d, 0); | 114 | __fh_size_t __b = __bos(__d, 0); |
| 115 | 115 | ||
| 116 | if (__n > __b) | 116 | if (__n > __b) |
| 117 | __builtin_trap(); | 117 | __builtin_trap(); |
| @@ -125,7 +125,7 @@ _FORTIFY_FN(strchr) char *strchr(const char * _FORTIFY_POS0 __s, int __c) | |||
| 125 | #if __has_builtin(__builtin___strchr_chk) && USE_NATIVE_CHK | 125 | #if __has_builtin(__builtin___strchr_chk) && USE_NATIVE_CHK |
| 126 | return __builtin___strchr_chk(__s, __c, __bos(__s, 0)); | 126 | return __builtin___strchr_chk(__s, __c, __bos(__s, 0)); |
| 127 | #else | 127 | #else |
| 128 | size_t __b = __bos(__s, 0); | 128 | __fh_size_t __b = __bos(__s, 0); |
| 129 | 129 | ||
| 130 | char* __r = __builtin_strchr(__s, __c); | 130 | char* __r = __builtin_strchr(__s, __c); |
| 131 | if (__r - __s > __b) | 131 | if (__r - __s > __b) |
| @@ -140,7 +140,7 @@ _FORTIFY_FN(strrchr) char *strrchr(const char * _FORTIFY_POS0 __s, int __c) | |||
| 140 | #if __has_builtin(__builtin___strrchr_chk) && USE_NATIVE_CHK | 140 | #if __has_builtin(__builtin___strrchr_chk) && USE_NATIVE_CHK |
| 141 | return __builtin___strrchr_chk(__s, __c, __bos(__s, 0)); | 141 | return __builtin___strrchr_chk(__s, __c, __bos(__s, 0)); |
| 142 | #else | 142 | #else |
| 143 | size_t __b = __bos(__s, 0); | 143 | __fh_size_t __b = __bos(__s, 0); |
| 144 | 144 | ||
| 145 | char* __r = __builtin_strrchr(__s, __c); | 145 | char* __r = __builtin_strrchr(__s, __c); |
| 146 | if (__r - __s > __b) | 146 | if (__r - __s > __b) |
| @@ -163,12 +163,12 @@ _FORTIFY_FN(stpcpy) char *stpcpy(char * _FORTIFY_POS0 __d, const char *__s) | |||
| 163 | #if __has_builtin(__builtin___stpcpy_chk) && USE_NATIVE_CHK | 163 | #if __has_builtin(__builtin___stpcpy_chk) && USE_NATIVE_CHK |
| 164 | return __builtin___stpcpy_chk(__d, __s, __bos(__d, 0)); | 164 | return __builtin___stpcpy_chk(__d, __s, __bos(__d, 0)); |
| 165 | #else | 165 | #else |
| 166 | size_t __n = strlen(__s) + 1; | 166 | __fh_size_t __n = strlen(__s) + 1; |
| 167 | 167 | ||
| 168 | if (__fh_overlap(__d, __s, __n)) | 168 | if (__fh_overlap(__d, __s, __n)) |
| 169 | __builtin_trap(); | 169 | __builtin_trap(); |
| 170 | 170 | ||
| 171 | size_t __b = __bos(__d, 0); | 171 | __fh_size_t __b = __bos(__d, 0); |
| 172 | if (__n > __b) | 172 | if (__n > __b) |
| 173 | __builtin_trap(); | 173 | __builtin_trap(); |
| 174 | return __orig_stpcpy(__d, __s); | 174 | return __orig_stpcpy(__d, __s); |
| @@ -190,7 +190,7 @@ _FORTIFY_FN(stpncpy) char *stpncpy(char * _FORTIFY_POS0 __d, const char *__s, | |||
| 190 | if (__fh_overlap(__d, __s, __n)) | 190 | if (__fh_overlap(__d, __s, __n)) |
| 191 | __builtin_trap(); | 191 | __builtin_trap(); |
| 192 | 192 | ||
| 193 | size_t __b = __bos(__d, 0); | 193 | __fh_size_t __b = __bos(__d, 0); |
| 194 | if (__n > __b && strlen(__s) + 1 > __b) | 194 | if (__n > __b && strlen(__s) + 1 > __b) |
| 195 | __builtin_trap(); | 195 | __builtin_trap(); |
| 196 | return __orig_stpncpy(__d, __s, __n); | 196 | return __orig_stpncpy(__d, __s, __n); |
| @@ -208,7 +208,7 @@ _FORTIFY_FN(strcat) char *strcat(char * _FORTIFY_POS0 __d, const char *__s) | |||
| 208 | #if __has_builtin(__builtin___strcat_chk) && USE_NATIVE_CHK | 208 | #if __has_builtin(__builtin___strcat_chk) && USE_NATIVE_CHK |
| 209 | return __builtin___strcat_chk(__d, __s, __bos(__d, 0)); | 209 | return __builtin___strcat_chk(__d, __s, __bos(__d, 0)); |
| 210 | #else | 210 | #else |
| 211 | size_t __b = __bos(__d, 0); | 211 | __fh_size_t __b = __bos(__d, 0); |
| 212 | 212 | ||
| 213 | if (strlen(__s) + strlen(__d) + 1 > __b) | 213 | if (strlen(__s) + strlen(__d) + 1 > __b) |
| 214 | __builtin_trap(); | 214 | __builtin_trap(); |
| @@ -226,12 +226,12 @@ _FORTIFY_FN(strcpy) char *strcpy(char * _FORTIFY_POS0 __d, const char *__s) | |||
| 226 | #if __has_builtin(__builtin___strcpy_chk) && USE_NATIVE_CHK | 226 | #if __has_builtin(__builtin___strcpy_chk) && USE_NATIVE_CHK |
| 227 | return __builtin___strcpy_chk(__d, __s, __bos(__d, 0)); | 227 | return __builtin___strcpy_chk(__d, __s, __bos(__d, 0)); |
| 228 | #else | 228 | #else |
| 229 | size_t __n = strlen(__s) + 1; | 229 | __fh_size_t __n = strlen(__s) + 1; |
| 230 | 230 | ||
| 231 | if (__fh_overlap(__d, __s, __n)) | 231 | if (__fh_overlap(__d, __s, __n)) |
| 232 | __builtin_trap(); | 232 | __builtin_trap(); |
| 233 | 233 | ||
| 234 | size_t __b = __bos(__d, 0); | 234 | __fh_size_t __b = __bos(__d, 0); |
| 235 | if (__n > __b) | 235 | if (__n > __b) |
| 236 | __builtin_trap(); | 236 | __builtin_trap(); |
| 237 | return __orig_strcpy(__d, __s); | 237 | return __orig_strcpy(__d, __s); |
| @@ -247,7 +247,7 @@ _FORTIFY_FN(strlen) size_t strlen(const char * _FORTIFY_POS0 __s) | |||
| 247 | #if __has_builtin(__builtin___strlen_chk) && USE_NATIVE_CHK | 247 | #if __has_builtin(__builtin___strlen_chk) && USE_NATIVE_CHK |
| 248 | return __builtin___strlen_chk(__s, __bos(__s, 0)); | 248 | return __builtin___strlen_chk(__s, __bos(__s, 0)); |
| 249 | #else | 249 | #else |
| 250 | size_t ret = __orig_strlen(__s); | 250 | __fh_size_t ret = __orig_strlen(__s); |
| 251 | if (ret > __bos(__s, 0) - 1) | 251 | if (ret > __bos(__s, 0) - 1) |
| 252 | __builtin_trap(); | 252 | __builtin_trap(); |
| 253 | return ret; | 253 | return ret; |
| @@ -265,11 +265,11 @@ _FORTIFY_FN(strncat) char *strncat(char * _FORTIFY_POS0 __d, const char *__s, | |||
| 265 | #if __has_builtin(__builtin___strncat_chk) && USE_NATIVE_CHK | 265 | #if __has_builtin(__builtin___strncat_chk) && USE_NATIVE_CHK |
| 266 | return __builtin___strncat_chk(__d, __s, __n, __bos(__d, 0)); | 266 | return __builtin___strncat_chk(__d, __s, __n, __bos(__d, 0)); |
| 267 | #else | 267 | #else |
| 268 | size_t __b = __bos(__d, 0); | 268 | __fh_size_t __b = __bos(__d, 0); |
| 269 | 269 | ||
| 270 | if (__n > __b) { | 270 | if (__n > __b) { |
| 271 | size_t __sl = strnlen(__s, __n); | 271 | __fh_size_t __sl = strnlen(__s, __n); |
| 272 | size_t __dl = strlen(__d); | 272 | __fh_size_t __dl = strlen(__d); |
| 273 | if (__sl + __dl + 1 > __b) | 273 | if (__sl + __dl + 1 > __b) |
| 274 | __builtin_trap(); | 274 | __builtin_trap(); |
| 275 | } | 275 | } |
| @@ -291,7 +291,7 @@ _FORTIFY_FN(strncpy) char *strncpy(char * _FORTIFY_POS0 __d, | |||
| 291 | if (__fh_overlap(__d, __s, __n)) | 291 | if (__fh_overlap(__d, __s, __n)) |
| 292 | __builtin_trap(); | 292 | __builtin_trap(); |
| 293 | 293 | ||
| 294 | size_t __b = __bos(__d, 0); | 294 | __fh_size_t __b = __bos(__d, 0); |
| 295 | if (__n > __b) | 295 | if (__n > __b) |
| 296 | __builtin_trap(); | 296 | __builtin_trap(); |
| 297 | return __orig_strncpy(__d, __s, __n); | 297 | return __orig_strncpy(__d, __s, __n); |
| @@ -311,8 +311,8 @@ _FORTIFY_FN(mempcpy) void *mempcpy(void * _FORTIFY_POS0 __d, | |||
| 311 | #if __has_builtin(__builtin___mempcpy_chk) && USE_NATIVE_CHK | 311 | #if __has_builtin(__builtin___mempcpy_chk) && USE_NATIVE_CHK |
| 312 | return __builtin___mempcpy_chk(__d, __s, __n, __bos(__d, 0)); | 312 | return __builtin___mempcpy_chk(__d, __s, __n, __bos(__d, 0)); |
| 313 | #else | 313 | #else |
| 314 | size_t __bd = __bos(__d, 0); | 314 | __fh_size_t __bd = __bos(__d, 0); |
| 315 | size_t __bs = __bos(__s, 0); | 315 | __fh_size_t __bs = __bos(__s, 0); |
| 316 | 316 | ||
| 317 | if (__n > __bd || __n > __bs) | 317 | if (__n > __bd || __n > __bs) |
| 318 | __builtin_trap(); | 318 | __builtin_trap(); |
| @@ -335,7 +335,7 @@ _FORTIFY_FN(strlcat) size_t strlcat(char * _FORTIFY_POS0 __d, | |||
| 335 | #if __has_builtin(__builtin___strlcat_chk) && USE_NATIVE_CHK | 335 | #if __has_builtin(__builtin___strlcat_chk) && USE_NATIVE_CHK |
| 336 | return __builtin___strlcat_chk(__d, __s, __n, __bos(__d, 0)); | 336 | return __builtin___strlcat_chk(__d, __s, __n, __bos(__d, 0)); |
| 337 | #else | 337 | #else |
| 338 | size_t __b = __bos(__d, 0); | 338 | __fh_size_t __b = __bos(__d, 0); |
| 339 | 339 | ||
| 340 | if (__n > __b) | 340 | if (__n > __b) |
| 341 | __builtin_trap(); | 341 | __builtin_trap(); |
| @@ -354,7 +354,7 @@ _FORTIFY_FN(strlcpy) size_t strlcpy(char * _FORTIFY_POS0 __d, | |||
| 354 | #if __has_builtin(__builtin___strlcpy_chk) && USE_NATIVE_CHK | 354 | #if __has_builtin(__builtin___strlcpy_chk) && USE_NATIVE_CHK |
| 355 | return __builtin___strlcpy_chk(__d, __s, __n, __bos(__d, 0)); | 355 | return __builtin___strlcpy_chk(__d, __s, __n, __bos(__d, 0)); |
| 356 | #else | 356 | #else |
| 357 | size_t __b = __bos(__d, 0); | 357 | __fh_size_t __b = __bos(__d, 0); |
| 358 | 358 | ||
| 359 | if (__n > __b) | 359 | if (__n > __b) |
| 360 | __builtin_trap(); | 360 | __builtin_trap(); |
diff --git a/include/strings.h b/include/strings.h index c91715d..6886ddc 100644 --- a/include/strings.h +++ b/include/strings.h | |||
| @@ -40,8 +40,8 @@ __diagnose_as_builtin(__builtin_bcopy, 1, 2, 3) | |||
| 40 | _FORTIFY_FN(bcopy) void bcopy(const void * _FORTIFY_POS0 __s, | 40 | _FORTIFY_FN(bcopy) void bcopy(const void * _FORTIFY_POS0 __s, |
| 41 | void * _FORTIFY_POS0 __d, size_t __n) | 41 | void * _FORTIFY_POS0 __d, size_t __n) |
| 42 | { | 42 | { |
| 43 | size_t __bd = __bos(__d, 0); | 43 | __fh_size_t __bd = __bos(__d, 0); |
| 44 | size_t __bs = __bos(__s, 0); | 44 | __fh_size_t __bs = __bos(__s, 0); |
| 45 | 45 | ||
| 46 | if (__n > __bd || __n > __bs) | 46 | if (__n > __bd || __n > __bs) |
| 47 | __builtin_trap(); | 47 | __builtin_trap(); |
| @@ -54,7 +54,7 @@ __diagnose_as_builtin(__builtin_bzero, 1, 2) | |||
| 54 | #endif | 54 | #endif |
| 55 | _FORTIFY_FN(bzero) void bzero(void * _FORTIFY_POS0 __s, size_t __n) | 55 | _FORTIFY_FN(bzero) void bzero(void * _FORTIFY_POS0 __s, size_t __n) |
| 56 | { | 56 | { |
| 57 | size_t __b = __bos(__s, 0); | 57 | __fh_size_t __b = __bos(__s, 0); |
| 58 | 58 | ||
| 59 | if (__n > __b) | 59 | if (__n > __b) |
| 60 | __builtin_trap(); | 60 | __builtin_trap(); |
diff --git a/include/sys/select.h b/include/sys/select.h index f1cefee..9813bb7 100644 --- a/include/sys/select.h +++ b/include/sys/select.h | |||
| @@ -33,7 +33,7 @@ extern "C" { | |||
| 33 | 33 | ||
| 34 | _STI void __fortify_FD_CLR(int __f, fd_set * _FORTIFY_POS0 __s) | 34 | _STI void __fortify_FD_CLR(int __f, fd_set * _FORTIFY_POS0 __s) |
| 35 | { | 35 | { |
| 36 | size_t __b = __bos(__s, 0); | 36 | __fh_size_t __b = __bos(__s, 0); |
| 37 | 37 | ||
| 38 | if (__f < 0 || __f >= FD_SETSIZE || __b < sizeof(fd_set)) | 38 | if (__f < 0 || __f >= FD_SETSIZE || __b < sizeof(fd_set)) |
| 39 | __builtin_trap(); | 39 | __builtin_trap(); |
| @@ -42,7 +42,7 @@ _STI void __fortify_FD_CLR(int __f, fd_set * _FORTIFY_POS0 __s) | |||
| 42 | 42 | ||
| 43 | _STI void __fortify_FD_SET(int __f, fd_set * _FORTIFY_POS0 __s) | 43 | _STI void __fortify_FD_SET(int __f, fd_set * _FORTIFY_POS0 __s) |
| 44 | { | 44 | { |
| 45 | size_t __b = __bos(__s, 0); | 45 | __fh_size_t __b = __bos(__s, 0); |
| 46 | 46 | ||
| 47 | if (__f < 0 || __f >= FD_SETSIZE || __b < sizeof(fd_set)) | 47 | if (__f < 0 || __f >= FD_SETSIZE || __b < sizeof(fd_set)) |
| 48 | __builtin_trap(); | 48 | __builtin_trap(); |
| @@ -51,7 +51,7 @@ _STI void __fortify_FD_SET(int __f, fd_set * _FORTIFY_POS0 __s) | |||
| 51 | 51 | ||
| 52 | _STI int __fortify_FD_ISSET(int __f, fd_set * _FORTIFY_POS0 __s) | 52 | _STI int __fortify_FD_ISSET(int __f, fd_set * _FORTIFY_POS0 __s) |
| 53 | { | 53 | { |
| 54 | size_t __b = __bos(__s, 0); | 54 | __fh_size_t __b = __bos(__s, 0); |
| 55 | 55 | ||
| 56 | if (__f < 0 || __f >= FD_SETSIZE || __b < sizeof(fd_set)) | 56 | if (__f < 0 || __f >= FD_SETSIZE || __b < sizeof(fd_set)) |
| 57 | __builtin_trap(); | 57 | __builtin_trap(); |
diff --git a/include/sys/socket.h b/include/sys/socket.h index 94cc0c8..b7a8cf8 100644 --- a/include/sys/socket.h +++ b/include/sys/socket.h | |||
| @@ -38,7 +38,7 @@ __access(write_only, 2, 3) | |||
| 38 | _FORTIFY_FN(recv) ssize_t recv(int __f, void * _FORTIFY_POS0 __s, size_t __n, | 38 | _FORTIFY_FN(recv) ssize_t recv(int __f, void * _FORTIFY_POS0 __s, size_t __n, |
| 39 | int __fl) | 39 | int __fl) |
| 40 | { | 40 | { |
| 41 | size_t __b = __bos(__s, 0); | 41 | __fh_size_t __b = __bos(__s, 0); |
| 42 | 42 | ||
| 43 | if (__n > __b) | 43 | if (__n > __b) |
| 44 | __builtin_trap(); | 44 | __builtin_trap(); |
| @@ -50,7 +50,7 @@ _FORTIFY_FN(recvfrom) ssize_t recvfrom(int __f, void * _FORTIFY_POS0 __s, | |||
| 50 | size_t __n, int __fl, | 50 | size_t __n, int __fl, |
| 51 | struct sockaddr *__a, socklen_t *__l) | 51 | struct sockaddr *__a, socklen_t *__l) |
| 52 | { | 52 | { |
| 53 | size_t __b = __bos(__s, 0); | 53 | __fh_size_t __b = __bos(__s, 0); |
| 54 | 54 | ||
| 55 | if (__n > __b) | 55 | if (__n > __b) |
| 56 | __builtin_trap(); | 56 | __builtin_trap(); |
| @@ -61,7 +61,7 @@ __access(read_only, 2, 3) | |||
| 61 | _FORTIFY_FN(send) ssize_t send(int __f, const void * _FORTIFY_POS0 __s, | 61 | _FORTIFY_FN(send) ssize_t send(int __f, const void * _FORTIFY_POS0 __s, |
| 62 | size_t __n, int __fl) | 62 | size_t __n, int __fl) |
| 63 | { | 63 | { |
| 64 | size_t __b = __bos(__s, 0); | 64 | __fh_size_t __b = __bos(__s, 0); |
| 65 | 65 | ||
| 66 | if (__n > __b) | 66 | if (__n > __b) |
| 67 | __builtin_trap(); | 67 | __builtin_trap(); |
| @@ -73,7 +73,7 @@ _FORTIFY_FN(sendto) ssize_t sendto(int __f, const void * _FORTIFY_POS0 __s, | |||
| 73 | size_t __n, int __fl, | 73 | size_t __n, int __fl, |
| 74 | const struct sockaddr *__a, socklen_t __l) | 74 | const struct sockaddr *__a, socklen_t __l) |
| 75 | { | 75 | { |
| 76 | size_t __b = __bos(__s, 0); | 76 | __fh_size_t __b = __bos(__s, 0); |
| 77 | 77 | ||
| 78 | if (__n > __b) | 78 | if (__n > __b) |
| 79 | __builtin_trap(); | 79 | __builtin_trap(); |
diff --git a/include/unistd.h b/include/unistd.h index 38c7c9b..5074d33 100644 --- a/include/unistd.h +++ b/include/unistd.h | |||
| @@ -47,8 +47,8 @@ __diagnose_as_builtin(__builtin_confstr, 1, 2, 3) | |||
| 47 | #endif | 47 | #endif |
| 48 | _FORTIFY_FN(confstr) size_t confstr(int __n, char * _FORTIFY_POS0 __s, size_t __l) | 48 | _FORTIFY_FN(confstr) size_t confstr(int __n, char * _FORTIFY_POS0 __s, size_t __l) |
| 49 | { | 49 | { |
| 50 | size_t __b = __bos(__s, 0); | 50 | __fh_size_t __b = __bos(__s, 0); |
| 51 | size_t __r = __orig_confstr(__n, __s, __b > __l ? __l : __b); | 51 | __fh_size_t __r = __orig_confstr(__n, __s, __b > __l ? __l : __b); |
| 52 | 52 | ||
| 53 | if (__l > __b && __r > __b) | 53 | if (__l > __b && __r > __b) |
| 54 | __builtin_trap(); | 54 | __builtin_trap(); |
| @@ -61,7 +61,7 @@ __diagnose_as_builtin(__builtin_getcwd, 1, 2) | |||
| 61 | #endif | 61 | #endif |
| 62 | _FORTIFY_FN(getcwd) char *getcwd(char * _FORTIFY_POS0 __s, size_t __l) | 62 | _FORTIFY_FN(getcwd) char *getcwd(char * _FORTIFY_POS0 __s, size_t __l) |
| 63 | { | 63 | { |
| 64 | size_t __b = __bos(__s, 0); | 64 | __fh_size_t __b = __bos(__s, 0); |
| 65 | 65 | ||
| 66 | if (__l > __b) | 66 | if (__l > __b) |
| 67 | __builtin_trap(); | 67 | __builtin_trap(); |
| @@ -76,7 +76,7 @@ __diagnose_as_builtin(__builtin_getdomainname, 1, 2) | |||
| 76 | #endif | 76 | #endif |
| 77 | _FORTIFY_FN(getdomainname) int getdomainname(char * _FORTIFY_POS0 __s, size_t __l) | 77 | _FORTIFY_FN(getdomainname) int getdomainname(char * _FORTIFY_POS0 __s, size_t __l) |
| 78 | { | 78 | { |
| 79 | size_t __b = __bos(__s, 0); | 79 | __fh_size_t __b = __bos(__s, 0); |
| 80 | 80 | ||
| 81 | if (__l > __b) | 81 | if (__l > __b) |
| 82 | __builtin_trap(); | 82 | __builtin_trap(); |
| @@ -89,7 +89,7 @@ __diagnose_as_builtin(__builtin_getgroups, 1, 2) | |||
| 89 | #endif | 89 | #endif |
| 90 | _FORTIFY_FN(getgroups) int getgroups(int __l, gid_t * _FORTIFY_POS0 __s) | 90 | _FORTIFY_FN(getgroups) int getgroups(int __l, gid_t * _FORTIFY_POS0 __s) |
| 91 | { | 91 | { |
| 92 | size_t __b = __bos(__s, 0); | 92 | __fh_size_t __b = __bos(__s, 0); |
| 93 | 93 | ||
| 94 | if (__l > 0 && (unsigned)__l > __b / sizeof(gid_t)) | 94 | if (__l > 0 && (unsigned)__l > __b / sizeof(gid_t)) |
| 95 | __builtin_trap(); | 95 | __builtin_trap(); |
| @@ -102,7 +102,7 @@ __diagnose_as_builtin(__builtin_gethostname, 1, 2) | |||
| 102 | #endif | 102 | #endif |
| 103 | _FORTIFY_FN(gethostname) int gethostname(char * _FORTIFY_POS0 __s, size_t __l) | 103 | _FORTIFY_FN(gethostname) int gethostname(char * _FORTIFY_POS0 __s, size_t __l) |
| 104 | { | 104 | { |
| 105 | size_t __b = __bos(__s, 0); | 105 | __fh_size_t __b = __bos(__s, 0); |
| 106 | 106 | ||
| 107 | if (__l > __b) | 107 | if (__l > __b) |
| 108 | __builtin_trap(); | 108 | __builtin_trap(); |
| @@ -115,7 +115,7 @@ __diagnose_as_builtin(__builtin_getlogin_r, 1, 2) | |||
| 115 | #endif | 115 | #endif |
| 116 | _FORTIFY_FN(getlogin_r) int getlogin_r(char * _FORTIFY_POS0 __s, size_t __l) | 116 | _FORTIFY_FN(getlogin_r) int getlogin_r(char * _FORTIFY_POS0 __s, size_t __l) |
| 117 | { | 117 | { |
| 118 | size_t __b = __bos(__s, 0); | 118 | __fh_size_t __b = __bos(__s, 0); |
| 119 | 119 | ||
| 120 | if (__l > __b) | 120 | if (__l > __b) |
| 121 | __builtin_trap(); | 121 | __builtin_trap(); |
| @@ -128,7 +128,7 @@ __diagnose_as_builtin(__builtin_pread, 1, 2, 3, 4) | |||
| 128 | _FORTIFY_FN(pread) ssize_t pread(int __f, void * _FORTIFY_POS0 __s, | 128 | _FORTIFY_FN(pread) ssize_t pread(int __f, void * _FORTIFY_POS0 __s, |
| 129 | size_t __n, off_t __o) | 129 | size_t __n, off_t __o) |
| 130 | { | 130 | { |
| 131 | size_t __b = __bos(__s, 0); | 131 | __fh_size_t __b = __bos(__s, 0); |
| 132 | 132 | ||
| 133 | if (__n > __b) | 133 | if (__n > __b) |
| 134 | __builtin_trap(); | 134 | __builtin_trap(); |
| @@ -141,7 +141,7 @@ __diagnose_as_builtin(__builtin_read, 1, 2, 3) | |||
| 141 | #endif | 141 | #endif |
| 142 | _FORTIFY_FN(read) ssize_t read(int __f, void * _FORTIFY_POS0 __s, size_t __n) | 142 | _FORTIFY_FN(read) ssize_t read(int __f, void * _FORTIFY_POS0 __s, size_t __n) |
| 143 | { | 143 | { |
| 144 | size_t __b = __bos(__s, 0); | 144 | __fh_size_t __b = __bos(__s, 0); |
| 145 | 145 | ||
| 146 | if (__n > __b) | 146 | if (__n > __b) |
| 147 | __builtin_trap(); | 147 | __builtin_trap(); |
| @@ -155,7 +155,7 @@ __diagnose_as_builtin(__builtin_readlink, 1, 2, 3) | |||
| 155 | _FORTIFY_FN(readlink) ssize_t readlink(const char *__p, | 155 | _FORTIFY_FN(readlink) ssize_t readlink(const char *__p, |
| 156 | char * _FORTIFY_POS0 __s, size_t __n) | 156 | char * _FORTIFY_POS0 __s, size_t __n) |
| 157 | { | 157 | { |
| 158 | size_t __b = __bos(__s, 0); | 158 | __fh_size_t __b = __bos(__s, 0); |
| 159 | 159 | ||
| 160 | if (__n > __b) | 160 | if (__n > __b) |
| 161 | __builtin_trap(); | 161 | __builtin_trap(); |
| @@ -169,7 +169,7 @@ __diagnose_as_builtin(__builtin_readlinkat, 1, 2, 3, 4) | |||
| 169 | _FORTIFY_FN(readlinkat) ssize_t readlinkat(int __f, const char *__p, | 169 | _FORTIFY_FN(readlinkat) ssize_t readlinkat(int __f, const char *__p, |
| 170 | char * _FORTIFY_POS0 __s, size_t __n) | 170 | char * _FORTIFY_POS0 __s, size_t __n) |
| 171 | { | 171 | { |
| 172 | size_t __b = __bos(__s, 0); | 172 | __fh_size_t __b = __bos(__s, 0); |
| 173 | 173 | ||
| 174 | if (__n > __b) | 174 | if (__n > __b) |
| 175 | __builtin_trap(); | 175 | __builtin_trap(); |
| @@ -183,7 +183,7 @@ __diagnose_as_builtin(__builtin_ttyname_r, 1, 2, 3) | |||
| 183 | _FORTIFY_FN(ttyname_r) int ttyname_r(int __f, char * _FORTIFY_POS0 __s, | 183 | _FORTIFY_FN(ttyname_r) int ttyname_r(int __f, char * _FORTIFY_POS0 __s, |
| 184 | size_t __n) | 184 | size_t __n) |
| 185 | { | 185 | { |
| 186 | size_t __b = __bos(__s, 0); | 186 | __fh_size_t __b = __bos(__s, 0); |
| 187 | 187 | ||
| 188 | if (__n > __b) | 188 | if (__n > __b) |
| 189 | __builtin_trap(); | 189 | __builtin_trap(); |
| @@ -197,7 +197,7 @@ __diagnose_as_builtin(__builtin_write, 1, 2, 3) | |||
| 197 | _FORTIFY_FN(write) ssize_t write(int __f, const void * _FORTIFY_POS0 __s, | 197 | _FORTIFY_FN(write) ssize_t write(int __f, const void * _FORTIFY_POS0 __s, |
| 198 | size_t __n) | 198 | size_t __n) |
| 199 | { | 199 | { |
| 200 | size_t __b = __bos(__s, 0); | 200 | __fh_size_t __b = __bos(__s, 0); |
| 201 | 201 | ||
| 202 | if (__n > __b) | 202 | if (__n > __b) |
| 203 | __builtin_trap(); | 203 | __builtin_trap(); |
| @@ -210,7 +210,7 @@ __diagnose_as_builtin(__builtin_pwrite, 1, 2, 3, 4) | |||
| 210 | _FORTIFY_FN(pwrite) ssize_t pwrite(int __f, const void * _FORTIFY_POS0 __s, | 210 | _FORTIFY_FN(pwrite) ssize_t pwrite(int __f, const void * _FORTIFY_POS0 __s, |
| 211 | size_t __n, off_t __o) | 211 | size_t __n, off_t __o) |
| 212 | { | 212 | { |
| 213 | size_t __b = __bos(__s, 0); | 213 | __fh_size_t __b = __bos(__s, 0); |
| 214 | 214 | ||
| 215 | if (__n > __b) | 215 | if (__n > __b) |
| 216 | __builtin_trap(); | 216 | __builtin_trap(); |
diff --git a/include/wchar.h b/include/wchar.h index e696ddf..7a2a192 100644 --- a/include/wchar.h +++ b/include/wchar.h | |||
| @@ -20,18 +20,6 @@ | |||
| 20 | #if !defined(__cplusplus) && !defined(__clang__) | 20 | #if !defined(__cplusplus) && !defined(__clang__) |
| 21 | __extension__ | 21 | __extension__ |
| 22 | #endif | 22 | #endif |
| 23 | #include_next <limits.h> | ||
| 24 | #if !defined(__cplusplus) && !defined(__clang__) | ||
| 25 | __extension__ | ||
| 26 | #endif | ||
| 27 | #include_next <stdlib.h> | ||
| 28 | #if !defined(__cplusplus) && !defined(__clang__) | ||
| 29 | __extension__ | ||
| 30 | #endif | ||
| 31 | #include_next <string.h> | ||
| 32 | #if !defined(__cplusplus) && !defined(__clang__) | ||
| 33 | __extension__ | ||
| 34 | #endif | ||
| 35 | #include_next <wchar.h> | 23 | #include_next <wchar.h> |
| 36 | 24 | ||
| 37 | #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 | 25 | #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 |
| @@ -43,15 +31,12 @@ extern "C" { | |||
| 43 | 31 | ||
| 44 | #undef fgetws | 32 | #undef fgetws |
| 45 | #undef mbsrtowcs | 33 | #undef mbsrtowcs |
| 46 | #undef mbstowcs | ||
| 47 | #undef wcrtomb | 34 | #undef wcrtomb |
| 48 | #undef wcscat | 35 | #undef wcscat |
| 49 | #undef wcscpy | 36 | #undef wcscpy |
| 50 | #undef wcsncat | 37 | #undef wcsncat |
| 51 | #undef wcsncpy | 38 | #undef wcsncpy |
| 52 | #undef wcsrtombs | 39 | #undef wcsrtombs |
| 53 | #undef wcstombs | ||
| 54 | #undef wctomb | ||
| 55 | #undef wmemcpy | 40 | #undef wmemcpy |
| 56 | #undef wmemmove | 41 | #undef wmemmove |
| 57 | #undef wmemset | 42 | #undef wmemset |
| @@ -62,9 +47,9 @@ __diagnose_as_builtin(__builtin_fgetws, 1, 2, 3) | |||
| 62 | _FORTIFY_FN(fgetws) wchar_t *fgetws(wchar_t * _FORTIFY_POS0 __s, | 47 | _FORTIFY_FN(fgetws) wchar_t *fgetws(wchar_t * _FORTIFY_POS0 __s, |
| 63 | int __n, FILE *__f) | 48 | int __n, FILE *__f) |
| 64 | { | 49 | { |
| 65 | size_t __b = __bos(__s, 0); | 50 | __fh_size_t __b = __bos(__s, 0); |
| 66 | 51 | ||
| 67 | if ((size_t)__n > __b / sizeof(wchar_t)) | 52 | if ((__fh_size_t)__n > __b / sizeof(wchar_t)) |
| 68 | __builtin_trap(); | 53 | __builtin_trap(); |
| 69 | return __orig_fgetws(__s, __n, __f); | 54 | return __orig_fgetws(__s, __n, __f); |
| 70 | } | 55 | } |
| @@ -79,17 +64,17 @@ _FORTIFY_FN(mbsnrtowcs) size_t mbsnrtowcs(wchar_t * _FORTIFY_POS0 __d, | |||
| 79 | const char **__s, size_t __n, | 64 | const char **__s, size_t __n, |
| 80 | size_t __wn, mbstate_t *__st) | 65 | size_t __wn, mbstate_t *__st) |
| 81 | { | 66 | { |
| 82 | size_t __b = __bos(__d, 0); | 67 | __fh_size_t __b = __bos(__d, 0); |
| 83 | size_t __r; | 68 | __fh_size_t __r; |
| 84 | 69 | ||
| 85 | if (__wn > __n / sizeof(wchar_t)) { | 70 | if (__wn > __n / sizeof(wchar_t)) { |
| 86 | __b /= sizeof(wchar_t); | 71 | __b /= sizeof(wchar_t); |
| 87 | __r = __orig_mbsnrtowcs(__d, __s, __n, __wn > __b ? __b : __wn, __st); | 72 | __r = __orig_mbsnrtowcs(__d, __s, __n, __wn > __b ? __b : __wn, __st); |
| 88 | if (__b < __wn && __d && *__s && __r != (size_t)-1) | 73 | if (__b < __wn && __d && *__s && __r != (__fh_size_t)-1) |
| 89 | __builtin_trap(); | 74 | __builtin_trap(); |
| 90 | } else { | 75 | } else { |
| 91 | __r = __orig_mbsnrtowcs(__d, __s, __n > __b ? __b : __n, __wn, __st); | 76 | __r = __orig_mbsnrtowcs(__d, __s, __n > __b ? __b : __n, __wn, __st); |
| 92 | if (__b < __n && __d && *__s && __r != (size_t)-1) | 77 | if (__b < __n && __d && *__s && __r != (__fh_size_t)-1) |
| 93 | __builtin_trap(); | 78 | __builtin_trap(); |
| 94 | } | 79 | } |
| 95 | return __r; | 80 | return __r; |
| @@ -103,29 +88,16 @@ _FORTIFY_FN(mbsrtowcs) size_t mbsrtowcs(wchar_t * _FORTIFY_POS0 __d, | |||
| 103 | const char **__s, size_t __wn, | 88 | const char **__s, size_t __wn, |
| 104 | mbstate_t *__st) | 89 | mbstate_t *__st) |
| 105 | { | 90 | { |
| 106 | size_t __b = __bos(__d, 0); | 91 | __fh_size_t __b = __bos(__d, 0); |
| 107 | size_t __r; | 92 | __fh_size_t __r; |
| 108 | 93 | ||
| 109 | __b /= sizeof(wchar_t); | 94 | __b /= sizeof(wchar_t); |
| 110 | __r = __orig_mbsrtowcs(__d, __s, __wn > __b ? __b : __wn, __st); | 95 | __r = __orig_mbsrtowcs(__d, __s, __wn > __b ? __b : __wn, __st); |
| 111 | if (__b < __wn && __d && *__s && __r != (size_t)-1) | 96 | if (__b < __wn && __d && *__s && __r != (__fh_size_t)-1) |
| 112 | __builtin_trap(); | 97 | __builtin_trap(); |
| 113 | return __r; | 98 | return __r; |
| 114 | } | 99 | } |
| 115 | 100 | ||
| 116 | #if __has_builtin(__builtin_mbstowcs) | ||
| 117 | __diagnose_as_builtin(__builtin_mbstowcs, 1, 2, 3) | ||
| 118 | #endif | ||
| 119 | _FORTIFY_FN(mbstowcs) size_t mbstowcs(wchar_t * _FORTIFY_POS0 __ws, | ||
| 120 | const char *__s, size_t __wn) | ||
| 121 | { | ||
| 122 | size_t __b = __bos(__ws, 0); | ||
| 123 | |||
| 124 | if (__ws && __wn > __b / sizeof(wchar_t)) | ||
| 125 | __builtin_trap(); | ||
| 126 | return __orig_mbstowcs(__ws, __s, __wn); | ||
| 127 | } | ||
| 128 | |||
| 129 | /* FIXME clang */ | 101 | /* FIXME clang */ |
| 130 | #ifndef __clang__ | 102 | #ifndef __clang__ |
| 131 | #if __has_builtin(__builtin_wcrtomb) | 103 | #if __has_builtin(__builtin_wcrtomb) |
| @@ -133,12 +105,13 @@ __diagnose_as_builtin(__builtin_wcrtomb, 1, 2, 3) | |||
| 133 | #endif | 105 | #endif |
| 134 | _FORTIFY_FN(wcrtomb) size_t wcrtomb(char * __s, wchar_t __w, mbstate_t *__st) | 106 | _FORTIFY_FN(wcrtomb) size_t wcrtomb(char * __s, wchar_t __w, mbstate_t *__st) |
| 135 | { | 107 | { |
| 136 | if (__s && MB_LEN_MAX > __bos(__s, 2)) { | 108 | // In glibc, MB_LEN_MAX is typically 16 (6 in glibc versions earlier than 2.2) |
| 137 | char __buf[MB_LEN_MAX]; | 109 | if (__s && 16 > __bos(__s, 2)) { |
| 138 | size_t __r; | 110 | char __buf[16]; |
| 111 | __fh_size_t __r; | ||
| 139 | 112 | ||
| 140 | __r = __orig_wcrtomb(__buf, __w, __st); | 113 | __r = __orig_wcrtomb(__buf, __w, __st); |
| 141 | if (__r == (size_t)-1) | 114 | if (__r == (__fh_size_t)-1) |
| 142 | return __r; | 115 | return __r; |
| 143 | if (__r > __bos(__s, 0)) | 116 | if (__r > __bos(__s, 0)) |
| 144 | __builtin_trap(); | 117 | __builtin_trap(); |
| @@ -155,7 +128,7 @@ __diagnose_as_builtin(__builtin_wcscat, 1, 2) | |||
| 155 | _FORTIFY_FN(wcscat) wchar_t *wcscat(wchar_t * _FORTIFY_POS0 __d, | 128 | _FORTIFY_FN(wcscat) wchar_t *wcscat(wchar_t * _FORTIFY_POS0 __d, |
| 156 | const wchar_t *__s) | 129 | const wchar_t *__s) |
| 157 | { | 130 | { |
| 158 | size_t __b = __bos(__d, 0); | 131 | __fh_size_t __b = __bos(__d, 0); |
| 159 | 132 | ||
| 160 | if (wcslen(__s) + wcslen(__d) + 1 > __b / sizeof(wchar_t)) | 133 | if (wcslen(__s) + wcslen(__d) + 1 > __b / sizeof(wchar_t)) |
| 161 | __builtin_trap(); | 134 | __builtin_trap(); |
| @@ -168,7 +141,7 @@ __diagnose_as_builtin(__builtin_wcscpy, 1, 2) | |||
| 168 | _FORTIFY_FN(wcscpy) wchar_t *wcscpy(wchar_t * _FORTIFY_POS0 __d, | 141 | _FORTIFY_FN(wcscpy) wchar_t *wcscpy(wchar_t * _FORTIFY_POS0 __d, |
| 169 | const wchar_t *__s) | 142 | const wchar_t *__s) |
| 170 | { | 143 | { |
| 171 | size_t __b = __bos(__d, 0); | 144 | __fh_size_t __b = __bos(__d, 0); |
| 172 | 145 | ||
| 173 | if (wcslen(__s) + 1 > __b / sizeof(wchar_t)) | 146 | if (wcslen(__s) + 1 > __b / sizeof(wchar_t)) |
| 174 | __builtin_trap(); | 147 | __builtin_trap(); |
| @@ -181,8 +154,8 @@ __diagnose_as_builtin(__builtin_wcsncat, 1, 2, 3) | |||
| 181 | _FORTIFY_FN(wcsncat) wchar_t *wcsncat(wchar_t * _FORTIFY_POS0 __d, | 154 | _FORTIFY_FN(wcsncat) wchar_t *wcsncat(wchar_t * _FORTIFY_POS0 __d, |
| 182 | const wchar_t *__s, size_t __n) | 155 | const wchar_t *__s, size_t __n) |
| 183 | { | 156 | { |
| 184 | size_t __b = __bos(__d, 0); | 157 | __fh_size_t __b = __bos(__d, 0); |
| 185 | size_t __sl, __dl; | 158 | __fh_size_t __sl, __dl; |
| 186 | 159 | ||
| 187 | if (__n > __b / sizeof(wchar_t)) { | 160 | if (__n > __b / sizeof(wchar_t)) { |
| 188 | __sl = wcslen(__s); | 161 | __sl = wcslen(__s); |
| @@ -201,7 +174,7 @@ __diagnose_as_builtin(__builtin_wcsncpy, 1, 2, 3) | |||
| 201 | _FORTIFY_FN(wcsncpy) wchar_t *wcsncpy(wchar_t * _FORTIFY_POS0 __d, | 174 | _FORTIFY_FN(wcsncpy) wchar_t *wcsncpy(wchar_t * _FORTIFY_POS0 __d, |
| 202 | const wchar_t *__s, size_t __n) | 175 | const wchar_t *__s, size_t __n) |
| 203 | { | 176 | { |
| 204 | size_t __b = __bos(__d, 0); | 177 | __fh_size_t __b = __bos(__d, 0); |
| 205 | 178 | ||
| 206 | if (__n > __b / sizeof(wchar_t)) | 179 | if (__n > __b / sizeof(wchar_t)) |
| 207 | __builtin_trap(); | 180 | __builtin_trap(); |
| @@ -218,17 +191,17 @@ _FORTIFY_FN(wcsnrtombs) size_t wcsnrtombs(char * _FORTIFY_POS0 __d, | |||
| 218 | const wchar_t **__s, size_t __wn, | 191 | const wchar_t **__s, size_t __wn, |
| 219 | size_t __n, mbstate_t *__st) | 192 | size_t __n, mbstate_t *__st) |
| 220 | { | 193 | { |
| 221 | size_t __b = __bos(__d, 0); | 194 | __fh_size_t __b = __bos(__d, 0); |
| 222 | size_t __r; | 195 | __fh_size_t __r; |
| 223 | 196 | ||
| 224 | if (__wn > __n / sizeof(wchar_t)) { | 197 | if (__wn > __n / sizeof(wchar_t)) { |
| 225 | __b /= sizeof(wchar_t); | 198 | __b /= sizeof(wchar_t); |
| 226 | __r = __orig_wcsnrtombs(__d, __s, __wn > __b ? __b : __wn, __n, __st); | 199 | __r = __orig_wcsnrtombs(__d, __s, __wn > __b ? __b : __wn, __n, __st); |
| 227 | if (__b < __wn && __d && *__s && __r != (size_t)-1) | 200 | if (__b < __wn && __d && *__s && __r != (__fh_size_t)-1) |
| 228 | __builtin_trap(); | 201 | __builtin_trap(); |
| 229 | } else { | 202 | } else { |
| 230 | __r = __orig_wcsnrtombs(__d, __s, __wn, __n > __b ? __b : __n, __st); | 203 | __r = __orig_wcsnrtombs(__d, __s, __wn, __n > __b ? __b : __n, __st); |
| 231 | if (__b < __n && __d && *__s && __r != (size_t)-1) | 204 | if (__b < __n && __d && *__s && __r != (__fh_size_t)-1) |
| 232 | __builtin_trap(); | 205 | __builtin_trap(); |
| 233 | } | 206 | } |
| 234 | return __r; | 207 | return __r; |
| @@ -242,40 +215,29 @@ _FORTIFY_FN(wcsrtombs) size_t wcsrtombs(char * _FORTIFY_POS0 __d, | |||
| 242 | const wchar_t **__s, size_t __n, | 215 | const wchar_t **__s, size_t __n, |
| 243 | mbstate_t *__st) | 216 | mbstate_t *__st) |
| 244 | { | 217 | { |
| 245 | size_t __b = __bos(__d, 0); | 218 | __fh_size_t __b = __bos(__d, 0); |
| 246 | size_t __r; | 219 | __fh_size_t __r; |
| 247 | 220 | ||
| 248 | __r = __orig_wcsrtombs(__d, __s, __n > __b ? __b : __n, __st); | 221 | __r = __orig_wcsrtombs(__d, __s, __n > __b ? __b : __n, __st); |
| 249 | if (__b < __n && __d && *__s && __r != (size_t)-1) | 222 | if (__b < __n && __d && *__s && __r != (__fh_size_t)-1) |
| 250 | __builtin_trap(); | 223 | __builtin_trap(); |
| 251 | return __r; | 224 | return __r; |
| 252 | } | 225 | } |
| 253 | 226 | ||
| 254 | __access(write_only, 1, 3) | 227 | #ifdef MB_CUR_MAX |
| 255 | #if __has_builtin(__builtin_wcstombs) | 228 | #undef wctomb |
| 256 | __diagnose_as_builtin(__builtin_wcstombs, 1, 2, 3) | ||
| 257 | #endif | ||
| 258 | _FORTIFY_FN(wcstombs) size_t wcstombs(char * _FORTIFY_POS0 __s, | ||
| 259 | const wchar_t *__ws, size_t __n) | ||
| 260 | { | ||
| 261 | size_t __b = __bos(__s, 0); | ||
| 262 | |||
| 263 | if (__s && __n > __b) | ||
| 264 | __builtin_trap(); | ||
| 265 | return __orig_wcstombs(__s, __ws, __n); | ||
| 266 | } | ||
| 267 | |||
| 268 | #if __has_builtin(__builtin_wctomb) | 229 | #if __has_builtin(__builtin_wctomb) |
| 269 | __diagnose_as_builtin(__builtin_wctomb, 1, 2) | 230 | __diagnose_as_builtin(__builtin_wctomb, 1, 2) |
| 270 | #endif | 231 | #endif |
| 271 | _FORTIFY_FN(wctomb) int wctomb(char * _FORTIFY_POS0 __s, wchar_t __w) | 232 | _FORTIFY_FN(wctomb) int wctomb(char * _FORTIFY_POS0 __s, wchar_t __w) |
| 272 | { | 233 | { |
| 273 | size_t __b = __bos(__s, 0); | 234 | __fh_size_t __b = __bos(__s, 0); |
| 274 | 235 | ||
| 275 | if (__s && MB_LEN_MAX > __b && MB_CUR_MAX > __b) | 236 | if (__s && 16 > __b && MB_CUR_MAX > __b) |
| 276 | __builtin_trap(); | 237 | __builtin_trap(); |
| 277 | return __orig_wctomb(__s, __w); | 238 | return __orig_wctomb(__s, __w); |
| 278 | } | 239 | } |
| 240 | #endif // MB_CUR_MAX | ||
| 279 | 241 | ||
| 280 | #if __has_builtin(__builtin_wmemcpy) | 242 | #if __has_builtin(__builtin_wmemcpy) |
| 281 | __diagnose_as_builtin(__builtin_wmemcpy, 1, 2, 3) | 243 | __diagnose_as_builtin(__builtin_wmemcpy, 1, 2, 3) |
| @@ -283,7 +245,7 @@ __diagnose_as_builtin(__builtin_wmemcpy, 1, 2, 3) | |||
| 283 | _FORTIFY_FN(wmemcpy) wchar_t *wmemcpy(wchar_t * _FORTIFY_POS0 __d, | 245 | _FORTIFY_FN(wmemcpy) wchar_t *wmemcpy(wchar_t * _FORTIFY_POS0 __d, |
| 284 | const wchar_t *__s, size_t __n) | 246 | const wchar_t *__s, size_t __n) |
| 285 | { | 247 | { |
| 286 | size_t __b = __bos(__d, 0); | 248 | __fh_size_t __b = __bos(__d, 0); |
| 287 | 249 | ||
| 288 | if (__n > __b / sizeof(wchar_t)) | 250 | if (__n > __b / sizeof(wchar_t)) |
| 289 | __builtin_trap(); | 251 | __builtin_trap(); |
| @@ -296,7 +258,7 @@ __diagnose_as_builtin(__builtin_wmemmove, 1, 2, 3) | |||
| 296 | _FORTIFY_FN(wmemmove) wchar_t *wmemmove(wchar_t * _FORTIFY_POS0 __d, | 258 | _FORTIFY_FN(wmemmove) wchar_t *wmemmove(wchar_t * _FORTIFY_POS0 __d, |
| 297 | const wchar_t *__s, size_t __n) | 259 | const wchar_t *__s, size_t __n) |
| 298 | { | 260 | { |
| 299 | size_t __b = __bos(__d, 0); | 261 | __fh_size_t __b = __bos(__d, 0); |
| 300 | 262 | ||
| 301 | if (__n > __b / sizeof(wchar_t)) | 263 | if (__n > __b / sizeof(wchar_t)) |
| 302 | __builtin_trap(); | 264 | __builtin_trap(); |
| @@ -309,7 +271,7 @@ __diagnose_as_builtin(__builtin_wmemset, 1, 2, 3) | |||
| 309 | _FORTIFY_FN(wmemset) wchar_t *wmemset(wchar_t * _FORTIFY_POS0 __s, | 271 | _FORTIFY_FN(wmemset) wchar_t *wmemset(wchar_t * _FORTIFY_POS0 __s, |
| 310 | wchar_t __c, size_t __n) | 272 | wchar_t __c, size_t __n) |
| 311 | { | 273 | { |
| 312 | size_t __b = __bos(__s, 0); | 274 | __fh_size_t __b = __bos(__s, 0); |
| 313 | 275 | ||
| 314 | if (__n > __b / sizeof(wchar_t)) | 276 | if (__n > __b / sizeof(wchar_t)) |
| 315 | __builtin_trap(); | 277 | __builtin_trap(); |
