fortify-headers

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

commit fe149628eaae9748be08815d726cc56e8e492c73
parent adae76af26e498af6c3004a52a4b1de2c6fd91c3
Author: Daniel Kolesa <daniel@octaforge.org>
Date:   Wed, 26 Oct 2022 00:30:00 +0200

add initial clang support

Diffstat:
Minclude/fortify-headers.h | 25+++++++++++++++++++++++--
Minclude/poll.h | 7++++---
Minclude/stdio.h | 37++++++++++++++++++++++++++++++-------
Minclude/stdlib.h | 4+++-
Minclude/string.h | 33+++++++++++++++++++++------------
Minclude/strings.h | 6++++--
Minclude/sys/select.h | 13+++++++++++--
Minclude/sys/socket.h | 13+++++++++----
Minclude/unistd.h | 30++++++++++++++++++------------
Minclude/wchar.h | 50++++++++++++++++++++++++++++++++++----------------
10 files changed, 157 insertions(+), 61 deletions(-)

diff --git a/include/fortify-headers.h b/include/fortify-headers.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org> + * Copyright (C) 2022 q66 <q66@chimera-linux.org> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted. @@ -16,10 +17,30 @@ #ifndef _FORTIFY_HEADERS_H #define _FORTIFY_HEADERS_H +#ifdef __clang__ + +/* clang uses overloads; see https://github.com/llvm/llvm-project/issues/53516 */ +#define _FORTIFY_POSN(n) const __attribute__((__pass_object_size__(n))) +/* we can't use extern inline with overloads without making them external */ +#define _FORTIFY_INLINE static __inline__ \ + __attribute__((__always_inline__,__artificial__,__overloadable__)) + +#else /* !__clang__ */ + +#define _FORTIFY_POSN(n) +#define _FORTIFY_INLINE extern __inline__ \ + __attribute__((__always_inline__,__gnu_inline__,__artificial__)) + +#endif /* __clang__ */ + +#define _FORTIFY_POS0 _FORTIFY_POSN(0) +#define _FORTIFY_POS1 _FORTIFY_POSN(1) +#define _FORTIFY_POS2 _FORTIFY_POSN(2) + #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); \ - extern __inline__ __attribute__((__always_inline__,__gnu_inline__,__artificial__)) +#define _FORTIFY_FNB(fn) _FORTIFY_ORIG(__USER_LABEL_PREFIX__,fn) +#define _FORTIFY_FN(fn) _FORTIFY_FNB(fn); _FORTIFY_INLINE /* Use __builtin_dynamic_object_size with _FORTIFY_SOURCE>2, if available. */ diff --git a/include/poll.h b/include/poll.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org> + * Copyright (C) 2022 q66 <q66@chimera-linux.org> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted. @@ -30,7 +31,7 @@ extern "C" { #undef poll -_FORTIFY_FN(poll) int poll(struct pollfd *__f, nfds_t __n, int __s) +_FORTIFY_FN(poll) int poll(struct pollfd * _FORTIFY_POS0 __f, nfds_t __n, int __s) { size_t __b = __bos(__f, 0); @@ -41,8 +42,8 @@ _FORTIFY_FN(poll) int poll(struct pollfd *__f, nfds_t __n, int __s) #if defined(_GNU_SOURCE) && !_REDIR_TIME64 #undef ppoll -_FORTIFY_FN(ppoll) int ppoll(struct pollfd *__f, nfds_t __n, const struct timespec *__s, - const sigset_t *__m) +_FORTIFY_FN(ppoll) int ppoll(struct pollfd * _FORTIFY_POS0 __f, nfds_t __n, + const struct timespec *__s, const sigset_t *__m) { size_t __b = __bos(__f, 0); diff --git a/include/stdio.h b/include/stdio.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org> + * Copyright (C) 2022 q66 <q66@chimera-linux.org> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted. @@ -37,7 +38,7 @@ extern "C" { #undef sprintf __access(write_only, 1, 2) -_FORTIFY_FN(fgets) char *fgets(char *__s, int __n, FILE *__f) +_FORTIFY_FN(fgets) char *fgets(char * _FORTIFY_POS0 __s, int __n, FILE *__f) { size_t __b = __bos(__s, 0); @@ -46,7 +47,8 @@ _FORTIFY_FN(fgets) char *fgets(char *__s, int __n, FILE *__f) return __orig_fgets(__s, __n, __f); } -_FORTIFY_FN(fread) size_t fread(void *__d, size_t __n, size_t __m, FILE *__f) +_FORTIFY_FN(fread) size_t fread(void * _FORTIFY_POS0 __d, size_t __n, + size_t __m, FILE *__f) { size_t __b = __bos(__d, 0); @@ -57,7 +59,8 @@ _FORTIFY_FN(fread) size_t fread(void *__d, size_t __n, size_t __m, FILE *__f) return __orig_fread(__d, __n, __m, __f); } -_FORTIFY_FN(fwrite) size_t fwrite(const void *__d, size_t __n, size_t __m, FILE *__f) +_FORTIFY_FN(fwrite) size_t fwrite(const void * _FORTIFY_POS0 __d, size_t __n, + size_t __m, FILE *__f) { size_t __b = __bos(__d, 0); @@ -68,8 +71,8 @@ _FORTIFY_FN(fwrite) size_t fwrite(const void *__d, size_t __n, size_t __m, FILE return __orig_fwrite(__d, __n, __m, __f); } -_FORTIFY_FN(vsnprintf) int vsnprintf(char *__s, size_t __n, const char *__f, - __builtin_va_list __v) +_FORTIFY_FN(vsnprintf) int vsnprintf(char * _FORTIFY_POS0 __s, size_t __n, + const char *__f, __builtin_va_list __v) { size_t __b = __bos(__s, 0); @@ -78,7 +81,8 @@ _FORTIFY_FN(vsnprintf) int vsnprintf(char *__s, size_t __n, const char *__f, return __orig_vsnprintf(__s, __n, __f, __v); } -_FORTIFY_FN(vsprintf) int vsprintf(char *__s, const char *__f, __builtin_va_list __v) +_FORTIFY_FN(vsprintf) int vsprintf(char * _FORTIFY_POS0 __s, const char *__f, + __builtin_va_list __v) { size_t __b = __bos(__s, 0); int __r; @@ -93,7 +97,23 @@ _FORTIFY_FN(vsprintf) int vsprintf(char *__s, const char *__f, __builtin_va_list return __r; } -_FORTIFY_FN(snprintf) int snprintf(char *__s, size_t __n, const char *__f, ...) +#if defined(__has_builtin) +#if __has_builtin(__builtin_va_arg_pack) + +/* clang is missing __builtin_va_arg_pack, so we cannot use these impls + * outside of gcc; we then have a few options: + * + * 1) using va_start/end and implementing these functions as static inline, + * with inlining never happening; that means extra symbols with internal + * linkage, which is not ideal + * 2) using macros; this is incompatible with c++ and since musl does not + * have the __chk variants, we'd need to implement a body with intermediate + * variables within the macro, which means more non-portable mess + * 3) not implementing these under clang, which is what we do for now + */ + +_FORTIFY_FN(snprintf) int snprintf(char *__s, size_t __n, + const char *__f, ...) { size_t __b = __bos(__s, 0); @@ -117,6 +137,9 @@ _FORTIFY_FN(sprintf) int sprintf(char *__s, const char *__f, ...) return __r; } +#endif /* __has_builtin(__builtin_va_arg_pack) */ +#endif /* defined(__has_builtin) */ + #ifdef __cplusplus } #endif diff --git a/include/stdlib.h b/include/stdlib.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org> + * Copyright (C) 2022 q66 <q66@chimera-linux.org> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted. @@ -35,7 +36,8 @@ __extension__ extern "C" { #endif -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) +/* FIXME clang */ +#if (defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)) && !defined(__clang__) #undef realpath _FORTIFY_FN(realpath) char *realpath(const char *__p, char *__r) { diff --git a/include/string.h b/include/string.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org> + * Copyright (C) 2022 q66 <q66@chimera-linux.org> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted. @@ -38,7 +39,8 @@ extern "C" { __access(write_only, 1) __access(read_only, 2, 3) -_FORTIFY_FN(memcpy) void *memcpy(void *__od, const void *__os, size_t __n) +_FORTIFY_FN(memcpy) void *memcpy(void * _FORTIFY_POS0 __od, + const void * _FORTIFY_POS0 __os, size_t __n) { size_t __bd = __bos(__od, 0); size_t __bs = __bos(__os, 0); @@ -57,7 +59,8 @@ _FORTIFY_FN(memcpy) void *memcpy(void *__od, const void *__os, size_t __n) __access(write_only, 1) __access(read_only, 2, 3) -_FORTIFY_FN(memmove) void *memmove(void *__d, const void *__s, size_t __n) +_FORTIFY_FN(memmove) void *memmove(void * _FORTIFY_POS0 __d, + const void * _FORTIFY_POS0 __s, size_t __n) { size_t __bd = __bos(__d, 0); size_t __bs = __bos(__s, 0); @@ -68,7 +71,7 @@ _FORTIFY_FN(memmove) void *memmove(void *__d, const void *__s, size_t __n) } __access(write_only, 1) -_FORTIFY_FN(memset) void *memset(void *__d, int __c, size_t __n) +_FORTIFY_FN(memset) void *memset(void * _FORTIFY_POS0 __d, int __c, size_t __n) { size_t __b = __bos(__d, 0); @@ -83,7 +86,7 @@ _FORTIFY_FN(memset) void *memset(void *__d, int __c, size_t __n) #undef stpcpy __access(write_only, 1) __access(read_only, 2) -_FORTIFY_FN(stpcpy) char *stpcpy(char *__d, const char *__s) +_FORTIFY_FN(stpcpy) char *stpcpy(char * _FORTIFY_POS0 __d, const char *__s) { size_t __n = strlen(__s) + 1; @@ -102,7 +105,8 @@ _FORTIFY_FN(stpcpy) char *stpcpy(char *__d, const char *__s) #undef stpncpy __access(write_only, 1) __access(read_only, 2, 3) -_FORTIFY_FN(stpncpy) char *stpncpy(char *__d, const char *__s, size_t __n) +_FORTIFY_FN(stpncpy) char *stpncpy(char * _FORTIFY_POS0 __d, const char *__s, + size_t __n) { /* trap if pointers are overlapping but not if dst == src. * gcc seems to like to generate code that relies on dst == src */ @@ -119,7 +123,7 @@ _FORTIFY_FN(stpncpy) char *stpncpy(char *__d, const char *__s, size_t __n) __access (read_write, 1) __access (read_only, 2) -_FORTIFY_FN(strcat) char *strcat(char *__d, const char *__s) +_FORTIFY_FN(strcat) char *strcat(char * _FORTIFY_POS0 __d, const char *__s) { size_t __b = __bos(__d, 0); @@ -130,7 +134,7 @@ _FORTIFY_FN(strcat) char *strcat(char *__d, const char *__s) __access (write_only, 1) __access (read_only, 2) -_FORTIFY_FN(strcpy) char *strcpy(char *__d, const char *__s) +_FORTIFY_FN(strcpy) char *strcpy(char * _FORTIFY_POS0 __d, const char *__s) { size_t __n = strlen(__s) + 1; @@ -148,7 +152,8 @@ _FORTIFY_FN(strcpy) char *strcpy(char *__d, const char *__s) __access (read_write, 1) __access (read_only, 2, 3) -_FORTIFY_FN(strncat) char *strncat(char *__d, const char *__s, size_t __n) +_FORTIFY_FN(strncat) char *strncat(char * _FORTIFY_POS0 __d, const char *__s, + size_t __n) { size_t __b = __bos(__d, 0); @@ -165,7 +170,8 @@ _FORTIFY_FN(strncat) char *strncat(char *__d, const char *__s, size_t __n) __access (write_only, 1) __access (read_only, 2, 3) -_FORTIFY_FN(strncpy) char *strncpy(char *__d, const char *__s, size_t __n) +_FORTIFY_FN(strncpy) char *strncpy(char * _FORTIFY_POS0 __d, + const char *__s, size_t __n) { /* trap if pointers are overlapping but not if dst == src. * gcc seems to like to generate code that relies on dst == src */ @@ -183,7 +189,8 @@ _FORTIFY_FN(strncpy) char *strncpy(char *__d, const char *__s, size_t __n) #undef mempcpy __access(write_only, 1) __access(read_only, 2, 3) -_FORTIFY_FN(mempcpy) void *mempcpy(void *__d, const void *__s, size_t __n) +_FORTIFY_FN(mempcpy) void *mempcpy(void * _FORTIFY_POS0 __d, + const void * _FORTIFY_POS0 __s, size_t __n) { size_t __bd = __bos(__d, 0); size_t __bs = __bos(__s, 0); @@ -199,7 +206,8 @@ _FORTIFY_FN(mempcpy) void *mempcpy(void *__d, const void *__s, size_t __n) #undef strlcpy __access (read_write, 1) __access (read_only, 2, 3) -_FORTIFY_FN(strlcat) size_t strlcat(char *__d, const char *__s, size_t __n) +_FORTIFY_FN(strlcat) size_t strlcat(char * _FORTIFY_POS0 __d, + const char *__s, size_t __n) { size_t __b = __bos(__d, 0); @@ -210,7 +218,8 @@ _FORTIFY_FN(strlcat) size_t strlcat(char *__d, const char *__s, size_t __n) __access (write_only, 1) __access (read_only, 2, 3) -_FORTIFY_FN(strlcpy) size_t strlcpy(char *__d, const char *__s, size_t __n) +_FORTIFY_FN(strlcpy) size_t strlcpy(char * _FORTIFY_POS0 __d, + const char *__s, size_t __n) { size_t __b = __bos(__d, 0); diff --git a/include/strings.h b/include/strings.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org> + * Copyright (C) 2022 q66 <q66@chimera-linux.org> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted. @@ -30,7 +31,8 @@ extern "C" { || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) #undef bcopy #undef bzero -_FORTIFY_FN(bcopy) void bcopy(const void *__s, void *__d, size_t __n) +_FORTIFY_FN(bcopy) void bcopy(const void * _FORTIFY_POS0 __s, + void * _FORTIFY_POS0 __d, size_t __n) { size_t __bd = __bos(__d, 0); size_t __bs = __bos(__s, 0); @@ -40,7 +42,7 @@ _FORTIFY_FN(bcopy) void bcopy(const void *__s, void *__d, size_t __n) return __orig_bcopy(__s, __d, __n); } -_FORTIFY_FN(bzero) void bzero(void *__s, size_t __n) +_FORTIFY_FN(bzero) void bzero(void * _FORTIFY_POS0 __s, size_t __n) { size_t __b = __bos(__s, 0); diff --git a/include/sys/select.h b/include/sys/select.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org> + * Copyright (C) 2022 q66 <q66@chimera-linux.org> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted. @@ -27,8 +28,14 @@ __extension__ extern "C" { #endif +#ifdef __clang__ +#define _FORTIFY_FD_POS0 const __attribute__((__pass_object_size__(0))) +#else +#define _FORTIFY_FD_POS0 +#endif + static __inline__ __attribute__((__always_inline__,__gnu_inline__,__artificial__)) -void __fortify_FD_CLR(int __f, fd_set *__s) +void __fortify_FD_CLR(int __f, fd_set * _FORTIFY_FD_POS0 __s) { size_t __b = __bos(__s, 0); @@ -38,7 +45,7 @@ void __fortify_FD_CLR(int __f, fd_set *__s) } static __inline__ __attribute__((__always_inline__,__gnu_inline__,__artificial__)) -void __fortify_FD_SET(int __f, fd_set *__s) +void __fortify_FD_SET(int __f, fd_set * _FORTIFY_FD_POS0 __s) { size_t __b = __bos(__s, 0); @@ -47,6 +54,8 @@ void __fortify_FD_SET(int __f, fd_set *__s) FD_SET(__f, __s); } +#undef _FORTIFY_FD_POS0 + #undef FD_CLR #define FD_CLR(fd, set) __fortify_FD_CLR(fd, set) #undef FD_SET diff --git a/include/sys/socket.h b/include/sys/socket.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org> + * Copyright (C) 2022 q66 <q66@chimera-linux.org> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted. @@ -33,7 +34,8 @@ extern "C" { #undef send #undef sendto -_FORTIFY_FN(recv) ssize_t recv(int __f, void *__s, size_t __n, int __fl) +_FORTIFY_FN(recv) ssize_t recv(int __f, void * _FORTIFY_POS0 __s, size_t __n, + int __fl) { size_t __b = __bos(__s, 0); @@ -42,7 +44,8 @@ _FORTIFY_FN(recv) ssize_t recv(int __f, void *__s, size_t __n, int __fl) return __orig_recv(__f, __s, __n, __fl); } -_FORTIFY_FN(recvfrom) ssize_t recvfrom(int __f, void *__s, size_t __n, int __fl, +_FORTIFY_FN(recvfrom) ssize_t recvfrom(int __f, void * _FORTIFY_POS0 __s, + size_t __n, int __fl, struct sockaddr *__a, socklen_t *__l) { size_t __b = __bos(__s, 0); @@ -52,7 +55,8 @@ _FORTIFY_FN(recvfrom) ssize_t recvfrom(int __f, void *__s, size_t __n, int __fl, return __orig_recvfrom(__f, __s, __n, __fl, __a, __l); } -_FORTIFY_FN(send) ssize_t send(int __f, const void *__s, size_t __n, int __fl) +_FORTIFY_FN(send) ssize_t send(int __f, const void * _FORTIFY_POS0 __s, + size_t __n, int __fl) { size_t __b = __bos(__s, 0); @@ -61,7 +65,8 @@ _FORTIFY_FN(send) ssize_t send(int __f, const void *__s, size_t __n, int __fl) return __orig_send(__f, __s, __n, __fl); } -_FORTIFY_FN(sendto) ssize_t sendto(int __f, const void *__s, size_t __n, int __fl, +_FORTIFY_FN(sendto) ssize_t sendto(int __f, const void * _FORTIFY_POS0 __s, + size_t __n, int __fl, const struct sockaddr *__a, socklen_t __l) { size_t __b = __bos(__s, 0); diff --git a/include/unistd.h b/include/unistd.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org> + * Copyright (C) 2022 q66 <q66@chimera-linux.org> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted. @@ -40,7 +41,7 @@ extern "C" { #undef ttyname_r #undef write -_FORTIFY_FN(confstr) size_t confstr(int __n, char *__s, size_t __l) +_FORTIFY_FN(confstr) size_t confstr(int __n, char * _FORTIFY_POS0 __s, size_t __l) { size_t __b = __bos(__s, 0); size_t __r = __orig_confstr(__n, __s, __b > __l ? __l : __b); @@ -50,7 +51,7 @@ _FORTIFY_FN(confstr) size_t confstr(int __n, char *__s, size_t __l) return __r; } -_FORTIFY_FN(getcwd) char *getcwd(char *__s, size_t __l) +_FORTIFY_FN(getcwd) char *getcwd(char * _FORTIFY_POS0 __s, size_t __l) { size_t __b = __bos(__s, 0); @@ -61,7 +62,7 @@ _FORTIFY_FN(getcwd) char *getcwd(char *__s, size_t __l) #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) #undef getdomainname -_FORTIFY_FN(getdomainname) int getdomainname(char *__s, size_t __l) +_FORTIFY_FN(getdomainname) int getdomainname(char * _FORTIFY_POS0 __s, size_t __l) { size_t __b = __bos(__s, 0); @@ -71,7 +72,7 @@ _FORTIFY_FN(getdomainname) int getdomainname(char *__s, size_t __l) } #endif -_FORTIFY_FN(getgroups) int getgroups(int __l, gid_t *__s) +_FORTIFY_FN(getgroups) int getgroups(int __l, gid_t * _FORTIFY_POS0 __s) { size_t __b = __bos(__s, 0); @@ -80,7 +81,7 @@ _FORTIFY_FN(getgroups) int getgroups(int __l, gid_t *__s) return __orig_getgroups(__l, __s); } -_FORTIFY_FN(gethostname) int gethostname(char *__s, size_t __l) +_FORTIFY_FN(gethostname) int gethostname(char * _FORTIFY_POS0 __s, size_t __l) { size_t __b = __bos(__s, 0); @@ -89,7 +90,7 @@ _FORTIFY_FN(gethostname) int gethostname(char *__s, size_t __l) return __orig_gethostname(__s, __l); } -_FORTIFY_FN(getlogin_r) int getlogin_r(char *__s, size_t __l) +_FORTIFY_FN(getlogin_r) int getlogin_r(char * _FORTIFY_POS0 __s, size_t __l) { size_t __b = __bos(__s, 0); @@ -98,7 +99,8 @@ _FORTIFY_FN(getlogin_r) int getlogin_r(char *__s, size_t __l) return __orig_getlogin_r(__s, __l); } -_FORTIFY_FN(pread) ssize_t pread(int __f, void *__s, size_t __n, off_t __o) +_FORTIFY_FN(pread) ssize_t pread(int __f, void * _FORTIFY_POS0 __s, + size_t __n, off_t __o) { size_t __b = __bos(__s, 0); @@ -107,7 +109,7 @@ _FORTIFY_FN(pread) ssize_t pread(int __f, void *__s, size_t __n, off_t __o) return __orig_pread(__f, __s, __n, __o); } -_FORTIFY_FN(read) ssize_t read(int __f, void *__s, size_t __n) +_FORTIFY_FN(read) ssize_t read(int __f, void * _FORTIFY_POS0 __s, size_t __n) { size_t __b = __bos(__s, 0); @@ -116,7 +118,8 @@ _FORTIFY_FN(read) ssize_t read(int __f, void *__s, size_t __n) return __orig_read(__f, __s, __n); } -_FORTIFY_FN(readlink) ssize_t readlink(const char *__p, char *__s, size_t __n) +_FORTIFY_FN(readlink) ssize_t readlink(const char *__p, + char * _FORTIFY_POS0 __s, size_t __n) { size_t __b = __bos(__s, 0); @@ -125,7 +128,8 @@ _FORTIFY_FN(readlink) ssize_t readlink(const char *__p, char *__s, size_t __n) return __orig_readlink(__p, __s, __n); } -_FORTIFY_FN(readlinkat) ssize_t readlinkat(int __f, const char *__p, char *__s, size_t __n) +_FORTIFY_FN(readlinkat) ssize_t readlinkat(int __f, const char *__p, + char * _FORTIFY_POS0 __s, size_t __n) { size_t __b = __bos(__s, 0); @@ -134,7 +138,8 @@ _FORTIFY_FN(readlinkat) ssize_t readlinkat(int __f, const char *__p, char *__s, return __orig_readlinkat(__f, __p, __s, __n); } -_FORTIFY_FN(ttyname_r) int ttyname_r(int __f, char *__s, size_t __n) +_FORTIFY_FN(ttyname_r) int ttyname_r(int __f, char * _FORTIFY_POS0 __s, + size_t __n) { size_t __b = __bos(__s, 0); @@ -143,7 +148,8 @@ _FORTIFY_FN(ttyname_r) int ttyname_r(int __f, char *__s, size_t __n) return __orig_ttyname_r(__f, __s, __n); } -_FORTIFY_FN(write) ssize_t write(int __f, const void *__s, size_t __n) +_FORTIFY_FN(write) ssize_t write(int __f, const void * _FORTIFY_POS0 __s, + size_t __n) { size_t __b = __bos(__s, 0); diff --git a/include/wchar.h b/include/wchar.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2015-2017 Dimitris Papastamos <sin@2f30.org> + * Copyright (C) 2022 q66 <q66@chimera-linux.org> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted. @@ -55,7 +56,8 @@ extern "C" { #undef wmemmove #undef wmemset -_FORTIFY_FN(fgetws) wchar_t *fgetws(wchar_t *__s, int __n, FILE *__f) +_FORTIFY_FN(fgetws) wchar_t *fgetws(wchar_t * _FORTIFY_POS0 __s, + int __n, FILE *__f) { size_t __b = __bos(__s, 0); @@ -67,7 +69,8 @@ _FORTIFY_FN(fgetws) wchar_t *fgetws(wchar_t *__s, int __n, FILE *__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, +_FORTIFY_FN(mbsnrtowcs) size_t mbsnrtowcs(wchar_t * _FORTIFY_POS0 __d, + const char **__s, size_t __n, size_t __wn, mbstate_t *__st) { size_t __b = __bos(__d, 0); @@ -87,7 +90,8 @@ _FORTIFY_FN(mbsnrtowcs) size_t mbsnrtowcs(wchar_t *__d, const char **__s, size_t } #endif -_FORTIFY_FN(mbsrtowcs) size_t mbsrtowcs(wchar_t *__d, const char **__s, size_t __wn, +_FORTIFY_FN(mbsrtowcs) size_t mbsrtowcs(wchar_t * _FORTIFY_POS0 __d, + const char **__s, size_t __wn, mbstate_t *__st) { size_t __b = __bos(__d, 0); @@ -100,7 +104,8 @@ _FORTIFY_FN(mbsrtowcs) size_t mbsrtowcs(wchar_t *__d, const char **__s, size_t _ 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 * _FORTIFY_POS0 __ws, + const char *__s, size_t __wn) { size_t __b = __bos(__ws, 0); @@ -109,7 +114,9 @@ _FORTIFY_FN(mbstowcs) size_t mbstowcs(wchar_t *__ws, const char *__s, size_t __w return __orig_mbstowcs(__ws, __s, __wn); } -_FORTIFY_FN(wcrtomb) size_t wcrtomb(char *__s, wchar_t __w, mbstate_t *__st) +/* FIXME clang */ +#ifndef __clang__ +_FORTIFY_FN(wcrtomb) size_t wcrtomb(char * __s, wchar_t __w, mbstate_t *__st) { if (__s && MB_LEN_MAX > __bos(__s, 2)) { char __buf[MB_LEN_MAX]; @@ -125,8 +132,10 @@ _FORTIFY_FN(wcrtomb) size_t wcrtomb(char *__s, wchar_t __w, mbstate_t *__st) } return __orig_wcrtomb(__s, __w, __st); } +#endif -_FORTIFY_FN(wcscat) wchar_t *wcscat(wchar_t *__d, const wchar_t *__s) +_FORTIFY_FN(wcscat) wchar_t *wcscat(wchar_t * _FORTIFY_POS0 __d, + const wchar_t *__s) { size_t __b = __bos(__d, 0); @@ -135,7 +144,8 @@ _FORTIFY_FN(wcscat) wchar_t *wcscat(wchar_t *__d, const wchar_t *__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 * _FORTIFY_POS0 __d, + const wchar_t *__s) { size_t __b = __bos(__d, 0); @@ -144,7 +154,8 @@ _FORTIFY_FN(wcscpy) wchar_t *wcscpy(wchar_t *__d, const wchar_t *__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 * _FORTIFY_POS0 __d, + const wchar_t *__s, size_t __n) { size_t __b = __bos(__d, 0); size_t __sl, __dl; @@ -160,7 +171,8 @@ _FORTIFY_FN(wcsncat) wchar_t *wcsncat(wchar_t *__d, const wchar_t *__s, size_t _ 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 * _FORTIFY_POS0 __d, + const wchar_t *__s, size_t __n) { size_t __b = __bos(__d, 0); @@ -172,7 +184,8 @@ _FORTIFY_FN(wcsncpy) wchar_t *wcsncpy(wchar_t *__d, const wchar_t *__s, size_t _ #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, +_FORTIFY_FN(wcsnrtombs) size_t wcsnrtombs(char * _FORTIFY_POS0 __d, + const wchar_t **__s, size_t __wn, size_t __n, mbstate_t *__st) { size_t __b = __bos(__d, 0); @@ -192,7 +205,8 @@ _FORTIFY_FN(wcsnrtombs) size_t wcsnrtombs(char *__d, const wchar_t **__s, size_t } #endif -_FORTIFY_FN(wcsrtombs) size_t wcsrtombs(char *__d, const wchar_t **__s, size_t __n, +_FORTIFY_FN(wcsrtombs) size_t wcsrtombs(char * _FORTIFY_POS0 __d, + const wchar_t **__s, size_t __n, mbstate_t *__st) { size_t __b = __bos(__d, 0); @@ -204,7 +218,8 @@ _FORTIFY_FN(wcsrtombs) size_t wcsrtombs(char *__d, const wchar_t **__s, size_t _ return __r; } -_FORTIFY_FN(wcstombs) size_t wcstombs(char *__s, const wchar_t *__ws, size_t __n) +_FORTIFY_FN(wcstombs) size_t wcstombs(char * _FORTIFY_POS0 __s, + const wchar_t *__ws, size_t __n) { size_t __b = __bos(__s, 0); @@ -213,7 +228,7 @@ _FORTIFY_FN(wcstombs) size_t wcstombs(char *__s, const wchar_t *__ws, size_t __n return __orig_wcstombs(__s, __ws, __n); } -_FORTIFY_FN(wctomb) int wctomb(char *__s, wchar_t __w) +_FORTIFY_FN(wctomb) int wctomb(char * _FORTIFY_POS0 __s, wchar_t __w) { size_t __b = __bos(__s, 0); @@ -222,7 +237,8 @@ _FORTIFY_FN(wctomb) int wctomb(char *__s, wchar_t __w) 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 * _FORTIFY_POS0 __d, + const wchar_t *__s, size_t __n) { size_t __b = __bos(__d, 0); @@ -231,7 +247,8 @@ _FORTIFY_FN(wmemcpy) wchar_t *wmemcpy(wchar_t *__d, const wchar_t *__s, size_t _ 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 * _FORTIFY_POS0 __d, + const wchar_t *__s, size_t __n) { size_t __b = __bos(__d, 0); @@ -240,7 +257,8 @@ _FORTIFY_FN(wmemmove) wchar_t *wmemmove(wchar_t *__d, const wchar_t *__s, size_t 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 * _FORTIFY_POS0 __s, + wchar_t __c, size_t __n) { size_t __b = __bos(__s, 0);