diff options
| author | Ulrich Drepper <drepper@redhat.com> | 2007-09-26 20:45:18 +0000 |
|---|---|---|
| committer | Ulrich Drepper <drepper@redhat.com> | 2007-09-26 20:45:18 +0000 |
| commit | d6cd6bf4de43672803ad47f4c745ac6e510c6d61 (patch) | |
| tree | f8e5ce0692de101c6ca1d0e4bdabbc60c6ee2473 | |
| parent | 408cfca0c4ec78358314d9fc7c36448d36eeb931 (diff) | |
| download | glibc-d6cd6bf4de43672803ad47f4c745ac6e510c6d61.tar.xz glibc-d6cd6bf4de43672803ad47f4c745ac6e510c6d61.zip | |
* misc/sys/cdefs.h (__warndecl, __errordecl): For GCC 4.3+ define
with __warning__/__error__ attributes.
(__warnattr): Define.
* stdlib/bits/stdlib.h (__realpath_chk_warn, __ptsname_r_chk_warn,
__mbstowcs_chk_warn, __wcstombs_chk_warn): New aliases with
__warnattr.
(realpath, ptsname_r, mbstowcs, wcstombs): Call __*_chk_warn instead
of __*_chk if compile time detectable overflow is found.
* libio/bits/stdio2.h (__fgets_chk_warn, __fread_chk_warn,
__fgets_unlocked_chk_warn, __fread_unlocked_chk_warn): New aliases
with __warnattr.
(fgets, fread, fgets_unlocked, fread_unlocked): Call __*_chk_warn
instead of __*_chk if compile time detectable overflow is found.
(__gets_alias): Rename to...
(__gets_warn): ... this. Add __warnattr.
(gets): Call __gets_warn instead of __gets_alias.
* socket/bits/socket2.h (__recv_chk_warn, __recvfrom_chk_warn): New
aliases with __warnattr.
(recv, recvfrom): Call __*_chk_warn instead of __*_chk if compile
time detectable overflow is found.
* posix/bits/unistd.h (__read_chk_warn, __pread_chk_warn,
__pread64_chk_warn, __readlink_chk_warn, __readlinkat_chk_warn,
__getcwd_chk_warn, __confstr_chk_warn, __getgroups_chk_warn,
__ttyname_r_chk_warn, __getlogin_r_chk_warn, __gethostname_chk_warn,
__getdomainname_chk_warn): New aliases with __warnattr.
(read, pread, pread64, readlink, readlinkat, getcwd, confstr,
getgroups, ttyname_r, getlogin_r, gethostname, getdomainname): Call
__*_chk_warn instead of __*_chk if compile time detectable overflow
is found.
(__getgroups_chk): Rename argument to __listlen from listlen.
(__getwd_alias): Rename to...
(__getwd_warn): ... this. Add __warnattr.
(getwd): Call __getwd_warn instead of __getwd_alias.
* wcsmbs/bits/wchar2.h (__wmemcpy_chk_warn, __wmemmove_chk_warn,
__wmempcpy_chk_warn, __wmemset_chk_warn, __wcsncpy_chk_warn,
__wcpncpy_chk_warn, __fgetws_chk_warn, __fgetws_unlocked_chk_warn,
__mbsrtowcs_chk_warn, __wcsrtombs_chk_warn, __mbsnrtowcs_chk_warn,
__wcsnrtombs_chk_warn): New aliases with __warnattr.
(wmemcpy, wmemmove, wmempcpy, wmemset, mbsrtowcs, wcsrtombs,
mbsnrtowcs, wcsnrtombs): Call __*_chk_warn instead of __*_chk if
compile time detectable overflow is found.
(wcsncpy, wcpncpy): Likewise. For constant __n fix check whether
to use __*_chk or not.
(fgetws, fgetws_unlocked): Divide __bos by sizeof (wchar_t), both
in comparisons which function should be called and in __*_chk*
arguments. Call __*_chk_warn instead of __*_chk if compile time
detectable overflow is found.
(swprintf, vswprintf): Divide __bos by sizeof (wchar_t) in
__*_chk argument.
* debug/tst-chk1.c (do_test): Add a few more tests.
| -rw-r--r-- | ChangeLog | 53 | ||||
| -rw-r--r-- | debug/tst-chk1.c | 22 | ||||
| -rw-r--r-- | libio/bits/stdio2.h | 82 | ||||
| -rw-r--r-- | misc/sys/cdefs.h | 13 | ||||
| -rw-r--r-- | posix/bits/unistd.h | 224 | ||||
| -rw-r--r-- | socket/bits/socket2.h | 36 | ||||
| -rw-r--r-- | stdlib/bits/stdlib.h | 65 | ||||
| -rw-r--r-- | wcsmbs/bits/wchar2.h | 228 |
8 files changed, 601 insertions, 122 deletions
@@ -1,3 +1,56 @@ +2007-09-26 Jakub Jelinek <jakub@redhat.com> + + * misc/sys/cdefs.h (__warndecl, __errordecl): For GCC 4.3+ define + with __warning__/__error__ attributes. + (__warnattr): Define. + * stdlib/bits/stdlib.h (__realpath_chk_warn, __ptsname_r_chk_warn, + __mbstowcs_chk_warn, __wcstombs_chk_warn): New aliases with + __warnattr. + (realpath, ptsname_r, mbstowcs, wcstombs): Call __*_chk_warn instead + of __*_chk if compile time detectable overflow is found. + * libio/bits/stdio2.h (__fgets_chk_warn, __fread_chk_warn, + __fgets_unlocked_chk_warn, __fread_unlocked_chk_warn): New aliases + with __warnattr. + (fgets, fread, fgets_unlocked, fread_unlocked): Call __*_chk_warn + instead of __*_chk if compile time detectable overflow is found. + (__gets_alias): Rename to... + (__gets_warn): ... this. Add __warnattr. + (gets): Call __gets_warn instead of __gets_alias. + * socket/bits/socket2.h (__recv_chk_warn, __recvfrom_chk_warn): New + aliases with __warnattr. + (recv, recvfrom): Call __*_chk_warn instead of __*_chk if compile + time detectable overflow is found. + * posix/bits/unistd.h (__read_chk_warn, __pread_chk_warn, + __pread64_chk_warn, __readlink_chk_warn, __readlinkat_chk_warn, + __getcwd_chk_warn, __confstr_chk_warn, __getgroups_chk_warn, + __ttyname_r_chk_warn, __getlogin_r_chk_warn, __gethostname_chk_warn, + __getdomainname_chk_warn): New aliases with __warnattr. + (read, pread, pread64, readlink, readlinkat, getcwd, confstr, + getgroups, ttyname_r, getlogin_r, gethostname, getdomainname): Call + __*_chk_warn instead of __*_chk if compile time detectable overflow + is found. + (__getgroups_chk): Rename argument to __listlen from listlen. + (__getwd_alias): Rename to... + (__getwd_warn): ... this. Add __warnattr. + (getwd): Call __getwd_warn instead of __getwd_alias. + * wcsmbs/bits/wchar2.h (__wmemcpy_chk_warn, __wmemmove_chk_warn, + __wmempcpy_chk_warn, __wmemset_chk_warn, __wcsncpy_chk_warn, + __wcpncpy_chk_warn, __fgetws_chk_warn, __fgetws_unlocked_chk_warn, + __mbsrtowcs_chk_warn, __wcsrtombs_chk_warn, __mbsnrtowcs_chk_warn, + __wcsnrtombs_chk_warn): New aliases with __warnattr. + (wmemcpy, wmemmove, wmempcpy, wmemset, mbsrtowcs, wcsrtombs, + mbsnrtowcs, wcsnrtombs): Call __*_chk_warn instead of __*_chk if + compile time detectable overflow is found. + (wcsncpy, wcpncpy): Likewise. For constant __n fix check whether + to use __*_chk or not. + (fgetws, fgetws_unlocked): Divide __bos by sizeof (wchar_t), both + in comparisons which function should be called and in __*_chk* + arguments. Call __*_chk_warn instead of __*_chk if compile time + detectable overflow is found. + (swprintf, vswprintf): Divide __bos by sizeof (wchar_t) in + __*_chk argument. + * debug/tst-chk1.c (do_test): Add a few more tests. + 2007-09-24 Ulrich Drepper <drepper@redhat.com> [BZ #5058] diff --git a/debug/tst-chk1.c b/debug/tst-chk1.c index 78a61be53b..487b071026 100644 --- a/debug/tst-chk1.c +++ b/debug/tst-chk1.c @@ -317,6 +317,14 @@ do_test (void) CHK_FAIL_START snprintf (buf + 8, l0 + 3, "%d", num2); CHK_FAIL_END + + CHK_FAIL_START + swprintf (wbuf + 8, 3, L"%d", num1); + CHK_FAIL_END + + CHK_FAIL_START + swprintf (wbuf + 8, l0 + 3, L"%d", num1); + CHK_FAIL_END # endif memcpy (buf, str1 + 2, l0 + 9); @@ -514,11 +522,15 @@ do_test (void) CHK_FAIL_END CHK_FAIL_START + wmemcpy (wbuf + 9, L"abcdefghij", l0 + 10); + CHK_FAIL_END + + CHK_FAIL_START wmemmove (wbuf + 2, wbuf + 1, l0 + 9); CHK_FAIL_END CHK_FAIL_START - wp = wmempcpy (wbuf + 6, L"abcde", l0 + 5); + wp = wmempcpy (wbuf + 6, L"abcde", l0 + 5); CHK_FAIL_END CHK_FAIL_START @@ -538,6 +550,14 @@ do_test (void) CHK_FAIL_END CHK_FAIL_START + wcsncpy (wbuf + 9, L"XABCDEFGH", 8); + CHK_FAIL_END + + CHK_FAIL_START + wcpncpy (wbuf + 9, L"XABCDEFGH", 8); + CHK_FAIL_END + + CHK_FAIL_START wcpncpy (wbuf + 6, L"cd", l0 + 5); CHK_FAIL_END diff --git a/libio/bits/stdio2.h b/libio/bits/stdio2.h index 841a0ff6aa..8889540689 100644 --- a/libio/bits/stdio2.h +++ b/libio/bits/stdio2.h @@ -131,14 +131,16 @@ vfprintf (FILE *__restrict __stream, #endif extern char *__gets_chk (char *__str, size_t) __wur; -extern char *__REDIRECT (__gets_alias, (char *__str), gets) __wur; +extern char *__REDIRECT (__gets_warn, (char *__str), gets) + __wur __warnattr ("please use fgets or getline instead, gets can't " + "specify buffer size"); __extern_always_inline __wur char * gets (char *__str) { if (__bos (__str) != (size_t) -1) return __gets_chk (__str, __bos (__str)); - return __gets_alias (__str); + return __gets_warn (__str); } extern char *__fgets_chk (char *__restrict __s, size_t __size, int __n, @@ -146,13 +148,23 @@ extern char *__fgets_chk (char *__restrict __s, size_t __size, int __n, extern char *__REDIRECT (__fgets_alias, (char *__restrict __s, int __n, FILE *__restrict __stream), fgets) __wur; +extern char *__REDIRECT (__fgets_chk_warn, + (char *__restrict __s, size_t __size, int __n, + FILE *__restrict __stream), __fgets_chk) + __wur __warnattr ("fgets called with bigger size than length " + "of destination buffer"); __extern_always_inline __wur char * fgets (char *__restrict __s, int __n, FILE *__restrict __stream) { - if (__bos (__s) != (size_t) -1 - && (!__builtin_constant_p (__n) || (size_t) __n > __bos (__s))) - return __fgets_chk (__s, __bos (__s), __n, __stream); + if (__bos (__s) != (size_t) -1) + { + if (!__builtin_constant_p (__n) || __n <= 0) + return __fgets_chk (__s, __bos (__s), __n, __stream); + + if ((size_t) __n > __bos (__s)) + return __fgets_chk_warn (__s, __bos (__s), __n, __stream); + } return __fgets_alias (__s, __n, __stream); } @@ -163,17 +175,28 @@ extern size_t __REDIRECT (__fread_alias, (void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __stream), fread) __wur; +extern size_t __REDIRECT (__fread_chk_warn, + (void *__restrict __ptr, size_t __ptrlen, + size_t __size, size_t __n, + FILE *__restrict __stream), + __fread_chk) + __wur __warnattr ("fread called with bigger size * nmemb than length " + "of destination buffer"); __extern_always_inline __wur size_t fread (void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __stream) { - if (__bos0 (__ptr) != (size_t) -1 - && (!__builtin_constant_p (__size) + if (__bos0 (__ptr) != (size_t) -1) + { + if (!__builtin_constant_p (__size) || !__builtin_constant_p (__n) - || (__size | __n) >= (((size_t) 1) << (8 * sizeof (size_t) / 2)) - || __size * __n > __bos0 (__ptr))) - return __fread_chk (__ptr, __bos0 (__ptr), __size, __n, __stream); + || (__size | __n) >= (((size_t) 1) << (8 * sizeof (size_t) / 2))) + return __fread_chk (__ptr, __bos0 (__ptr), __size, __n, __stream); + + if (__size * __n > __bos0 (__ptr)) + return __fread_chk_warn (__ptr, __bos0 (__ptr), __size, __n, __stream); + } return __fread_alias (__ptr, __size, __n, __stream); } @@ -183,13 +206,23 @@ extern char *__fgets_unlocked_chk (char *__restrict __s, size_t __size, extern char *__REDIRECT (__fgets_unlocked_alias, (char *__restrict __s, int __n, FILE *__restrict __stream), fgets_unlocked) __wur; +extern char *__REDIRECT (__fgets_unlocked_chk_warn, + (char *__restrict __s, size_t __size, int __n, + FILE *__restrict __stream), __fgets_unlocked_chk) + __wur __warnattr ("fgets_unlocked called with bigger size than length " + "of destination buffer"); __extern_always_inline __wur char * fgets_unlocked (char *__restrict __s, int __n, FILE *__restrict __stream) { - if (__bos (__s) != (size_t) -1 - && (!__builtin_constant_p (__n) || (size_t) __n > __bos (__s))) - return __fgets_unlocked_chk (__s, __bos (__s), __n, __stream); + if (__bos (__s) != (size_t) -1) + { + if (!__builtin_constant_p (__n) || __n <= 0) + return __fgets_unlocked_chk (__s, __bos (__s), __n, __stream); + + if ((size_t) __n > __bos (__s)) + return __fgets_unlocked_chk_warn (__s, __bos (__s), __n, __stream); + } return __fgets_unlocked_alias (__s, __n, __stream); } #endif @@ -203,17 +236,30 @@ extern size_t __REDIRECT (__fread_unlocked_alias, (void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __stream), fread_unlocked) __wur; +extern size_t __REDIRECT (__fread_unlocked_chk_warn, + (void *__restrict __ptr, size_t __ptrlen, + size_t __size, size_t __n, + FILE *__restrict __stream), + __fread_unlocked_chk) + __wur __warnattr ("fread_unlocked called with bigger size * nmemb than " + "length of destination buffer"); __extern_always_inline __wur size_t fread_unlocked (void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __stream) { - if (__bos0 (__ptr) != (size_t) -1 - && (!__builtin_constant_p (__size) + if (__bos0 (__ptr) != (size_t) -1) + { + if (!__builtin_constant_p (__size) || !__builtin_constant_p (__n) - || (__size | __n) >= (((size_t) 1) << (8 * sizeof (size_t) / 2)) - || __size * __n > __bos0 (__ptr))) - return __fread_unlocked_chk (__ptr, __bos0 (__ptr), __size, __n, __stream); + || (__size | __n) >= (((size_t) 1) << (8 * sizeof (size_t) / 2))) + return __fread_unlocked_chk (__ptr, __bos0 (__ptr), __size, __n, + __stream); + + if (__size * __n > __bos0 (__ptr)) + return __fread_unlocked_chk_warn (__ptr, __bos0 (__ptr), __size, __n, + __stream); + } # ifdef __USE_EXTERN_INLINES if (__builtin_constant_p (__size) diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h index 26b9490bad..4650d5f74e 100644 --- a/misc/sys/cdefs.h +++ b/misc/sys/cdefs.h @@ -131,9 +131,18 @@ /* Fortify support. */ #define __bos(ptr) __builtin_object_size (ptr, __USE_FORTIFY_LEVEL > 1) #define __bos0(ptr) __builtin_object_size (ptr, 0) -#define __warndecl(name, msg) extern void name (void) -#define __errordecl(name, msg) extern void name (void) +#if __GNUC_PREREQ (4,3) +# define __warndecl(name, msg) \ + extern void name (void) __attribute__((__warning__ (msg))) +# define __warnattr(msg) __attribute__((__warning__ (msg))) +# define __errordecl(name, msg) \ + extern void name (void) __attribute__((__error__ (msg))) +#else +# define __warndecl(name, msg) extern void name (void) +# define __warnattr(msg) +# define __errordecl(name, msg) extern void name (void) +#endif /* Support for flexible arrays. */ #if __GNUC_PREREQ (2,97) diff --git a/posix/bits/unistd.h b/posix/bits/unistd.h index 331e8ea3b9..efd7f75a50 100644 --- a/posix/bits/unistd.h +++ b/posix/bits/unistd.h @@ -25,13 +25,23 @@ extern ssize_t __read_chk (int __fd, void *__buf, size_t __nbytes, size_t __buflen) __wur; extern ssize_t __REDIRECT (__read_alias, (int __fd, void *__buf, size_t __nbytes), read) __wur; +extern ssize_t __REDIRECT (__read_chk_warn, + (int __fd, void *__buf, size_t __nbytes, + size_t __buflen), __read_chk) + __wur __warnattr ("read called with bigger length than size of " + "the destination buffer"); __extern_always_inline __wur ssize_t read (int __fd, void *__buf, size_t __nbytes) { - if (__bos0 (__buf) != (size_t) -1 - && (!__builtin_constant_p (__nbytes) || __nbytes > __bos0 (__buf))) - return __read_chk (__fd, __buf, __nbytes, __bos0 (__buf)); + if (__bos0 (__buf) != (size_t) -1) + { + if (!__builtin_constant_p (__nbytes)) + return __read_chk (__fd, __buf, __nbytes, __bos0 (__buf)); + + if (__nbytes > __bos0 (__buf)) + return __read_chk_warn (__fd, __buf, __nbytes, __bos0 (__buf)); + } return __read_alias (__fd, __buf, __nbytes); } @@ -46,23 +56,47 @@ extern ssize_t __REDIRECT (__pread_alias, extern ssize_t __REDIRECT (__pread64_alias, (int __fd, void *__buf, size_t __nbytes, __off64_t __offset), pread64) __wur; +extern ssize_t __REDIRECT (__pread_chk_warn, + (int __fd, void *__buf, size_t __nbytes, + __off_t __offset, size_t __bufsize), __pread_chk) + __wur __warnattr ("pread called with bigger length than size of " + "the destination buffer"); +extern ssize_t __REDIRECT (__pread64_chk_warn, + (int __fd, void *__buf, size_t __nbytes, + __off64_t __offset, size_t __bufsize), + __pread64_chk) + __wur __warnattr ("pread64 called with bigger length than size of " + "the destination buffer"); # ifndef __USE_FILE_OFFSET64 __extern_always_inline __wur ssize_t pread (int __fd, void *__buf, size_t __nbytes, __off_t __offset) { - if (__bos0 (__buf) != (size_t) -1 - && (!__builtin_constant_p (__nbytes) || __nbytes > __bos0 (__buf))) - return __pread_chk (__fd, __buf, __nbytes, __offset, __bos0 (__buf)); + if (__bos0 (__buf) != (size_t) -1) + { + if (!__builtin_constant_p (__nbytes)) + return __pread_chk (__fd, __buf, __nbytes, __offset, __bos0 (__buf)); + + if ( __nbytes > __bos0 (__buf)) + return __pread_chk_warn (__fd, __buf, __nbytes, __offset, + __bos0 (__buf)); + } return __pread_alias (__fd, __buf, __nbytes, __offset); } # else __extern_always_inline __wur ssize_t pread (int __fd, void *__buf, size_t __nbytes, __off64_t __offset) { - if (__bos0 (__buf) != (size_t) -1 - && (!__builtin_constant_p (__nbytes) || __nbytes > __bos0 (__buf))) - return __pread64_chk (__fd, __buf, __nbytes, __offset, __bos0 (__buf)); + if (__bos0 (__buf) != (size_t) -1) + { + if (!__builtin_constant_p (__nbytes)) + return __pread64_chk (__fd, __buf, __nbytes, __offset, __bos0 (__buf)); + + if ( __nbytes > __bos0 (__buf)) + return __pread64_chk_warn (__fd, __buf, __nbytes, __offset, + __bos0 (__buf)); + } + return __pread64_alias (__fd, __buf, __nbytes, __offset); } # endif @@ -71,9 +105,16 @@ pread (int __fd, void *__buf, size_t __nbytes, __off64_t __offset) __extern_always_inline __wur ssize_t pread64 (int __fd, void *__buf, size_t __nbytes, __off64_t __offset) { - if (__bos0 (__buf) != (size_t) -1 - && (!__builtin_constant_p (__nbytes) || __nbytes > __bos0 (__buf))) - return __pread64_chk (__fd, __buf, __nbytes, __offset, __bos0 (__buf)); + if (__bos0 (__buf) != (size_t) -1) + { + if (!__builtin_constant_p (__nbytes)) + return __pread64_chk (__fd, __buf, __nbytes, __offset, __bos0 (__buf)); + + if ( __nbytes > __bos0 (__buf)) + return __pread64_chk_warn (__fd, __buf, __nbytes, __offset, + __bos0 (__buf)); + } + return __pread64_alias (__fd, __buf, __nbytes, __offset); } # endif @@ -88,14 +129,25 @@ extern ssize_t __REDIRECT_NTH (__readlink_alias, (__const char *__restrict __path, char *__restrict __buf, size_t __len), readlink) __nonnull ((1, 2)) __wur; +extern ssize_t __REDIRECT_NTH (__readlink_chk_warn, + (__const char *__restrict __path, + char *__restrict __buf, size_t __len, + size_t __buflen), __readlink_chk) + __nonnull ((1, 2)) __wur __warnattr ("readlink called with bigger length " + "than size of destination buffer"); __extern_always_inline __nonnull ((1, 2)) __wur ssize_t __NTH (readlink (__const char *__restrict __path, char *__restrict __buf, size_t __len)) { - if (__bos (__buf) != (size_t) -1 - && (!__builtin_constant_p (__len) || __len > __bos (__buf))) - return __readlink_chk (__path, __buf, __len, __bos (__buf)); + if (__bos (__buf) != (size_t) -1) + { + if (!__builtin_constant_p (__len)) + return __readlink_chk (__path, __buf, __len, __bos (__buf)); + + if ( __len > __bos (__buf)) + return __readlink_chk_warn (__path, __buf, __len, __bos (__buf)); + } return __readlink_alias (__path, __buf, __len); } #endif @@ -110,14 +162,27 @@ extern ssize_t __REDIRECT_NTH (__readlinkat_alias, char *__restrict __buf, size_t __len), readlinkat) __nonnull ((2, 3)) __wur; +extern ssize_t __REDIRECT_NTH (__readlinkat_chk_warn, + (int __fd, __const char *__restrict __path, + char *__restrict __buf, size_t __len, + size_t __buflen), __readlinkat_chk) + __nonnull ((2, 3)) __wur __warnattr ("readlinkat called with bigger " + "length than size of destination " + "buffer"); __extern_always_inline __nonnull ((2, 3)) __wur ssize_t __NTH (readlinkat (int __fd, __const char *__restrict __path, char *__restrict __buf, size_t __len)) { - if (__bos (__buf) != (size_t) -1 - && (!__builtin_constant_p (__len) || __len > __bos (__buf))) - return __readlinkat_chk (__fd, __path, __buf, __len, __bos (__buf)); + if (__bos (__buf) != (size_t) -1) + { + if (!__builtin_constant_p (__len)) + return __readlinkat_chk (__fd, __path, __buf, __len, __bos (__buf)); + + if (__len > __bos (__buf)) + return __readlinkat_chk_warn (__fd, __path, __buf, __len, + __bos (__buf)); + } return __readlinkat_alias (__fd, __path, __buf, __len); } #endif @@ -126,28 +191,39 @@ extern char *__getcwd_chk (char *__buf, size_t __size, size_t __buflen) __THROW __wur; extern char *__REDIRECT_NTH (__getcwd_alias, (char *__buf, size_t __size), getcwd) __wur; +extern char *__REDIRECT_NTH (__getcwd_chk_warn, + (char *__buf, size_t __size, size_t __buflen), + __getcwd_chk) + __wur __warnattr ("getcwd caller with bigger length than size of " + "destination buffer"); __extern_always_inline __wur char * __NTH (getcwd (char *__buf, size_t __size)) { - if (__bos (__buf) != (size_t) -1 - && (!__builtin_constant_p (__size) || __size > __bos (__buf))) - return __getcwd_chk (__buf, __size, __bos (__buf)); + if (__bos (__buf) != (size_t) -1) + { + if (!__builtin_constant_p (__size)) + return __getcwd_chk (__buf, __size, __bos (__buf)); + + if (__size > __bos (__buf)) + return __getcwd_chk_warn (__buf, __size, __bos (__buf)); + } return __getcwd_alias (__buf, __size); } #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED extern char *__getwd_chk (char *__buf, size_t buflen) __THROW __nonnull ((1)) __wur; -extern char *__REDIRECT_NTH (__getwd_alias, (char *__buf), getwd) - __nonnull ((1)) __wur; +extern char *__REDIRECT_NTH (__getwd_warn, (char *__buf), getwd) + __nonnull ((1)) __wur __warnattr ("please use getcwd instead, as getwd " + "doesn't specify buffer size"); __extern_always_inline __nonnull ((1)) __attribute_deprecated__ __wur char * __NTH (getwd (char *__buf)) { if (__bos (__buf) != (size_t) -1) return __getwd_chk (__buf, __bos (__buf)); - return __getwd_alias (__buf); + return __getwd_warn (__buf); } #endif @@ -155,29 +231,48 @@ extern size_t __confstr_chk (int __name, char *__buf, size_t __len, size_t __buflen) __THROW; extern size_t __REDIRECT_NTH (__confstr_alias, (int __name, char *__buf, size_t __len), confstr); +extern size_t __REDIRECT_NTH (__confstr_chk_warn, + (int __name, char *__buf, size_t __len, + size_t __buflen), __confstr_chk) + __warnattr ("confstr called with bigger length than size of destination " + "buffer"); __extern_always_inline size_t __NTH (confstr (int __name, char *__buf, size_t __len)) { - if (__bos (__buf) != (size_t) -1 - && (!__builtin_constant_p (__len) || __bos (__buf) < __len)) - return __confstr_chk (__name, __buf, __len, __bos (__buf)); + if (__bos (__buf) != (size_t) -1) + { + if (!__builtin_constant_p (__len)) + return __confstr_chk (__name, __buf, __len, __bos (__buf)); + + if (__bos (__buf) < __len) + return __confstr_chk_warn (__name, __buf, __len, __bos (__buf)); + } return __confstr_alias (__name, __buf, __len); } -extern int __getgroups_chk (int __size, __gid_t __list[], size_t listlen) +extern int __getgroups_chk (int __size, __gid_t __list[], size_t __listlen) __THROW __wur; extern int __REDIRECT_NTH (__getgroups_alias, (int __size, __gid_t __list[]), getgroups) __wur; +extern int __REDIRECT_NTH (__getgroups_chk_warn, + (int __size, __gid_t __list[], size_t __listlen), + __getgroups_chk) + __wur __warnattr ("getgroups called with bigger group count than what " + "can fit into destination buffer"); __extern_always_inline int __NTH (getgroups (int __size, __gid_t __list[])) { - if (__bos (__list) != (size_t) -1 - && (!__builtin_constant_p (__size) - || __size * sizeof (__gid_t) > __bos (__list))) - return __getgroups_chk (__size, __list, __bos (__list)); + if (__bos (__list) != (size_t) -1) + { + if (!__builtin_constant_p (__size)) + return __getgrou |
