fortify-headers

standalone fortify-source implementation
git clone git://git.2f30.org/fortify-headers.git
Log | Files | Refs | README | LICENSE

commit 1cd5461a5375207602f2cbdfd9a50a9b751cb7c8
parent a9ee1d2743acb0b2903db87c0a241c0a569cfc4e
Author: Trutz Behn <me@trutz.be>
Date:   Wed Jun  3 19:27:01 +0200

Use namespace-safe macro, param and variable names

Diffstat:
include/fortify-headers.h | 2+-
include/poll.h | 18+++++++++---------
include/stdio.h | 78+++++++++++++++++++++++++++++++++++++++---------------------------------------
include/stdlib.h | 12++++++------
include/string.h | 124++++++++++++++++++++++++++++++++++++++++----------------------------------------
include/strings.h | 18+++++++++---------
include/sys/select.h | 16++++++++--------
include/sys/socket.h | 36++++++++++++++++++------------------
include/unistd.h | 96++++++++++++++++++++++++++++++++++++++++----------------------------------------
include/wchar.h | 182++++++++++++++++++++++++++++++++++++++++----------------------------------------
10 files changed, 291 insertions(+), 291 deletions(-)
diff --git a/include/fortify-headers.h b/include/fortify-headers.h @@ -18,7 +18,7 @@ #define _FORTIFY_STR(s) #s #define _FORTIFY_ORIG(p,fn) __typeof__(fn) __orig_##fn __asm__(_FORTIFY_STR(p) #fn) -#define fortify_fn(fn) _FORTIFY_ORIG(__USER_LABEL_PREFIX__,fn); \ +#define _FORTIFY_FN(fn) _FORTIFY_ORIG(__USER_LABEL_PREFIX__,fn); \ extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) #endif diff --git a/include/poll.h b/include/poll.h @@ -27,25 +27,25 @@ extern "C" { #undef poll -fortify_fn(poll) int poll(struct pollfd *fds, nfds_t nfds, int timeout) +_FORTIFY_FN(poll) int poll(struct pollfd *__f, nfds_t __n, int __s) { - __typeof__(sizeof 0) bos = __builtin_object_size(fds, 0); + __typeof__(sizeof 0) __b = __builtin_object_size(__f, 0); - if (nfds > bos / sizeof(struct pollfd)) + if (__n > __b / sizeof(struct pollfd)) __builtin_trap(); - return __orig_poll(fds, nfds, timeout); + return __orig_poll(__f, __n, __s); } #ifdef _GNU_SOURCE #undef ppoll -fortify_fn(ppoll) int ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout, - const sigset_t *mask) +_FORTIFY_FN(ppoll) int ppoll(struct pollfd *__f, nfds_t __n, const struct timespec *__s, + const sigset_t *__m) { - __typeof__(sizeof 0) bos = __builtin_object_size(fds, 0); + __typeof__(sizeof 0) __b = __builtin_object_size(__f, 0); - if (nfds > bos / sizeof(struct pollfd)) + if (__n > __b / sizeof(struct pollfd)) __builtin_trap(); - return __orig_ppoll(fds, nfds, timeout, mask); + return __orig_ppoll(__f, __n, __s, __m); } #endif diff --git a/include/stdio.h b/include/stdio.h @@ -33,84 +33,84 @@ extern "C" { #undef snprintf #undef sprintf -fortify_fn(fgets) char *fgets(char *s, int n, FILE *fp) +_FORTIFY_FN(fgets) char *fgets(char *__s, int __n, FILE *__f) { - size_t bos = __builtin_object_size(s, 0); + size_t __b = __builtin_object_size(__s, 0); - if ((size_t)n > bos) + if ((size_t)__n > __b) __builtin_trap(); - return __orig_fgets(s, n, fp); + return __orig_fgets(__s, __n, __f); } -fortify_fn(fread) size_t fread(void *dst, size_t n, size_t nmemb, FILE *fp) +_FORTIFY_FN(fread) size_t fread(void *__d, size_t __n, size_t __m, FILE *__f) { - size_t bos = __builtin_object_size(dst, 0); + size_t __b = __builtin_object_size(__d, 0); - if (n != 0 && (n * nmemb) / n != nmemb) + if (__n != 0 && (__n * __m) / __n != __m) __builtin_trap(); - if (n * nmemb > bos) + if (__n * __m > __b) __builtin_trap(); - return __orig_fread(dst, n, nmemb, fp); + return __orig_fread(__d, __n, __m, __f); } -fortify_fn(fwrite) size_t fwrite(const void *dst, size_t n, size_t nmemb, FILE *fp) +_FORTIFY_FN(fwrite) size_t fwrite(const void *__d, size_t __n, size_t __m, FILE *__f) { - size_t bos = __builtin_object_size(dst, 0); + size_t __b = __builtin_object_size(__d, 0); - if (n != 0 && (n * nmemb) / n != nmemb) + if (__n != 0 && (__n * __m) / __n != __m) __builtin_trap(); - if (n * nmemb > bos) + if (__n * __m > __b) __builtin_trap(); - return __orig_fwrite(dst, n, nmemb, fp); + return __orig_fwrite(__d, __n, __m, __f); } -fortify_fn(vsnprintf) int vsnprintf(char *s, size_t n, const char *fmt, - __builtin_va_list ap) +_FORTIFY_FN(vsnprintf) int vsnprintf(char *__s, size_t __n, const char *__f, + __builtin_va_list __v) { - size_t bos = __builtin_object_size(s, 0); + size_t __b = __builtin_object_size(__s, 0); - if (n > bos) + if (__n > __b) __builtin_trap(); - return __orig_vsnprintf(s, n, fmt, ap); + return __orig_vsnprintf(__s, __n, __f, __v); } -fortify_fn(vsprintf) int vsprintf(char *s, const char *fmt, __builtin_va_list ap) +_FORTIFY_FN(vsprintf) int vsprintf(char *__s, const char *__f, __builtin_va_list __v) { - size_t bos = __builtin_object_size(s, 0); - int r; + size_t __b = __builtin_object_size(__s, 0); + int __r; - if (bos != (size_t)-1) { - r = __orig_vsnprintf(s, bos, fmt, ap); - if (r != -1 && (size_t)r >= bos) + if (__b != (size_t)-1) { + __r = __orig_vsnprintf(__s, __b, __f, __v); + if (__r != -1 && (size_t)__r >= __b) __builtin_trap(); } else { - r = __orig_vsprintf(s, fmt, ap); + __r = __orig_vsprintf(__s, __f, __v); } - return r; + return __r; } -fortify_fn(snprintf) int snprintf(char *s, size_t n, const char *fmt, ...) +_FORTIFY_FN(snprintf) int snprintf(char *__s, size_t __n, const char *__f, ...) { - size_t bos = __builtin_object_size(s, 0); + size_t __b = __builtin_object_size(__s, 0); - if (n > bos) + if (__n > __b) __builtin_trap(); - return __orig_snprintf(s, n, fmt, __builtin_va_arg_pack()); + return __orig_snprintf(__s, __n, __f, __builtin_va_arg_pack()); } -fortify_fn(sprintf) int sprintf(char *s, const char *fmt, ...) +_FORTIFY_FN(sprintf) int sprintf(char *__s, const char *__f, ...) { - size_t bos = __builtin_object_size(s, 0); - int r; + size_t __b = __builtin_object_size(__s, 0); + int __r; - if (bos != (size_t)-1) { - r = __orig_snprintf(s, bos, fmt, __builtin_va_arg_pack()); - if (r != -1 && (size_t)r >= bos) + if (__b != (size_t)-1) { + __r = __orig_snprintf(__s, __b, __f, __builtin_va_arg_pack()); + if (__r != -1 && (size_t)__r >= __b) __builtin_trap(); } else { - r = __orig_sprintf(s, fmt, __builtin_va_arg_pack()); + __r = __orig_sprintf(__s, __f, __builtin_va_arg_pack()); } - return r; + return __r; } #ifdef __cplusplus diff --git a/include/stdlib.h b/include/stdlib.h @@ -31,20 +31,20 @@ extern "C" { #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) #undef realpath -fortify_fn(realpath) char *realpath(const char *path, char *resolved) +_FORTIFY_FN(realpath) char *realpath(const char *__p, char *__r) { - size_t bos; + size_t __b; - if (resolved) { + if (__r) { #ifndef PATH_MAX #error PATH_MAX unset. A fortified realpath will not work. #else - bos = __builtin_object_size(resolved, 0); - if (PATH_MAX > bos) + __b = __builtin_object_size(__r, 0); + if (PATH_MAX > __b) __builtin_trap(); #endif } - return __orig_realpath(path, resolved); + return __orig_realpath(__p, __r); } #endif diff --git a/include/string.h b/include/string.h @@ -33,141 +33,141 @@ extern "C" { #undef strncat #undef strncpy -fortify_fn(memcpy) void *memcpy(void *dst, const void *src, size_t n) +_FORTIFY_FN(memcpy) void *memcpy(void *__od, const void *__os, size_t __n) { - size_t bos_dst = __builtin_object_size(dst, 0); - size_t bos_src = __builtin_object_size(src, 0); - char *d = (char *)dst; - const char *s = (const char *)src; + size_t __bd = __builtin_object_size(__od, 0); + size_t __bs = __builtin_object_size(__os, 0); + char *__d = (char *)__od; + const char *__s = (const char *)__os; /* trap if pointers are overlapping but not if dst == src. * gcc seems to like to generate code that relies on dst == src */ - if ((d < s && d + n > s) || - (s < d && s + n > d)) + if ((__d < __s && __d + __n > __s) || + (__s < __d && __s + __n > __d)) __builtin_trap(); - if (n > bos_dst || n > bos_src) + if (__n > __bd || __n > __bs) __builtin_trap(); - return __orig_memcpy(dst, src, n); + return __orig_memcpy(__od, __os, __n); } -fortify_fn(memmove) void *memmove(void *dst, const void *src, size_t n) +_FORTIFY_FN(memmove) void *memmove(void *__d, const void *__s, size_t __n) { - size_t bos_dst = __builtin_object_size(dst, 0); - size_t bos_src = __builtin_object_size(src, 0); + size_t __bd = __builtin_object_size(__d, 0); + size_t __bs = __builtin_object_size(__s, 0); - if (n > bos_dst || n > bos_src) + if (__n > __bd || __n > __bs) __builtin_trap(); - return __orig_memmove(dst, src, n); + return __orig_memmove(__d, __s, __n); } -fortify_fn(memset) void *memset(void *dst, int c, size_t n) +_FORTIFY_FN(memset) void *memset(void *__d, int __c, size_t __n) { - size_t bos = __builtin_object_size(dst, 0); + size_t __b = __builtin_object_size(__d, 0); - if (n > bos) + if (__n > __b) __builtin_trap(); - return __orig_memset(dst, c, n); + return __orig_memset(__d, __c, __n); } #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ || defined(_BSD_SOURCE) #undef stpcpy -fortify_fn(stpcpy) char *stpcpy(char *dst, const char *src) +_FORTIFY_FN(stpcpy) char *stpcpy(char *__d, const char *__s) { - size_t bos = __builtin_object_size(dst, 0); + size_t __b = __builtin_object_size(__d, 0); - if (strlen(src) + 1 > bos) + if (strlen(__s) + 1 > __b) __builtin_trap(); - return __orig_stpcpy(dst, src); + return __orig_stpcpy(__d, __s); } #undef stpncpy -fortify_fn(stpncpy) char *stpncpy(char *dst, const char *src, size_t n) +_FORTIFY_FN(stpncpy) char *stpncpy(char *__d, const char *__s, size_t __n) { - size_t bos = __builtin_object_size(dst, 0); + size_t __b = __builtin_object_size(__d, 0); - if (n > bos) + if (__n > __b) __builtin_trap(); - return __orig_stpncpy(dst, src, n); + return __orig_stpncpy(__d, __s, __n); } #endif -fortify_fn(strcat) char *strcat(char *dst, const char *src) +_FORTIFY_FN(strcat) char *strcat(char *__d, const char *__s) { - size_t bos = __builtin_object_size(dst, 0); + size_t __b = __builtin_object_size(__d, 0); - if (strlen(src) + strlen(dst) + 1 > bos) + if (strlen(__s) + strlen(__d) + 1 > __b) __builtin_trap(); - return __orig_strcat(dst, src); + return __orig_strcat(__d, __s); } -fortify_fn(strcpy) char *strcpy(char *dst, const char *src) +_FORTIFY_FN(strcpy) char *strcpy(char *__d, const char *__s) { - size_t bos = __builtin_object_size(dst, 0); + size_t __b = __builtin_object_size(__d, 0); - if (strlen(src) + 1 > bos) + if (strlen(__s) + 1 > __b) __builtin_trap(); - return __orig_strcpy(dst, src); + return __orig_strcpy(__d, __s); } -fortify_fn(strncat) char *strncat(char *dst, const char *src, size_t n) +_FORTIFY_FN(strncat) char *strncat(char *__d, const char *__s, size_t __n) { - size_t bos = __builtin_object_size(dst, 0); - size_t slen, dlen; - - if (n > bos) { - slen = strlen(src); - dlen = strlen(dst); - if (slen > n) - slen = n; - if (slen + dlen + 1 > bos) + size_t __b = __builtin_object_size(__d, 0); + size_t __sl, __dl; + + if (__n > __b) { + __sl = strlen(__s); + __dl = strlen(__d); + if (__sl > __n) + __sl = __n; + if (__sl + __dl + 1 > __b) __builtin_trap(); } - return __orig_strncat(dst, src, n); + return __orig_strncat(__d, __s, __n); } -fortify_fn(strncpy) char *strncpy(char *dst, const char *src, size_t n) +_FORTIFY_FN(strncpy) char *strncpy(char *__d, const char *__s, size_t __n) { - size_t bos = __builtin_object_size(dst, 0); + size_t __b = __builtin_object_size(__d, 0); - if (n > bos) + if (__n > __b) __builtin_trap(); - return __orig_strncpy(dst, src, n); + return __orig_strncpy(__d, __s, __n); } #ifdef _GNU_SOURCE #undef mempcpy -fortify_fn(mempcpy) void *mempcpy(void *dst, const void *src, size_t n) +_FORTIFY_FN(mempcpy) void *mempcpy(void *__d, const void *__s, size_t __n) { - size_t bos_dst = __builtin_object_size(dst, 0); - size_t bos_src = __builtin_object_size(src, 0); + size_t __bd = __builtin_object_size(__d, 0); + size_t __bs = __builtin_object_size(__s, 0); - if (n > bos_dst || n > bos_src) + if (__n > __bd || __n > __bs) __builtin_trap(); - return __orig_mempcpy(dst, src, n); + return __orig_mempcpy(__d, __s, __n); } #endif #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) #undef strlcat #undef strlcpy -fortify_fn(strlcat) size_t strlcat(char *dst, const char *src, size_t n) +_FORTIFY_FN(strlcat) size_t strlcat(char *__d, const char *__s, size_t __n) { - size_t bos = __builtin_object_size(dst, 0); + size_t __b = __builtin_object_size(__d, 0); - if (n > bos) + if (__n > __b) __builtin_trap(); - return __orig_strlcat(dst, src, n); + return __orig_strlcat(__d, __s, __n); } -fortify_fn(strlcpy) size_t strlcpy(char *dst, const char *src, size_t n) +_FORTIFY_FN(strlcpy) size_t strlcpy(char *__d, const char *__s, size_t __n) { - size_t bos = __builtin_object_size(dst, 0); + size_t __b = __builtin_object_size(__d, 0); - if (n > bos) + if (__n > __b) __builtin_trap(); - return __orig_strlcpy(dst, src, n); + return __orig_strlcpy(__d, __s, __n); } #endif diff --git a/include/strings.h b/include/strings.h @@ -30,23 +30,23 @@ extern "C" { || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) #undef bcopy #undef bzero -fortify_fn(bcopy) void bcopy(const void *src, void *dst, size_t n) +_FORTIFY_FN(bcopy) void bcopy(const void *__s, void *__d, size_t __n) { - size_t bos_dst = __builtin_object_size(dst, 0); - size_t bos_src = __builtin_object_size(src, 0); + size_t __bd = __builtin_object_size(__d, 0); + size_t __bs = __builtin_object_size(__s, 0); - if (n > bos_dst || n > bos_src) + if (__n > __bd || __n > __bs) __builtin_trap(); - return __orig_bcopy(src, dst, n); + return __orig_bcopy(__s, __d, __n); } -fortify_fn(bzero) void bzero(void *src, size_t n) +_FORTIFY_FN(bzero) void bzero(void *__s, size_t __n) { - size_t bos = __builtin_object_size(src, 0); + size_t __b = __builtin_object_size(__s, 0); - if (n > bos) + if (__n > __b) __builtin_trap(); - return __orig_bzero(src, n); + return __orig_bzero(__s, __n); } #endif diff --git a/include/sys/select.h b/include/sys/select.h @@ -25,23 +25,23 @@ extern "C" { #endif static __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) -void __fortify_FD_CLR(int fd, fd_set *set) +void __fortify_FD_CLR(int __f, fd_set *__s) { - size_t bos = __builtin_object_size(set, 0); + size_t __b = __builtin_object_size(__s, 0); - if (fd < 0 || fd >= FD_SETSIZE || bos < sizeof(fd_set)) + if (__f < 0 || __f >= FD_SETSIZE || __b < sizeof(fd_set)) __builtin_trap(); - FD_CLR(fd, set); + FD_CLR(__f, __s); } static __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) -void __fortify_FD_SET(int fd, fd_set *set) +void __fortify_FD_SET(int __f, fd_set *__s) { - size_t bos = __builtin_object_size(set, 0); + size_t __b = __builtin_object_size(__s, 0); - if (fd < 0 || fd >= FD_SETSIZE || bos < sizeof(fd_set)) + if (__f < 0 || __f >= FD_SETSIZE || __b < sizeof(fd_set)) __builtin_trap(); - FD_SET(fd, set); + FD_SET(__f, __s); } #undef FD_CLR diff --git a/include/sys/socket.h b/include/sys/socket.h @@ -30,42 +30,42 @@ extern "C" { #undef send #undef sendto -fortify_fn(recv) ssize_t recv(int sockfd, void *buf, size_t n, int flags) +_FORTIFY_FN(recv) ssize_t recv(int __f, void *__s, size_t __n, int __fl) { - size_t bos = __builtin_object_size(buf, 0); + size_t __b = __builtin_object_size(__s, 0); - if (n > bos) + if (__n > __b) __builtin_trap(); - return __orig_recv(sockfd, buf, n, flags); + return __orig_recv(__f, __s, __n, __fl); } -fortify_fn(recvfrom) ssize_t recvfrom(int sockfd, void *buf, size_t n, int flags, - struct sockaddr *sa, socklen_t *salen) +_FORTIFY_FN(recvfrom) ssize_t recvfrom(int __f, void *__s, size_t __n, int __fl, + struct sockaddr *__a, socklen_t *__l) { - size_t bos = __builtin_object_size(buf, 0); + size_t __b = __builtin_object_size(__s, 0); - if (n > bos) + if (__n > __b) __builtin_trap(); - return __orig_recvfrom(sockfd, buf, n, flags, sa, salen); + return __orig_recvfrom(__f, __s, __n, __fl, __a, __l); } -fortify_fn(send) ssize_t send(int sockfd, const void *buf, size_t n, int flags) +_FORTIFY_FN(send) ssize_t send(int __f, const void *__s, size_t __n, int __fl) { - size_t bos = __builtin_object_size(buf, 0); + size_t __b = __builtin_object_size(__s, 0); - if (n > bos) + if (__n > __b) __builtin_trap(); - return __orig_send(sockfd, buf, n, flags); + return __orig_send(__f, __s, __n, __fl); } -fortify_fn(sendto) ssize_t sendto(int sockfd, const void *buf, size_t n, int flags, - const struct sockaddr *sa, socklen_t salen) +_FORTIFY_FN(sendto) ssize_t sendto(int __f, const void *__s, size_t __n, int __fl, + const struct sockaddr *__a, socklen_t __l) { - size_t bos = __builtin_object_size(buf, 0); + size_t __b = __builtin_object_size(__s, 0); - if (n > bos) + if (__n > __b) __builtin_trap(); - return __orig_sendto(sockfd, buf, n, flags, sa, salen); + return __orig_sendto(__f, __s, __n, __fl, __a, __l); } #ifdef __cplusplus diff --git a/include/unistd.h b/include/unistd.h @@ -37,115 +37,115 @@ extern "C" { #undef ttyname_r #undef write -fortify_fn(confstr) size_t confstr(int name, char *buf, size_t len) +_FORTIFY_FN(confstr) size_t confstr(int __n, char *__s, size_t __l) { - size_t bos = __builtin_object_size(buf, 0); + size_t __b = __builtin_object_size(__s, 0); - if (len > bos) + if (__l > __b) __builtin_trap(); - return __orig_confstr(name, buf, len); + return __orig_confstr(__n, __s, __l); } -fortify_fn(getcwd) char *getcwd(char *buf, size_t len) +_FORTIFY_FN(getcwd) char *getcwd(char *__s, size_t __l) { - size_t bos = __builtin_object_size(buf, 0); + size_t __b = __builtin_object_size(__s, 0); - if (len > bos) + if (__l > __b) __builtin_trap(); - return __orig_getcwd(buf, len); + return __orig_getcwd(__s, __l); } #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) #undef getdomainname -fortify_fn(getdomainname) int getdomainname(char *name, size_t len) +_FORTIFY_FN(getdomainname) int getdomainname(char *__s, size_t __l) { - size_t bos = __builtin_object_size(name, 0); + size_t __b = __builtin_object_size(__s, 0); - if (len > bos) + if (__l > __b) __builtin_trap(); - return __orig_getdomainname(name, len); + return __orig_getdomainname(__s, __l); } #endif -fortify_fn(getgroups) int getgroups(int len, gid_t *set) +_FORTIFY_FN(getgroups) int getgroups(int __l, gid_t *__s) { - size_t bos = __builtin_object_size(set, 0); + size_t __b = __builtin_object_size(__s, 0); - if (len > bos / sizeof(gid_t)) + if (__l > __b / sizeof(gid_t)) __builtin_trap(); - return __orig_getgroups(len, set); + return __orig_getgroups(__l, __s); } -fortify_fn(gethostname) int gethostname(char *name, size_t len) +_FORTIFY_FN(gethostname) int gethostname(char *__s, size_t __l) { - size_t bos = __builtin_object_size(name, 0); + size_t __b = __builtin_object_size(__s, 0); - if (len > bos) + if (__l > __b) __builtin_trap(); - return __orig_gethostname(name, len); + return __orig_gethostname(__s, __l); } -fortify_fn(getlogin_r) int getlogin_r(char *name, size_t len) +_FORTIFY_FN(getlogin_r) int getlogin_r(char *__s, size_t __l) { - size_t bos = __builtin_object_size(name, 0); + size_t __b = __builtin_object_size(__s, 0); - if (len > bos) + if (__l > __b) __builtin_trap(); - return __orig_getlogin_r(name, len); + return __orig_getlogin_r(__s, __l); } -fortify_fn(pread) ssize_t pread(int fd, void *buf, size_t n, off_t offset) +_FORTIFY_FN(pread) ssize_t pread(int __f, void *__s, size_t __n, off_t __o) { - size_t bos = __builtin_object_size(buf, 0); + size_t __b = __builtin_object_size(__s, 0); - if (n > bos) + if (__n > __b) __builtin_trap(); - return __orig_pread(fd, buf, n, offset); + return __orig_pread(__f, __s, __n, __o); } -fortify_fn(read) ssize_t read(int fd, void *buf, size_t n) +_FORTIFY_FN(read) ssize_t read(int __f, void *__s, size_t __n) { - size_t bos = __builtin_object_size(buf, 0); + size_t __b = __builtin_object_size(__s, 0); - if (n > bos) + if (__n > __b) __builtin_trap(); - return __orig_read(fd, buf, n); + return __orig_read(__f, __s, __n); } -fortify_fn(readlink) ssize_t readlink(const char *path, char *buf, size_t n) +_FORTIFY_FN(readlink) ssize_t readlink(const char *__p, char *__s, size_t __n) { - size_t bos = __builtin_object_size(buf, 0); + size_t __b = __builtin_object_size(__s, 0); - if (n > bos) + if (__n > __b) __builtin_trap(); - return __orig_readlink(path, buf, n); + return __orig_readlink(__p, __s, __n); } -fortify_fn(readlinkat) ssize_t readlinkat(int fd, const char *path, char *buf, size_t n) +_FORTIFY_FN(readlinkat) ssize_t readlinkat(int __f, const char *__p, char *__s, size_t __n) { - size_t bos = __builtin_object_size(buf, 0); + size_t __b = __builtin_object_size(__s, 0); - if (n > bos) + if (__n > __b) __builtin_trap(); - return __orig_readlinkat(fd, path, buf, n); + return __orig_readlinkat(__f, __p, __s, __n); } -fortify_fn(ttyname_r) int ttyname_r(int fd, char *name, size_t n) +_FORTIFY_FN(ttyname_r) int ttyname_r(int __f, char *__s, size_t __n) { - size_t bos = __builtin_object_size(name, 0); + size_t __b = __builtin_object_size(__s, 0); - if (n > bos) + if (__n > __b) __builtin_trap(); - return __orig_ttyname_r(fd, name, n); + return __orig_ttyname_r(__f, __s, __n); } -fortify_fn(write) ssize_t write(int fd, const void *buf, size_t n) +_FORTIFY_FN(write) ssize_t write(int __f, const void *__s, size_t __n) { - size_t bos = __builtin_object_size(buf, 0); + size_t __b = __builtin_object_size(__s, 0); - if (n > bos) + if (__n > __b) __builtin_trap(); - return __orig_write(fd, buf, n); + return __orig_write(__f, __s, __n); } #ifdef __cplusplus diff --git a/include/wchar.h b/include/wchar.h @@ -41,190 +41,190 @@ extern "C" { #undef wmemmove #undef wmemset -fortify_fn(fgetws) wchar_t *fgetws(wchar_t *s, int n, FILE *fp) +_FORTIFY_FN(fgetws) wchar_t *fgetws(wchar_t *__s, int __n, FILE *__f) { - size_t bos = __builtin_object_size(s, 0); + size_t __b = __builtin_object_size(__s, 0); - if ((size_t)n > bos / sizeof(wchar_t)) + if ((size_t)__n > __b / sizeof(wchar_t)) __builtin_trap(); - return __orig_fgetws(s, n, fp); + return __orig_fgetws(__s, __n, __f); } #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) #undef mbsnrtowcs -fortify_fn(mbsnrtowcs) size_t mbsnrtowcs(wchar_t *d, const char **s, size_t n, - size_t wn, mbstate_t *st) +_FORTIFY_FN(mbsnrtowcs) size_t mbsnrtowcs(wchar_t *__d, const char **__s, size_t __n, + size_t __wn, mbstate_t *__st) { - size_t bos = __builtin_object_size(d, 0); - size_t r; + size_t __b = __builtin_object_size(__d, 0); + size_t __r; - if (wn > n / sizeof(wchar_t)) { - bos /= sizeof(wchar_t); - r = __orig_mbsnrtowcs(d, s, n, wn > bos ? bos : wn, st); - if (bos < wn && d && *s && r != (size_t)-1) + if (__wn > __n / sizeof(wchar_t)) { + __b /= sizeof(wchar_t); + __r = __orig_mbsnrtowcs(__d, __s, __n, __wn > __b ? __b : __wn, __st); + if (__b < __wn && __d && *__s && __r != (size_t)-1) __builtin_trap(); } else { - r = __orig_mbsnrtowcs(d, s, n > bos ? bos : n, wn, st); - if (bos < n && d && *s && r != (size_t)-1) + __r = __orig_mbsnrtowcs(__d, __s, __n > __b ? __b : __n, __wn, __st); + if (__b < __n && __d && *__s && __r != (size_t)-1) __builtin_trap(); } - return r; + return __r; } #endif -fortify_fn(mbsrtowcs) size_t mbsrtowcs(wchar_t *d, const char **s, size_t wn, - mbstate_t *st) +_FORTIFY_FN(mbsrtowcs) size_t mbsrtowcs(wchar_t *__d, const char **__s, size_t __wn, + mbstate_t *__st) { - size_t bos = __builtin_object_size(d, 0); - size_t r; + size_t __b = __builtin_object_size(__d, 0); + size_t __r; - bos /= sizeof(wchar_t); - r = __orig_mbsrtowcs(d, s, wn > bos ? bos : wn, st); - if (bos < wn && d && *s && r != (size_t)-1) + __b /= sizeof(wchar_t); + __r = __orig_mbsrtowcs(__d, __s, __wn > __b ? __b : __wn, __st); + if (__b < __wn && __d && *__s && __r != (size_t)-1) __builtin_trap(); - return r; + return __r; } -fortify_fn(mbstowcs) size_t mbstowcs(wchar_t *ws, const char *s, size_t wn) +_FORTIFY_FN(mbstowcs) size_t mbstowcs(wchar_t *__ws, const char *__s, size_t __wn) { - size_t bos = __builtin_object_size(ws, 0); + size_t __b = __builtin_object_size(__ws, 0); - if (ws && wn > bos / sizeof(wchar_t)) + if (__ws && __wn > __b / sizeof(wchar_t)) __builtin_trap(); - return __orig_mbstowcs(ws, s, wn); + return __orig_mbstowcs(__ws, __s, __wn); } -fortify_fn(wcrtomb) size_t wcrtomb(char *s, wchar_t wc, mbstate_t *st) +_FORTIFY_FN(wcrtomb) size_t wcrtomb(char *__s, wchar_t __w, mbstate_t *__st) { - size_t bos = __builtin_object_size(s, 0); + size_t __b = __builtin_object_size(__s, 0); - if (s && MB_CUR_MAX > bos) + if (__s && MB_CUR_MAX > __b) __builtin_trap(); - return __orig_wcrtomb(s, wc, st); + return __orig_wcrtomb(__s, __w, __st); } -fortify_fn(wcscat) wchar_t *wcscat(wchar_t *d, const wchar_t *s) +_FORTIFY_FN(wcscat) wchar_t *wcscat(wchar_t *__d, const wchar_t *__s) { - size_t bos = __builtin_object_size(d, 0); + size_t __b = __builtin_object_size(__d, 0); - if (wcslen(s) + wcslen(d) + 1 > bos / sizeof(wchar_t)) + if (wcslen(__s) + wcslen(__d) + 1 > __b / sizeof(wchar_t)) __builtin_trap(); - return __orig_wcscat(d, s); + return __orig_wcscat(__d, __s); } -fortify_fn(wcscpy) wchar_t *wcscpy(wchar_t *d, const wchar_t *s) +_FORTIFY_FN(wcscpy) wchar_t *wcscpy(wchar_t *__d, const wchar_t *__s) { - size_t bos = __builtin_object_size(d, 0); + size_t __b = __builtin_object_size(__d, 0); - if (wcslen(s) + 1 > bos / sizeof(wchar_t)) + if (wcslen(__s) + 1 > __b / sizeof(wchar_t)) __builtin_trap(); - return __orig_wcscpy(d, s); + return __orig_wcscpy(__d, __s); } -fortify_fn(wcsncat) wchar_t *wcsncat(wchar_t *d, const wchar_t *s, size_t n) +_FORTIFY_FN(wcsncat) wchar_t *wcsncat(wchar_t *__d, const wchar_t *__s, size_t __n) { - size_t bos = __builtin_object_size(d, 0); - size_t slen, dlen; + size_t __b = __builtin_object_size(__d, 0); + size_t __sl, __dl; - if (n > bos / sizeof(wchar_t)) { - slen = wcslen(s); - dlen = wcslen(d); - if (slen > n) - slen = n; - if (slen + dlen + 1 > bos / sizeof(wchar_t)) + if (__n > __b / sizeof(wchar_t)) { + __sl = wcslen(__s); + __dl = wcslen(__d); + if (__sl > __n) + __sl = __n; + if (__sl + __dl + 1 > __b / sizeof(wchar_t)) __builtin_trap(); } - return __orig_wcsncat(d, s, n); + return __orig_wcsncat(__d, __s, __n); } -fortify_fn(wcsncpy) wchar_t *wcsncpy(wchar_t *d, const wchar_t *s, size_t n) +_FORTIFY_FN(wcsncpy) wchar_t *wcsncpy(wchar_t *__d, const wchar_t *__s, size_t __n) { - size_t bos = __builtin_object_size(d, 0); + size_t __b = __builtin_object_size(__d, 0); - if (n > bos / sizeof(wchar_t)) + if (__n > __b / sizeof(wchar_t)) __builtin_trap(); - return __orig_wcsncpy(d, s, n); + return __orig_wcsncpy(__d, __s, __n); } #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) #undef wcsnrtombs -fortify_fn(wcsnrtombs) size_t wcsnrtombs(char *d, const wchar_t **s, size_t wn, - size_t n, mbstate_t *st) +_FORTIFY_FN(wcsnrtombs) size_t wcsnrtombs(char *__d, const wchar_t **__s, size_t __wn, + size_t __n, mbstate_t *__st) { - size_t bos = __builtin_object_size(d, 0); - size_t r; + size_t __b = __builtin_object_size(__d, 0); + size_t __r; - if (wn > n / sizeof(wchar_t)) { - bos /= sizeof(wchar_t); - r = __orig_wcsnrtombs(d, s, wn > bos ? bos : wn, n, st); - if (bos < wn && d && *s && r != (size_t)-1) + if (__wn > __n / sizeof(wchar_t)) { + __b /= sizeof(wchar_t); + __r = __orig_wcsnrtombs(__d, __s, __wn > __b ? __b : __wn, __n, __st); + if (__b < __wn && __d && *__s && __r != (size_t)-1) __builtin_trap(); } else { - r = __orig_wcsnrtombs(d, s, wn, n > bos ? bos : n, st); - if (bos < n && d && *s && r != (size_t)-1) + __r = __orig_wcsnrtombs(__d, __s, __wn, __n > __b ? __b : __n, __st); + if (__b < __n && __d && *__s && __r != (size_t)-1) __builtin_trap(); } - return r; + return __r; } #endif -fortify_fn(wcsrtombs) size_t wcsrtombs(char *d, const wchar_t **s, size_t n, - mbstate_t *st) +_FORTIFY_FN(wcsrtombs) size_t wcsrtombs(char *__d, const wchar_t **__s, size_t __n, + mbstate_t *__st) { - size_t bos = __builtin_object_size(d, 0); - size_t r; + size_t __b = __builtin_object_size(__d, 0); + size_t __r; - r = __orig_wcsrtombs(d, s, n > bos ? bos : n, st); - if (bos < n && d && *s && r != (size_t)-1) + __r = __orig_wcsrtombs(__d, __s, __n > __b ? __b : __n, __st); + if (__b < __n && __d && *__s && __r != (size_t)-1) __builtin_trap(); - return r; + return __r; } -fortify_fn(wcstombs) size_t wcstombs(char *s, const wchar_t *ws, size_t n) +_FORTIFY_FN(wcstombs) size_t wcstombs(char *__s, const wchar_t *__ws, size_t __n) { - size_t bos = __builtin_object_size(s, 0); + size_t __b = __builtin_object_size(__s, 0); - if (s && n > bos) + if (__s && __n > __b) __builtin_trap(); - return __orig_wcstombs(s, ws, n); + return __orig_wcstombs(__s, __ws, __n); } -fortify_fn(wctomb) int wctomb(char *s, wchar_t wc) +_FORTIFY_FN(wctomb) int wctomb(char *__s, wchar_t __w) { - size_t bos = __builtin_object_size(s, 0); + size_t __b = __builtin_object_size(__s, 0); - if (s && MB_CUR_MAX > bos) + if (__s && MB_CUR_MAX > __b) __builtin_trap(); - return __orig_wctomb(s, wc); + return __orig_wctomb(__s, __w); } -fortify_fn(wmemcpy) wchar_t *wmemcpy(wchar_t *d, const wchar_t *s, size_t n) +_FORTIFY_FN(wmemcpy) wchar_t *wmemcpy(wchar_t *__d, const wchar_t *__s, size_t __n) { - size_t bos = __builtin_object_size(d, 0); + size_t __b = __builtin_object_size(__d, 0); - if (n > bos / sizeof(wchar_t)) + if (__n > __b / sizeof(wchar_t)) __builtin_trap(); - return __orig_wmemcpy(d, s, n); + return __orig_wmemcpy(__d, __s, __n); } -fortify_fn(wmemmove) wchar_t *wmemmove(wchar_t *d, const wchar_t *s, size_t n) +_FORTIFY_FN(wmemmove) wchar_t *wmemmove(wchar_t *__d, const wchar_t *__s, size_t __n) { - size_t bos = __builtin_object_size(d, 0); + size_t __b = __builtin_object_size(__d, 0); - if (n > bos / sizeof(wchar_t)) + if (__n > __b / sizeof(wchar_t)) __builtin_trap(); - return __orig_wmemmove(d, s, n); + return __orig_wmemmove(__d, __s, __n); } -fortify_fn(wmemset) wchar_t *wmemset(wchar_t *s, wchar_t c, size_t n) +_FORTIFY_FN(wmemset) wchar_t *wmemset(wchar_t *__s, wchar_t __c, size_t __n) { - size_t bos = __builtin_object_size(s, 0); + size_t __b = __builtin_object_size(__s, 0); - if (n > bos / sizeof(wchar_t)) + if (__n > __b / sizeof(wchar_t)) __builtin_trap(); - return __orig_wmemset(s, c, n); + return __orig_wmemset(__s, __c, __n); } #ifdef __cplusplus