diff options
Diffstat (limited to 'posix/bits/unistd.h')
-rw-r--r-- | posix/bits/unistd.h | 174 |
1 files changed, 39 insertions, 135 deletions
diff --git a/posix/bits/unistd.h b/posix/bits/unistd.h index 622adeb2b2..697dcbbf7b 100644 --- a/posix/bits/unistd.h +++ b/posix/bits/unistd.h @@ -35,16 +35,9 @@ extern ssize_t __REDIRECT (__read_chk_warn, __fortify_function __wur ssize_t read (int __fd, void *__buf, size_t __nbytes) { - if (__glibc_objsize0 (__buf) != (size_t) -1) - { - if (!__builtin_constant_p (__nbytes)) - return __read_chk (__fd, __buf, __nbytes, __glibc_objsize0 (__buf)); - - if (__nbytes > __glibc_objsize0 (__buf)) - return __read_chk_warn (__fd, __buf, __nbytes, - __glibc_objsize0 (__buf)); - } - return __read_alias (__fd, __buf, __nbytes); + return __glibc_fortify (read, __nbytes, sizeof (char), + __glibc_objsize0 (__buf), + __fd, __buf, __nbytes); } #ifdef __USE_UNIX98 @@ -78,34 +71,17 @@ extern ssize_t __REDIRECT (__pread64_chk_warn, __fortify_function __wur ssize_t pread (int __fd, void *__buf, size_t __nbytes, __off_t __offset) { - if (__glibc_objsize0 (__buf) != (size_t) -1) - { - if (!__builtin_constant_p (__nbytes)) - return __pread_chk (__fd, __buf, __nbytes, __offset, - __glibc_objsize0 (__buf)); - - if ( __nbytes > __glibc_objsize0 (__buf)) - return __pread_chk_warn (__fd, __buf, __nbytes, __offset, - __glibc_objsize0 (__buf)); - } - return __pread_alias (__fd, __buf, __nbytes, __offset); + return __glibc_fortify (pread, __nbytes, sizeof (char), + __glibc_objsize0 (__buf), + __fd, __buf, __nbytes, __offset); } # else __fortify_function __wur ssize_t pread (int __fd, void *__buf, size_t __nbytes, __off64_t __offset) { - if (__glibc_objsize0 (__buf) != (size_t) -1) - { - if (!__builtin_constant_p (__nbytes)) - return __pread64_chk (__fd, __buf, __nbytes, __offset, - __glibc_objsize0 (__buf)); - - if ( __nbytes > __glibc_objsize0 (__buf)) - return __pread64_chk_warn (__fd, __buf, __nbytes, __offset, - __glibc_objsize0 (__buf)); - } - - return __pread64_alias (__fd, __buf, __nbytes, __offset); + return __glibc_fortify (pread64, __nbytes, sizeof (char), + __glibc_objsize0 (__buf), + __fd, __buf, __nbytes, __offset); } # endif @@ -113,18 +89,9 @@ pread (int __fd, void *__buf, size_t __nbytes, __off64_t __offset) __fortify_function __wur ssize_t pread64 (int __fd, void *__buf, size_t __nbytes, __off64_t __offset) { - if (__glibc_objsize0 (__buf) != (size_t) -1) - { - if (!__builtin_constant_p (__nbytes)) - return __pread64_chk (__fd, __buf, __nbytes, __offset, - __glibc_objsize0 (__buf)); - - if ( __nbytes > __glibc_objsize0 (__buf)) - return __pread64_chk_warn (__fd, __buf, __nbytes, __offset, - __glibc_objsize0 (__buf)); - } - - return __pread64_alias (__fd, __buf, __nbytes, __offset); + return __glibc_fortify (pread64, __nbytes, sizeof (char), + __glibc_objsize0 (__buf), + __fd, __buf, __nbytes, __offset); } # endif #endif @@ -149,16 +116,9 @@ __fortify_function __nonnull ((1, 2)) __wur ssize_t __NTH (readlink (const char *__restrict __path, char *__restrict __buf, size_t __len)) { - if (__glibc_objsize (__buf) != (size_t) -1) - { - if (!__builtin_constant_p (__len)) - return __readlink_chk (__path, __buf, __len, __glibc_objsize (__buf)); - - if ( __len > __glibc_objsize (__buf)) - return __readlink_chk_warn (__path, __buf, __len, - __glibc_objsize (__buf)); - } - return __readlink_alias (__path, __buf, __len); + return __glibc_fortify (readlink, __len, sizeof (char), + __glibc_objsize (__buf), + __path, __buf, __len); } #endif @@ -184,17 +144,9 @@ __fortify_function __nonnull ((2, 3)) __wur ssize_t __NTH (readlinkat (int __fd, const char *__restrict __path, char *__restrict __buf, size_t __len)) { - if (__glibc_objsize (__buf) != (size_t) -1) - { - if (!__builtin_constant_p (__len)) - return __readlinkat_chk (__fd, __path, __buf, __len, - __glibc_objsize (__buf)); - - if (__len > __glibc_objsize (__buf)) - return __readlinkat_chk_warn (__fd, __path, __buf, __len, - __glibc_objsize (__buf)); - } - return __readlinkat_alias (__fd, __path, __buf, __len); + return __glibc_fortify (readlinkat, __len, sizeof (char), + __glibc_objsize (__buf), + __fd, __path, __buf, __len); } #endif @@ -211,15 +163,9 @@ extern char *__REDIRECT_NTH (__getcwd_chk_warn, __fortify_function __wur char * __NTH (getcwd (char *__buf, size_t __size)) { - if (__glibc_objsize (__buf) != (size_t) -1) - { - if (!__builtin_constant_p (__size)) - return __getcwd_chk (__buf, __size, __glibc_objsize (__buf)); - - if (__size > __glibc_objsize (__buf)) - return __getcwd_chk_warn (__buf, __size, __glibc_objsize (__buf)); - } - return __getcwd_alias (__buf, __size); + return __glibc_fortify (getcwd, __size, sizeof (char), + __glibc_objsize (__buf), + __buf, __size); } #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED @@ -253,16 +199,9 @@ extern size_t __REDIRECT_NTH (__confstr_chk_warn, __fortify_function size_t __NTH (confstr (int __name, char *__buf, size_t __len)) { - if (__glibc_objsize (__buf) != (size_t) -1) - { - if (!__builtin_constant_p (__len)) - return __confstr_chk (__name, __buf, __len, __glibc_objsize (__buf)); - - if (__glibc_objsize (__buf) < __len) - return __confstr_chk_warn (__name, __buf, __len, - __glibc_objsize (__buf)); - } - return __confstr_alias (__name, __buf, __len); + return __glibc_fortify (confstr, __len, sizeof (char), + __glibc_objsize (__buf), + __name, __buf, __len); } @@ -279,15 +218,9 @@ extern int __REDIRECT_NTH (__getgroups_chk_warn, __fortify_function int __NTH (getgroups (int __size, __gid_t __list[])) { - if (__glibc_objsize (__list) != (size_t) -1) - { - if (!__builtin_constant_p (__size) || __size < 0) - return __getgroups_chk (__size, __list, __glibc_objsize (__list)); - - if (__size * sizeof (__gid_t) > __glibc_objsize (__list)) - return __getgroups_chk_warn (__size, __list, __glibc_objsize (__list)); - } - return __getgroups_alias (__size, __list); + return __glibc_fortify (getgroups, __size, sizeof (__gid_t), + __glibc_objsize (__list), + __size, __list); } @@ -306,17 +239,9 @@ extern int __REDIRECT_NTH (__ttyname_r_chk_warn, __fortify_function int __NTH (ttyname_r (int __fd, char *__buf, size_t __buflen)) { - if (__glibc_objsize (__buf) != (size_t) -1) - { - if (!__builtin_constant_p (__buflen)) - return __ttyname_r_chk (__fd, __buf, __buflen, - __glibc_objsize (__buf)); - - if (__buflen > __glibc_objsize (__buf)) - return __ttyname_r_chk_warn (__fd, __buf, __buflen, - __glibc_objsize (__buf)); - } - return __ttyname_r_alias (__fd, __buf, __buflen); + return __glibc_fortify (ttyname_r, __buflen, sizeof (char), + __glibc_objsize (__buf), + __fd, __buf, __buflen); } @@ -334,16 +259,9 @@ extern int __REDIRECT (__getlogin_r_chk_warn, __fortify_function int getlogin_r (char *__buf, size_t __buflen) { - if (__glibc_objsize (__buf) != (size_t) -1) - { - if (!__builtin_constant_p (__buflen)) - return __getlogin_r_chk (__buf, __buflen, __glibc_objsize (__buf)); - - if (__buflen > __glibc_objsize (__buf)) - return __getlogin_r_chk_warn (__buf, __buflen, - __glibc_objsize (__buf)); - } - return __getlogin_r_alias (__buf, __buflen); + return __glibc_fortify (getlogin_r, __buflen, sizeof (char), + __glibc_objsize (__buf), + __buf, __buflen); } #endif @@ -363,16 +281,9 @@ extern int __REDIRECT_NTH (__gethostname_chk_warn, __fortify_function int __NTH (gethostname (char *__buf, size_t __buflen)) { - if (__glibc_objsize (__buf) != (size_t) -1) - { - if (!__builtin_constant_p (__buflen)) - return __gethostname_chk (__buf, __buflen, __glibc_objsize (__buf)); - - if (__buflen > __glibc_objsize (__buf)) - return __gethostname_chk_warn (__buf, __buflen, - __glibc_objsize (__buf)); - } - return __gethostname_alias (__buf, __buflen); + return __glibc_fortify (gethostname, __buflen, sizeof (char), + __glibc_objsize (__buf), + __buf, __buflen); } #endif @@ -394,15 +305,8 @@ extern int __REDIRECT_NTH (__getdomainname_chk_warn, __fortify_function int __NTH (getdomainname (char *__buf, size_t __buflen)) { - if (__glibc_objsize (__buf) != (size_t) -1) - { - if (!__builtin_constant_p (__buflen)) - return __getdomainname_chk (__buf, __buflen, __glibc_objsize (__buf)); - - if (__buflen > __glibc_objsize (__buf)) - return __getdomainname_chk_warn (__buf, __buflen, - __glibc_objsize (__buf)); - } - return __getdomainname_alias (__buf, __buflen); + return __glibc_fortify (getdomainname, __buflen, sizeof (char), + __glibc_objsize (__buf), + __buf, __buflen); } #endif |